我需要向基于 Webflux 的应用程序添加安全性,并且有一些要求意味着我需要添加多个过滤器链。然而,目前的实施WebFilterChainProxy
uses Flux.filterWhen(...)
如果我正确阅读文档,它只会返回链中的第一个匹配项。
鉴于上述我有三个问题:-
我的反应知识非常有限,有人可以确认我的理解吗filterWhen
是否正确?
如果是这样,有人可以建议一种方法让多个过滤器链在新的 Spring Security 5 响应式模型中工作吗?
如果我误解了 filterWhen 方法的工作原理,任何人都可以提出任何建议,为什么只处理我的过滤器链之一?
我向链添加过滤器的方式是使用多种配置方法,并用注释@Order
,类似于下面的代码块。
@Configration
@EnableWebFluxSecurity
public class SecurityConfig
...
@Bean
@Order(1)
SecurityWebFilterChain chain1(ServerHttpSecurity http) {
return http.httpBasic().disable()......
}
@Bean
@Order(2)
SecurityWebFilterChain chain2(ServerHttpSecurity http) {
return http.httpBasic().disable()......
}
@Bean
@Order(3)
SecurityWebFilterChain chain3(ServerHttpSecurity http) {
return http.httpBasic().disable()......
}
...
}
当我调试应用程序时,我可以看到所有三个过滤器都已添加到WebFilterChainProxy
但我只得到一个匹配的过滤器。我需要找到一种返回所有匹配的过滤器的方法。
有人可以帮忙吗?
我终于能够通过使用解决这个问题服务器Web交换匹配器。我的用例涉及在访问 Spring Actuator 端点时启用基本身份验证,而在其他路径上不进行身份验证。我能够通过以下代码完成此任务:
@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();
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)