如何在基于弹簧的响应式应用程序中从身份验证中排除路径?

问题描述 投票:1回答:1

在非反应式弹簧应用程序中,我通常会创建一个配置类,扩展WebSecurityConfigurerAdapter并配置WebSecurity,如:

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

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

spring security reactor
1个回答
2
投票

在您使用@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()会将其配置为对所有其他请求进行身份验证。

© www.soinside.com 2019 - 2024. All rights reserved.