【发布时间】:2021-07-04 19:21:35
【问题描述】:
我正在尝试将所有以 /health 结尾的自定义端点列入白名单,但在 WebFlux Security 中,我无法使用正则表达式来匹配所有端点。例如/app/health、/app/meta/health、/app/custom/meta/health、/api/app/custom/meta/health 等。我没有找到任何模式(或正则表达式)将这些列入白名单 -在构造 SecurityWebFilterChain 时用一个条目指向。 如果我尝试使用正则表达式,我也会收到警告
spring-security '**' patterns are not supported in the middle of patterns and will be rejected in the future. Consider using '*' instead for matching a single path segment.
下面是代码sn-p
String[] ALLOWED_PATTERNS = {".*/health"};
// String[] ALLOWED_PATTERNS = {"/*/health"}; // allows whitelist /app/health endpoint
// String[] ALLOWED_PATTERNS = {"/*/health", "/*/*/health"}; // need generic way to whitelist all
@Bean
SecurityWebFilterChain springWebFilterChain(ServerHttpSecurity http) {
return http
.authorizeExchange()
.pathMatchers(ALLOWED_PATTERNS).permitAll()
.anyExchange().authenticated()
...
.build();
}
我可以通过提供 antMatchers 在 Spring Security 中实现相同的功能(不是响应式/Web Flux 安全性)
@Override
public void configure(WebSecurity web) {
web.ignoring().antMatchers("/**/health");
}
注意:这不是弹簧执行器健康端点,而是自定义健康端点
【问题讨论】:
标签: spring spring-boot spring-security spring-webflux whitelist