웹/Spring
WebSecurityConfigurerAdapter 사용 불가
컴퓨터과학
2022. 9. 1. 21:19
WebSecurityConfigurerAdapter 사용 불가 현상
Spring 5.7버전 이상부터는 사용 불가하다고 합니다.
https://spring.io/blog/2022/02/21/spring-security-without-the-websecurityconfigureradapter
Spring Security without the WebSecurityConfigurerAdapter
<p>In Spring Security 5.7.0-M2 we <a href="https://github.com/spring-projects/spring-security/issues/10822">deprecated</a> the <code>WebSecurityConfigurerAdapter</code>, as we encourage users to move towards a component-based security configuration.</p> <p
spring.io
그래서
간단하게 configure 함수 오버라이당 했던 방식으로 간단하게 보여드리겠습니다.
변경 전
@Configuration
@EnableWebSecurity
public class SecurityJavaConfig extends WebSecurityConfigurerAdapter
{
@Override
protected void configure(HttpSecurity http){
http.formLogin().disable();
}
}
변경후
@Configuration
@EnableWebSecurity
public class SecurityJavaConfig {
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http.formLogin().disable();
return http.build();
}
}
WebSecurityConfigurerAdapter 상속 받은 configure 오버라이딩 된 함수 대신해서 WebSceurtyConfiguration에서 제공하는 filterChain 함수를 사용합니다 대신 return으로 항상 http를 빌드해줍니다. (http.build())