如何在同一个 Spring Boot 应用程序中使用多个 "JWK Set Uri "值?

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

我需要使用两个不同的授权服务器(两个Okta实例)在一个Spring Boot应用程序(后端REST API层)中验证来自两个不同Web应用程序的验证令牌。

目前我有一个资源服务器,工作配置如下。

@Configuration
@EnableWebSecurity
public class ResourceServerSecurityConfig extends WebSecurityConfigurerAdapter {

  @Override
  protected void configure(HttpSecurity http) throws Exception{
    http
      .authorizeRequests().antMatchers("/public/**").permitAll()
      .anyRequest().authenticated()
      .and()
      .oauth2ResourceServer().jwt();
  }
}
spring.security.oauth2.resourceserver.jwt.issuer-uri=https://dev-X.okta.com/oauth2/default
spring.security.oauth2.resourceserver.jwt.jwk-set-uri=https://dev-X.okta.com/oauth2/default/v1/keys

和依赖关系 spring-security-oauth2-resource-serverspring-security-oauth2-jose 在我的Spring Boot应用程序(版本2.2.4.RELEASE)中,有以下内容

我想进入的最终状态是,根据请求中设置的自定义HTTP头,我想选择我的Spring Boot应用使用哪个Okta实例来解码和验证JWT令牌。

理想情况下,我将在配置文件中设置两个属性,如下所示。

jwkSetUri.X=https://dev-X.okta.com/oauth2/default/v1/keys
jwtIssuerUri.X=https://dev-X.okta.com/oauth2/default

jwkSetUri.Y=https://dev-Y.okta.com/oauth2/default/v1/keys
jwtIssuerUri.Y=https://dev-Y.okta.com/oauth2/default

我应该能够使用 RequestHeaderRequestMatcher 来匹配安全配置中的头值。我无法解决的是如何使用两个不同的 oauth2ResourceServer 我需要使用两个不同的授权服务器(两个Okta实例)来验证来自于一个Spring Boot中两个不同的Web应用程序的认证令牌。

spring spring-boot spring-security oauth-2.0 spring-security-oauth2
1个回答
1
投票

Spring Boot 5.3提供了这样的功能(spring boot 2.2.6仍然不支持spring security 5.3)。

https:/github.comspring-projectsspring-securityissues7857。 https:/github.comspring-projectsspring-securitypull7887。

可以通过以下链接手动配置资源服务器,使用多个身份提供者。提供的链接主要是针对spring boot webflux开发的。关于基本的spring boot web开发,请看这个视频。

https:/www.youtube.comwatch?v=ke13w8nab-k

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