Spring Security Reactive WebFilterChainProxy only calling a single filter chain

后端 未结 2 1753
耶瑟儿~
耶瑟儿~ 2021-01-19 14:14

I need to add security into a Webflux based app and have requirements that mean I need to add multiple filter chains. However, the current implementation of WebFilterC

2条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-19 14:45

    I was able to finally resolve this by using ServerWebExchangeMatchers. My use case involved enabling Basic Authentication when accessing Spring Actuator endpoints and no authentication on other paths. I was able to accomplish this by the following code:

    @Bean
    public SecurityWebFilterChain securityWebFilterChain(ServerHttpSecurity httpSecurity) 
    {
        httpSecurity
                .csrf().disable()
                .logout().disable()
                .formLogin().disable();
    
    
     httpSecurity.securityMatcher(ServerWebExchangeMatchers.pathMatchers("/actuator/**"))
                .httpBasic()
                .and()
                .authorizeExchange()
                .pathMatchers("/actuator/**")
                .hasRole(ACTUATOR_ADMIN_ROLE);
    
        return httpSecurity.build();
    }
    

提交回复
热议问题