在非反应式弹簧应用程序中,我通常会创建一个配置类,扩展WebSecurityConfigurerAdapter
并配置WebSecurity
,如:
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers("/pathToIgnore");
}
如何在响应式应用程序中执行等效操作?
在您使用@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()
会将其配置为对所有其他请求进行身份验证。