gpt4 book ai didi

spring - 如何在基于 Spring 的响应式(Reactive)应用程序中从身份验证中排除路径?

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

在非响应式 Spring 应用程序中,我通常会创建一个配置类,扩展 WebSecurityConfigurerAdapter并配置 WebSecurity像这样:

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

如何在响应式(Reactive)应用程序中执行等效操作?

最佳答案

在您用 @EnableWebFluxSecurity 注释的安全配置类中和 @EnableReactiveMethodSecurity ,注册一个bean如下:

@Bean
public SecurityWebFilterChain securityWebFilterChain(ServerHttpSecurity http) {
return http.authorizeExchange()
.pathMatchers("/pathToIgnore")
.permitAll()
.anyExchange()
.authenticated()
.and()
.formLogin()
.and()
.csrf()
.disable()
.build();
}

在这个配置中, pathMatchers("/pathToIgnore").permitAll()将其配置为允许匹配的路径从 auth 和 anyExchange().authenticated() 中排除。将其配置为对所有其他请求进行身份验证。

关于spring - 如何在基于 Spring 的响应式(Reactive)应用程序中从身份验证中排除路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52178552/

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