JAVA/SpringBoot
[SpringBoot] WebSecurityConfigurerAdapter 취소선 😀
박차
2023. 1. 10. 10:31
1. 문제 발견
WebSecurityConfigurerAdapter를 사용할 수 없음
2. 문제 이유
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
스프링 공식 사이트에서 WebSecurityConfigurerAdapter는 더이상 사용하지 않고
Spring Security 5.4에서는 SecurityFilterChain Bean을 생성하여 HttpSecurity를 구성하는 기능을 도입했다는 내용
3. 문제 해결
WebSecurityConfigurerAdapter 대신 SecurityFilterChain Bean을 생성
@Bean
protected SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/api/hello").permitAll()
.anyRequest().authenticated();
return http.build();
}
끝!