정수원님의 강의 스프링 시큐리티 완전 정복 [6.x 개정판] 보면서 공부한 내용입니다.
// /api/로 시작하는 URL에만 보안 필터 적용
http.securityMatcher("/api/**")
// /api/를 제외한 모든 URL에 보안 필터 적용
http .authorizeHttpRequests(authorize
-> authorize.anyRequest().authenticated())
api/user/
에 httpSecurity 요청이 오는 경우http.securityMatcher("/api/**")
와 http .authorizeHttpRequests(authorize -> authorize.anyRequest().authenticated())
요청을 처리하는 필터가 있다api/user/
의 경우 두 필터 모두 요청에 부합하므로 모두 작동이 가능하다@Order
어노테이션을 사용하여 http.securityMatcher("/api/**")
필터가 먼저 작동하도록 설정한다@Order(1)
// @Order 를 사용하여 어떤 SecurityFilterChain을 먼저 수행 할지 지정한다
// 아래 설정보다 우선적으로 보안 기능을 수행한다
public SecurityFilterChain apiFilterChain(HttpSecurity http) throws Exception {
http.securityMatcher("/api/**")
...
}
@Bean // @Order 가 지정되지 않으면 마지막으로 간주 된다
public SecurityFilterChain formLoginFilterChain(HttpSecurity http) throws Exception {
http .authorizeHttpRequests(authorize
-> authorize.anyRequest().authenticated())
...
}
HttpSecurity.with(C configurer, Customizer<C> customizer)
API가 필요하다public class MyCustomDsl extends AbstractHttpConfigurer<MyCustomDsl, HttpSecurity>
builder에는 HttpSecurity가 들어간다