具有SpringWebFlux安全性的匿名请求

具有SpringWebFlux安全性的匿名请求,spring,spring-security,spring-webflux,Spring,Spring Security,Spring Webflux,我正在尝试使用SpringWebfux安全性来保护SPA中的路径。要保护的路径为“/**/orderbook”,所有其他路径都应开放供匿名访问。我必须如何为此配置Spring安全性?目前,它总是要求登录,而不仅仅是要保护路径 我的Webflux配置: @Bean SecurityWebFilterChain springWebFilterChain(ServerHttpSecurity http) throws Exception { return http

我正在尝试使用SpringWebfux安全性来保护SPA中的路径。要保护的路径为“/**/orderbook”,所有其他路径都应开放供匿名访问。我必须如何为此配置Spring安全性?目前,它总是要求登录,而不仅仅是要保护路径

我的Webflux配置:

@Bean       
SecurityWebFilterChain springWebFilterChain(ServerHttpSecurity http) throws Exception {     

    return http
            .csrf().disable()
            .httpBasic().disable()
            .formLogin().disable()
            .logout().disable()
            .securityContextRepository(this.jwtSecContextRepository)
            .authorizeExchange()
            .pathMatchers("/**/orderbook").authenticated()
            .anyExchange().permitAll()
            .and().build();
     }
}
JwtSecContextRepository如下所示:

    @Component
public class JwtSecurityContextRepository implements ServerSecurityContextRepository {

    @Override
    public Mono<Void> save(ServerWebExchange exchange, SecurityContext context) {
        return null;
    }

    @Override
    public Mono<SecurityContext> load(ServerWebExchange exchange) {
        LinkedList<SimpleGrantedAuthority> linkedList = new LinkedList<>();
        linkedList.add(new SimpleGrantedAuthority("USERS"));
        Authentication auth = new JwtAuthenticationToken("user", "password", linkedList);           
        return Mono.just(new SecurityContextImpl(auth));
    }

}
@组件
公共类JwtSecurityContextRepository实现ServerSecurityContextRepository{
@凌驾
公共Mono存储(ServerWebExchange、SecurityContext上下文){
返回null;
}
@凌驾
公共Mono加载(服务器WebExchange){
LinkedList LinkedList=新建LinkedList();
添加(新的SimpleGrantedAuthority(“用户”);
Authentication auth=新的JwtAuthenticationToken(“用户”、“密码”、linkedList);
返回Mono.just(新的SecurityContextImpl(auth));
}
}
我缺少匿名访问这样的功能。SecurityContextRepository试图提供这一点,但没有成功。我觉得SecurityContentExterepository一点效果都没有


有人知道吗?

检查这是否有帮助谢谢你的帮助。我试过了,因为我在jetty上使用异步servlet,所以我需要使用WebSecurity。