在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将首先尝试解析提供的令牌。
发布于 2020-11-06 23:26:00
据我所知,在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();
}https://stackoverflow.com/questions/52740163
复制相似问题