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이 있는데 왜 둘 다 선언하신건 왜 일까용..
'spring' 카테고리의 다른 글
SignUpForm에대한 Validator (0) | 2022.08.04 |
---|---|
[JPA] table, entity 만들고 테스트하기 (0) | 2022.02.19 |
[Spring Boot] XCAPE Hint Project (0) | 2021.06.21 |
[스프링 프로젝트] 인스타그램 - 데이터베이스 (MySQL) (1) | 2021.05.04 |
[스프링 프로젝트] 인스타그램 - 첫 페이지와 회원가입 페이지 (0) | 2021.05.04 |