/*
   Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
   This file is licensed under the Apache License, Version 2.0 (the "License").
   You may not use this file except in compliance with the License. A copy of
   the License is located at
    http://aws.amazon.com/apache2.0/
   This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
   CONDITIONS OF ANY KIND, either express or implied. See the License for the
   specific language governing permissions and limitations under the License.
*/

package com.aws.securingweb;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.provisioning.InMemoryUserDetailsManager;
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;

@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
     @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
                .authorizeRequests()
                .antMatchers(
                        "/js/**",
                        "/css/**",
                        "/img/**",
                        "/webjars/**").permitAll()
                .anyRequest().authenticated()
                .and()
                .formLogin()
                .loginPage("/login")
                .permitAll()
                .and()
                .logout()
                .invalidateHttpSession(true)
                .clearAuthentication(true)
                .logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
                .logoutSuccessUrl("/login?logout")
                .permitAll();

        http.csrf().disable();
    }

    @Bean
    @Override
    public UserDetailsService userDetailsService() {
        UserDetails user =
                User.withDefaultPasswordEncoder()
                        .username("user")
                        .password("password")
                        .roles("USER")
                        .build();

        return new InMemoryUserDetailsManager(user);
    }
}

@@ -520,17 +520,16 @@
 nse.%0A*/%0A
-%0A
 package 
@@ -663,16 +663,124 @@
 ration;%0A
+import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;%0A
 import o
@@ -1086,242 +1086,109 @@
 ty.c
-ore.userdetails.User;%0Aimport org.springframework.security.core.userdetails.UserDetails;%0Aimport org.springframework.security.core.userdetails.UserDetailsService;%0Aimport org.springframework.security.provisioning.InMemoryUserDetailsManag
+rypto.bcrypt.BCryptPasswordEncoder;%0Aimport org.springframework.security.crypto.password.PasswordEncod
 er;%0A
@@ -2186,18 +2186,8 @@
  %7D%0A%0A
-    @Bean%0A
     
@@ -2205,116 +2205,158 @@
    p
-ublic UserDetailsService userDetailsService() %7B%0A        UserDetails user =%0A                User.withDefaultP
+rotected void configure(AuthenticationManagerBuilder auth) throws Exception %7B%0A        auth.inMemoryAuthentication()%0A                .passwordEncoder(p
 assw
@@ -2367,23 +2367,18 @@
 ncoder()
+)
 %0A
-      
         
@@ -2389,19 +2389,17 @@
     
-  .username
+.withUser
 (%22us
@@ -2403,24 +2403,16 @@
 %22user%22)%0A
-        
         
@@ -2429,16 +2429,41 @@
 assword(
+passwordEncoder().encode(
 %22passwor
@@ -2465,25 +2465,18 @@
 ssword%22)
+)
 %0A
-        
         
@@ -2501,94 +2501,115 @@
 ER%22)
+;
 %0A
-   
     
+%7D%0A%0A
     
-             .build();%0A%0A        return new InMemoryUserDetailsManager(user
+@Bean%0A    public PasswordEncoder passwordEncoder() %7B%0A        return new BCryptPasswordEncoder(
 );%0A 
@@ -2613,10 +2613,11 @@
 ;%0A    %7D%0A
+%0A
 %7D%0A

Update WebSecurityConfig.java