WebSecurityConfigurerAdapter Deprecated

 

 

 

 

 

 

 

 

 

 

 

WebSecurityConfigurerAdapter Deprecated 이유

출처: https://spring.io/blog/2022/02/21/spring-security-without-the-websecurityconfigureradapter

 

시큐리티 설정 클래스를 사용하려 WebSecurityConfigurerAdapter 클래스를 상속받으려 했는데 스프링 부트 2.7, Spring Security 5.7 이후 버전부터 WebSecurityConfigurerAdapter 클래스가 Deprecated 되었다.

 

 

 

 

 

 

 

 

 

 

 

 

해결: WebSecurityConfigurerAdapter 대체

이에 대한 대처 방법으로 공식 문서를 확인하면 된다.

공식 문서에 나와있는 여러 대체 방법 중 HttpSession 기반인 HttpSecurity 기반 부분을 옮겨적도록 하겠다.

 

 

HttpSecurity 구성

  • 변경 전: WebSecurityConfigurerAdapter를 상속
@Configuration
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
        	.authorizeHttpRequests((authz) -> authz
                .anyRequest().authenticated()
            )
            .httpBasic(withDefaults());
    }

}

 

 

  • 변경 후: SecurityFilterChain 빈 등록
@Configuration
public class SecurityConfiguration {

    @Bean
    public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
        http
            .authorizeHttpRequests((authz) -> authz
                .anyRequest().authenticated()
            )
            .httpBasic(withDefaults());
        return http.build();
    }

}