import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter{
@Override(100)
protected void configure(HttpSecurity http) throws Exception {
http.antMatchers("/foo/**").authenticated()
.csrf.disable()
.authorizeRequests();
}
@Override(200)
protected void configure(HttpSecurity http) throws Exception {
http.mvcMatcher("/bar/**");
}
@Override(300)
protected void configure(HttpSecurity http) throws Exception {
http.mvcMatcher("/**");
}
}
WebSecurityConfigurerAdapter 클래스는 Spring Security 에서 설정들을 다양하게 커스터마이징 할 수 있는 변경 포인트를 제공하는 설정자 클래스이다.
위의 설정들은 /foo/** , /bar/, / 의 경로들에 대해 필터를 설정해주는 것을 볼 수 있다.
또한 다양한 설정들을 할 수 있다. 이 때 내가 직접설정한 configure를 사용할 수도 있고, 내장되어 있는 것들(csrf.disable() 같은 configure들) 과 init()을 가져와 위의 configure들을 build하여 쓸 수 있다.
이렇게 만들어진 SecurityFilterChain 은 WebSecurity를 통해서 FilterChainProxy에 넣어준다.