webflux安全中无上下文根路径的白名单端点

abithluo  于 2021-07-13  发布在  Java
关注(0)|答案(0)|浏览(635)

我试图将所有以/health结尾的自定义终结点列入白名单,但在webflux安全性中,我无法使用正则表达式匹配所有终结点。e、 g./app/health、/app/meta/health、/app/custom/meta/health、/api/app/custom/meta/health等等。在构建securitywebfilterchain时,我找不到任何模式用一个条目将这些端点列为白名单。如果我尝试使用regex,我也会得到警告

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.

下面是代码片段

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();
}

通过提供AntMatcher,我可以在spring中实现同样的安全性(而不是被动/web流量安全性)

@Override
public void configure(WebSecurity web) {
   web.ignoring().antMatchers("/**/health");
}

注意:这不是一个spring执行器健康端点,而是一个自定义健康端点

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题