Reactive-Spring-Security-5.1.3.RELEASE, 多重授权

Reactive-Spring-Security-5.1.3.RELEASE, multiple authorizations

我们有一些端点,它们是安全的,在访问它们之前,我们正在验证 jws 是否正确。为了做到这一点,我们定义了一个 SecurityContext,它实际上持久化了 Auth pojo 并将其向下操纵到控制器中。 SecurityWebFilterChain 配置如下所示:

@Bean
public SecurityWebFilterChain securityWebFilterChain(ServerHttpSecurity http) {
    return http.csrf().disable()
            .formLogin().disable()
            .logout().disable()
            .httpBasic().disable()
            .securityContextRepository(securityContext)
            .authorizeExchange()
            .anyExchange().authenticated()
            .and()
            .build();
}

调用是在内部进行的,我们刚刚验证了 jws 令牌。

现在有一些外部客户端需要与我们集成,我们需要验证一个jwe令牌。问题是,我们需要以某种方式告诉 spring-security 来验证现有端点 jws 和新端点 jwe。

我尝试指定多个安全匹配器,但失败了 :( 。您还有其他建议吗?

您可以公开多个 bean。我建议指定顺序:

@Bean
@Order(1)
public SecurityWebFilterChain first(ServerHttpSecurity http) {
    http
        .securityMatcher(...)
        ...

    return http.build();
}

@Bean
@Order(2)
public SecurityWebFilterChain second(ServerHttpSecurity http) {
   http
       .securityMatcher(...)
       ...

   return http.build();
}

附带说明一下,Spring 安全性确实支持以反应方式验证 JWS 令牌,您可以使用它删除一些样板文件。