Java/Spring Boot Security
Spring boot Security Filter에 예외 URL 적용
바리새인
2024. 9. 8. 23:20
String[] exceptUrl = {
"/",
"/error",
};
OrRequestMatcher orRequestMathcers = new OrRequestMatcher(Util.getRequestMatcher(exceptUrl));
NegatedRequestMatcher negatedRequestMatcher = new NegatedRequestMatcher(orRequestMathcers);
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http.authorizeHttpRequests((requests) -> requests
.requestMatchers(exceptUrl).permitAll()
.anyRequest().authenticated())
.addFilterBefore(new SecurityFilter(negatedRequestMatcher), UsernamePasswordAuthenticationFilter.class)
.formLogin((form) -> form
.loginPage("/login")
.permitAll())
.logout((logout) -> logout.permitAll());
return http.build();
}