【问题标题】:Web ignoring using spring-webflux使用 spring-webflux 忽略 Web
【发布时间】:2019-03-15 08:40:39
【问题描述】:

在 spring-mvc 中可以从 WebSecurityConfigurerAdapter 扩展,覆盖 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 会先尝试解析提供的令牌。

【问题讨论】:

标签: java spring-security spring-webflux


【解决方案1】:

据我所知,确保 webflux 中的 spring security 忽略路径(和令牌)的等效方法是在 ServerHttpSecurity 上使用 securityMatcher() 方法。 IE。它应该与使用 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();
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-10-14
    • 2020-07-15
    • 2019-10-28
    • 2018-10-20
    • 2020-05-04
    • 2021-06-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多