httpSecurity : SecurityFilterChain 구성에 쓰인다. 보안 처리시 사용된다.
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http
.csrf().disable()
.headers().frameOptions().disable()
.and()
.authorizeRequests()
.antMatchers("/css/**","/images/**","/js/**","/h2/**").permitAll()
.antMatchers("/api/team/list/**").permitAll()
.antMatchers("/api/**").hasRole(Role.USER.name())
.anyRequest().authenticated()
.and().logout()
.logoutSuccessUrl("/api/team/list?page=1&size=10")
.and()
.oauth2Login()
.userInfoEndpoint()
.userService(customOAuth2UsersService)
.and()
.successHandler(authenticationSuccessHandler)
.defaultSuccessUrl("/api/team/list?page=1&size=10");
return http.build();
}
종종 우리가 하나의 SecurityFilterChain 말고 여러 SecurityFilterChain에 조건을 걸고 싶다면 WebSecurity를 사용한다고 한다. 보안 예외 처리(정적 리소스, HTML)로 사용된다.
@Bean
public WebSecurityCustomizer webSecurityCustomizer() {
return (web) -> web.ignoring().antMatchers("/h2/**", "/favicon.ico");
}