처음부터 차근차근
스프링 시큐리티 : WebSecurityConfigurerAdapter deprecated 본문
'org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter' is deprecated
: 'org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter'는 더 이상 사용되지 않습니다.
스프링 시큐리티 설정파일을 작성하던 도중 마주친 warning이다.
WebSecurityConfigurerAdapter class가 deprecated 됐다.
spring WebSecurityConfigurerAdapter class 공식문서로 가봤더니 해결방법이 나와있었다.
WebSecurityConfigurerAdapter class 공식문서 링크 : https://docs.spring.io/spring-security/site/docs/current/api/org/springframework/security/config/annotation/web/configuration/WebSecurityConfigurerAdapter.html
Deprecated.
Use a SecurityFilterChain Bean to configure HttpSecurity or a WebSecurityCustomizer Bean to configure WebSecurity
: 더 이상 사용되지 않습니다.
SecurityFilterChain Bean을 사용하여 HttpSecurity를 구성하거나 WebSecurityCustomizer Bean을 사용하여 WebSecurity를 구성하십시오.
bean으로 만들라고 하는 건 알겠는데, 이 글만 읽고는 이해가 안돼서 spring security 공식문서를 더 읽어보았다.
spring security 공식문서 링크 : https://spring.io/blog/2022/02/21/spring-security-without-the-websecurityconfigureradapter
WebSecurityConfigurerAdapter 상속을 없애고 configure() 메서드의 반환형식을 SecurityFilterChain으로 바꾼다음 bean으로 설정하라고 쓰여있다.
수정 전 코드
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/noticeboard/**").authenticated()
.antMatchers("/admin/**").hasRole("ADMIN")
.anyRequest().permitAll();
}
}
수정 후 코드
@Configuration
@EnableWebSecurity
public class WebSecurityConfig {
@Bean
public SecurityFilterChain configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/noticeboard/**").authenticated()
.antMatchers("/admin/**").hasRole("ADMIN")
.anyRequest().permitAll();
return http.build();
}
}
이렇게하니까 warning이 사라졌다!
'Error&Warning' 카테고리의 다른 글
swagger 관련 에러 : Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NullPointerException (0) | 2022.09.06 |
---|---|
jsp : No operations allowed after connection closed. (0) | 2022.08.07 |
cause: error: invalid source release: 17 (2) | 2022.07.14 |
Git : Not a valid object name: 'master' (0) | 2022.04.30 |
~가 ~에 이미 정의되어 있습니다.(C언어) (2) | 2022.04.29 |