gpt4 book ai didi

java - 使用 spring-webflux 忽略网络

转载 作者:行者123 更新时间:2023-12-03 11:20:11 25 4
gpt4 key购买 nike

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

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

这种方法的主要好处是 spring-security 甚至不会尝试解码传递的 token 。是否可以使用 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 将首先尝试解析提供的 token 。

最佳答案

据我所知,确保 webflux 中的 spring 安全性忽略路径(和 token )的等价物是在 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();
}

关于java - 使用 spring-webflux 忽略网络,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52740163/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com