package learn_to_code.springboot.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
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;

/**
 * Security configuration classes go here.
 * Remember: This call will be loaded by ComponentScan by spring-boot. In order to launch spring security at all
 * you need to annotate one of your configuration classes with @EnableWebSecurity.
 */
@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
                .authorizeRequests()
                .antMatchers("/css/**", "/login").permitAll()
                .antMatchers("/secure/**").authenticated()
                    .and()
                .formLogin().loginPage("/login").failureUrl("/login-error");
    }


    @Autowired
    public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
        auth
                .inMemoryAuthentication()
                .withUser(User.withDefaultPasswordEncoder()
                        .username("user")
                        .password("password")
                        .roles("USER"));
    }
}

@@ -98,16 +98,68 @@
 owired;%0A
+import org.springframework.context.annotation.Bean;%0A
 import o
@@ -211,16 +211,16 @@
 ration;%0A
-
 import o
@@ -651,16 +651,166 @@
 ls.User;
+%0Aimport org.springframework.security.core.userdetails.UserDetailsService;%0Aimport org.springframework.security.provisioning.InMemoryUserDetailsManager;
 %0A%0A/**%0A *
@@ -1523,25 +1523,20 @@
 %0A%0A%0A    @
-Autowired
+Bean
 %0A    pub
@@ -1543,137 +1543,128 @@
 lic 
-void configureGlobal(AuthenticationManagerBuilder auth) throws Exception %7B%0A        auth%0A                .inMemoryAuthentication
+UserDetailsService userDetailsService() %7B%0A        InMemoryUserDetailsManager manager = new InMemoryUserDetailsManager
 ()
+;
 %0A   
@@ -1672,21 +1672,22 @@
     
-        .with
+manager.create
 User
@@ -1737,24 +1737,16 @@
         
-        
 .usernam
@@ -1771,24 +1771,16 @@
         
-  
-      
 .passwor
@@ -1809,24 +1809,16 @@
         
-        
 .roles(%22
@@ -1823,17 +1823,49 @@
 (%22USER%22)
-)
+.build());%0A        return manager
 ;%0A    %7D%0A

replace configGlobal with userDetailsService