Ник*_*ель 5 java spring-security spring-webflux
在 spring-mvc 中可以扩展 from WebSecurityConfigurerAdapter,覆盖configure(WebSecurity web)并做一些这样的思考:
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers(AUTH_WHITE_LIST);
}
Run Code Online (Sandbox Code Playgroud)
这种方法的主要好处是 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();
}
Run Code Online (Sandbox Code Playgroud)
但是这样,据我所知,spring-security 将首先尝试解析提供的令牌。
小智 16
据我所知,确保 webflux 中的 spring security 忽略路径(和令牌)的等效方法是在 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();
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1002 次 |
| 最近记录: |