首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用spring-webflux忽略Web

使用spring-webflux忽略Web
EN

Stack Overflow用户
提问于 2018-10-10 20:21:34
回答 1查看 1.2K关注 0票数 5

在spring中-mvc可以从WebSecurityConfigurerAdapter扩展,覆盖configure(WebSecurity web),并像这样思考:

代码语言:javascript
复制
@Override
public void configure(WebSecurity web) throws Exception {
    web.ignoring().antMatchers(AUTH_WHITE_LIST);
}

这种方法的主要好处是spring-security甚至不会尝试解码传递的令牌。除了使用webflux之外,有没有可能做同样的事情?

我知道我可以这样做:

代码语言:javascript
复制
@Bean
public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) throws Exception {
    http.csrf().disable()
            .authorizeExchange().pathMatchers(AUTH_WHITE_LIST).permitAll()
            .anyExchange().authenticated();
    return http.build();
}

但据我所知,通过这种方式,spring-security将首先尝试解析提供的令牌。

EN

回答 1

Stack Overflow用户

发布于 2020-11-06 23:26:00

据我所知,在webflux中确保路径(和标记)被spring安全忽略的等效方法是在ServerHttpSecurity上使用securityMatcher()方法。也就是说,它应该与在antMatchers中使用WebSecurity#ignoring()方法相同。

代码语言:javascript
复制
@Bean
public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {
    return http.securityMatcher(new NegatedServerWebExchangeMatcher(
                ServerWebExchangeMatchers.pathMatchers("/ignore/this/path")))
            .authorizeExchange()
                .anyExchange().authenticated()
            .and()
                .csrf().disable()
             .build();
}
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52740163

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档