gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 14:23:32 24 4
gpt4 key购买 nike

我需要使用两个不同的授权服务器(两个 Okta 实例)来验证来自作为后端 REST API 层的单个 Spring Boot 应用程序中的两个不同 Web 应用程序的身份验证 token 。

目前我有一台资源服务器使用以下配置:

@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 header ,我想选择我的 Spring Boot 应用程序使用哪个 Okta 实例来解码和验证 JWT token 。

理想情况下,我的配置文件中有两个属性,如下所示:
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以匹配安全配置中的 header 值。我不能锻炼的是如何使用两种不同的 oauth2ResourceServer与安全配置一起使用的实例。

最佳答案

使用 Spring Boot ,现在不可能开箱即用。
Spring Security 5.3 提供了执行此操作的功能(spring boot 2.2.6 仍然不支持 spring security 5.3)。
请看以下问题:

https://github.com/spring-projects/spring-security/issues/7857
https://github.com/spring-projects/spring-security/pull/7887

通过遵循我提供的链接,可以手动配置资源服务器以使用多个身份提供者。提供的链接主要是针对spring boot webflux的开发。对于基本的 Spring Boot Web 开发,请观看此视频:

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

关于spring - 如何在同一个 Spring Boot 应用程序中使用多个 'JWK Set Uri' 值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60031919/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com