웹 개발
[Spring Boot] WebSecurityConfigurerAdapter Deprecated 해결하기
moonmm
2023. 10. 4. 22:44
스프링 시큐리티 설정 작업도중
WebSecurityConfigurerAdapter가 Deprecated되어 아예 사용할 수 없었다.
나는 스프링부트3.1.4 버전을 사용했고 스프링 부트3.0 이상부터는 스프링시큐리티6.0 으로 자동 적용된다고 한다.
그리고 스프링시큐리티 6버전부터 WebSecurityConfigurerAdapter가 지원되지않는것이다!!
WebSecurityConfigurerAdapter를 사용하면서 config를 오버라이드 해서 작성하였는데,
이젠 bean으로 등록하도록 작성하면된다.
수정 전
@Override
protected void configure(HttpSecurity http) throws Exception {
// http 시큐리티 빌더
http.cors()
.and()
.csrf()
.disable()
.httpBasic()
.disable()
.sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and()
.authorizeRequests()
.antMatchers("/", "/auth/**").permitAll()
.anyRequest()
.authenticated();
http.addFilterAfter(
jwtAuthenticationFilter,
CorsFilter.class
);
}
WebSecurityConfigurerAdapter 를 상속받는 클래스 안에 오버라이드하여 configure 함수를 작성하였다.
수정 후
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
// http 시큐리티 빌더
http
.cors().and()
.csrf().disable()
.httpBasic().disable()
.sessionManagement(c -> c.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
.authorizeRequests()
.requestMatchers("/", "/auth/**").permitAll()
.anyRequest()
.authenticated();
http.addFilterAfter(
jwtAuthenticationFilter,
CorsFilter.class
);
return http.build();
}
이 클래스는 아무것도 상속받지않고
filterChain함수를 빈으로 등록하였다.
WebSecurityConfigurerAdapter를 상속받지 않고 filterChain을 빈으로 등록하면서 http시큐리티 빌더 작성부분도
조금씩 달라진 것 같았다. 정답일진 모르겠으나 나는 우선 해결했다..
더 공부해서 친절한 설명을 드리겠습니다...