Multiple Spring Security Configuration
@Bean
@Order(1)
SecurityFilterChain apiSecurityFilterChain(HttpSecurity http) throws Exception {
return http
.securityMatcher("/api/**")
.authorizeHttpRequests(auth -> {
auth.anyRequest().authenticated();
})
.sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
.httpBasic(Customizer.withDefaults())
.build();
}
@Bean
@Order(2)
SecurityFilterChain H2ConsoleSecurityFilterChain(HttpSecurity http) throws Exception {
return http
.securityMatcher(AntPathRequestMatcher.antMatcher("h2-console/**"))
.authorizeHttpRequests(auth -> {
auth.requestMatchers(AntPathRequestMatcher.antMatcher("/h2-console/**")).permitAll();
})
.csrf(csrf -> csrf.ignoringRequestMatchers(AntPathRequestMatcher.antMatcher("/h2-console/**")))
.headers(headers -> headers.frameOptions(Customizer.withDefaults()).disable())
.build();
}