In a spring-boot 2.4 application, I have two SecurityWebFilterChain
s. For only one of them, I want to add some WebFilter
s via addFilterBefore().
@Configuration
@EnableWebFluxSecurity
class WebSecurityConfig {
@Bean
fun filter1(service: Service): WebFilter = Filter1(service)
@Bean
fun filter2(component: Component): WebFilter = Filter2(component)
@Bean
@Order(1)
fun apiSecurityConfiguration(
http: ServerHttpSecurity,
filter1: WebFilter,
filter2: WebFilter
): SecurityWebFilterChain = http
.securityMatcher(pathMatchers("/path/**"))
.addFilterBefore(filter1, SecurityWebFiltersOrder.AUTHENTICATION)
.addFilterAt(filter2, SecurityWebFiltersOrder.AUTHENTICATION)
.build()
@Bean
@Order(2)
fun actuatorSecurityConfiguration(
http: ServerHttpSecurity,
reactiveAuthenticationManager: ReactiveAuthenticationManager
): SecurityWebFilterChain = http
.securityMatcher(pathMatchers("/manage/**"))
.authenticationManager(reactiveAuthenticationManager)
.httpBasic { }
.build()
}
However, as those WebFilter
s are created as beans, they are registered automatically and are applied to all requests, seemingly outside the security chain.
For servlet filters, it is possible to disable this registration with a FilterRegistrationBean
(see spring-boot documentation).
Is there a similar way for reactive WebFilter
s, or do I have to add additional URL filtering into those filters?