기존에 webSecurityConfigurerAdapter가 굉장히 많은 역할을 해줬다는게 좀 느껴지네요.

Field authenticationManager in kr.co.kshproject.webDemo.interfaces.loginController required a bean of type 'org.springframework.security.authentication.AuthenticationManager' that could not be found.

에러가나는데 지금 아래와 같이 변경해서 작업중인데 에러가 나는군요 ㅠ webSecurityConfigurerAdapter가 그립네요 ㅎ ㅠ 퇴근하고 공부하는거라 많이 시간이 안나오네요 이번주 주말까지해서 회원가입시 SHA 256이용해서 비밀번호 변경하고 session을 이용해서 웹페이지마다 관리자가 이용하는 페이지 고객이 이용하는 페이지로 만들겁니다.

package kr.co.kshproject.webDemo.Common;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;
import org.springframework.security.authentication.AuthenticationProvider;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.authentication.configuration.GlobalAuthenticationConfigurerAdapter;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.web.SecurityFilterChain;

@Configuration
@EnableWebSecurity
public class SecurityConfig {

    @Autowired
    @Lazy
    private AuthenticationProvider myAuthenticationProvider;

    @Bean
    public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
        http.authorizeRequests()
                .antMatchers().permitAll()
                .anyRequest().authenticated()
                .and()
                .formLogin()
                .loginPage("/login")
                .defaultSuccessUrl("/Main")
                .permitAll()
                .and()
                .logout()
                .logoutUrl("/logout")
                .logoutSuccessUrl("/login")
                .permitAll();

        http.authenticationProvider(myAuthenticationProvider);

        return http.build();
    }
    @Configuration
    protected static class AuthenticationConfiguration extends GlobalAuthenticationConfigurerAdapter {

        @Autowired
        private AuthenticationProvider myAuthenticationProvider;

        @Override
        public void init(AuthenticationManagerBuilder auth) throws Exception {
            auth.authenticationProvider(myAuthenticationProvider);
        }
    }

    @Bean
    public AuthenticationProvider myAuthenticationProvider() {
        return new MyAuthenticationProvider();
    }

    @Bean
    public PasswordEncoder passwordEncoder() {
        return new BCryptPasswordEncoder();
    }
}

+ Recent posts