【发布时间】:2020-11-13 10:19:38
【问题描述】:
我们有以下场景:
- 多个“旧版”Spring Security Oauth2 身份验证服务器 (2.3.4) - 每个都配置了不同的 RSA 密钥,用于创建 JWT 令牌。
- 单个较新的(SS 5.3.3、SB 2.3.1)资源服务器,我们要接受来自任一身份验证服务器的令牌。
问题是资源服务器仅配置了 1 个密钥(当前)-因此它只能接受来自 1 个身份验证服务器的令牌。
是否有任何可以想象的方法来支持我们的资源服务器中的多个密钥来解码来自不同身份验证服务器的 JWT?
我们基本上想这样做,但有多个键: https://docs.spring.io/spring-security/site/docs/current/reference/html5/#oauth2resourceserver-jwt-decoder-public-key
Spring Security 5.3 表明这可以通过“多租户”https://docs.spring.io/spring-security/site/docs/current/reference/html5/#webflux-oauth2resourceserver-multitenancy 实现
这是一个基本配置
@Value("${security.oauth2.resourceserver.jwt.key-value}")
RSAPublicKey key;
@Override
protected void configure(HttpSecurity http) throws Exception {
http
// using new Spring Security SpE"{{LOCATOR_BASE_URL}}"L
//https://docs.spring.io/spring-security/site/docs/current/reference/htmlsingle/#webflux-oauth2resourceserver-jwt-authorization
.authorizeRequests(authorizeRequests ->
authorizeRequests
.antMatchers("/shipments/**").hasAuthority("SCOPE_DOMPick")
.anyRequest().authenticated()
)
.csrf().disable()
// ****** this is the new DSL way in Spring Security 5.2 instead of Spring Security Oauth @EnableResourceServer ******
.oauth2ResourceServer(oauth2ResourceServer ->
oauth2ResourceServer
.jwt(jwt ->
jwt.decoder(jwtDecoder())
)
);
}
// static key
@Bean
JwtDecoder jwtDecoder() {
return NimbusJwtDecoder.withPublicKey(this.key).build();
【问题讨论】:
标签: spring spring-boot spring-security jwt spring-security-oauth2