繁体   English   中英

使用 spring-webflux 忽略网络

[英]Web ignoring using spring-webflux

在 spring-mvc 中可以从WebSecurityConfigurerAdapter扩展,覆盖configure(WebSecurity web)并做一些这样的configure(WebSecurity web)

@Override
public void configure(WebSecurity web) throws Exception {
    web.ignoring().antMatchers(AUTH_WHITE_LIST);
}

这种方法的主要好处是 spring-security 甚至不会尝试解码传递的令牌。 是否可以使用 webflux 做几乎相同的事情?

我知道我可以这样做:

@Bean
public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) throws Exception {
    http.csrf().disable()
            .authorizeExchange().pathMatchers(AUTH_WHITE_LIST).permitAll()
            .anyExchange().authenticated();
    return http.build();
}

但是这样,据我所知,spring-security 将首先尝试解析提供的令牌。

据我所知,确保 webflux 中的 spring 安全性忽略路径(和令牌)的等价物是在 ServerHttpSecurity 上使用 securityMatcher() 方法。 即它应该与使用 antMatchers 的 WebSecurity#ignoring() 方法相同。

@Bean
public SecurityWebFilterChain springSecurityFilterChain(ServerHttpSecurity http) {
    return http.securityMatcher(new NegatedServerWebExchangeMatcher(
                ServerWebExchangeMatchers.pathMatchers("/ignore/this/path")))
            .authorizeExchange()
                .anyExchange().authenticated()
            .and()
                .csrf().disable()
             .build();
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM