spring
WebSecurityConfigurerAdapter is deprecated
고줭
2022. 8. 3. 19:08
Spring Security를 사용하며 Config를 정의하는 클래스는 그 동안 WebSecurityConfigurerAdapter를 extends해서 configure(HttpSecurity)를 Override해 사용해왔지만 deprecated된 후에는 SecurityFilterChain을 return 하는 메서드를 만들어 @Bean 을 등록해서 써야합니다.
기존코드
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeHttpRequests()
.mvcMatchers("/", "/login", "/sign-up", "/check-email", "/check-email-token",
"/email-login", "/check-email-login", "/login-link").permitAll()
.mvcMatchers(HttpMethod.GET, "/profile/*").permitAll()
.anyRequest().authenticated();
}
}
SecurityFilterChain을 리턴하는 코드
@EnableWebSecurity
public class SecurityConfig {
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http
.authorizeHttpRequests((authz) -> authz
.mvcMatchers("/", "/login", "/sign-up", "/check-email", "/check-email-token",
"/email-login", "/check-email-login", "/login-link").permitAll()
.mvcMatchers(HttpMethod.GET, "/profile/*").permitAll()
.anyRequest().authenticated());
return http.build();
}
}
위와같이 바꿔 쓸 수 있습니다.
현재 백기선선생님의 "스프링과 JPA 기반 웹 애플리케이션 개발"의 강의를 보고 있지만 강의 시간상 Deprecated되기 전 강의인가 보네요
@EnableWebSecurity에 @Configuration이 있는데 왜 둘 다 선언하신건 왜 일까용..