Spring Security 5.2-如何自定义OAuth2ResourceServer使用的NimbusJWTDecoder?

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

我有一个在本地运行的openid提供程序(openam)。我正在使用自签名证书,并且jwks网址为@ https://localhost:8443/openam/oauth2/connect/

由于ssl证书是自签名的,所以在解码oidc令牌时,我收到SSLHandshake异常。我尝试通过创建自定义的JwtDecoder(如https://docs.spring.io/spring-security/site/docs/current/reference/html5/#oauth2resourceserver-jwt-decoder-dsl中的建议)使用自定义的rest模板

@Bean
public JwtDecoder jwtDecoder() {
NimbusJwtDecoder.withJwkSetUri("https://localhost:8443/openam/oauth2/connect").restOperations(myCustomRestTemplateThatAllowsSelfSignedCerts()).build();
}

但是似乎未使用此解码器。 OidcIdTokenDecoderFactory用于创建解码器。此类似乎不允许我们传递自定义的jwtDecoder。

为什么oauthResourceServer()。jwt()。decoder(customDecoder())不起作用?我如何使解码器与具有自签名证书的网站jwks uri一起使用?

我正在考虑的一个选项是将自签名证书添加到我的jdk的cacerts文件夹中。

我有一个在本地运行的openid提供程序(openam)。我使用的是自签名证书,并且jwks网址为@ https:// localhost:8443 / openam / oauth2 / connect /,因为ssl证书是self ...

spring-security oauth-2.0 spring-security-oauth2 spring-oauth2 nimbus-jose-jwt
1个回答
0
投票

[OAuth2LoginAuthenticationFilter正在呼叫OidcAuthorizationCodeAuthenticationProvider以进行OpenID身份验证。要更改它使用的JwtDecoder,您应该有一个JwtDecoderFactory bean。

例如,您可能会有类似的内容:

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