|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2019 the original author or authors. |
| 2 | + * Copyright 2002-2023 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
49 | 49 | import org.springframework.security.oauth2.jwt.NimbusJwtDecoder;
|
50 | 50 | import org.springframework.util.Assert;
|
51 | 51 | import org.springframework.util.StringUtils;
|
| 52 | +import org.springframework.web.client.RestOperations; |
| 53 | +import org.springframework.web.client.RestTemplate; |
52 | 54 |
|
53 | 55 | /**
|
54 | 56 | * A {@link JwtDecoderFactory factory} that provides a {@link JwtDecoder} used for
|
@@ -89,6 +91,9 @@ public final class OidcIdTokenDecoderFactory implements JwtDecoderFactory<Client
|
89 | 91 | private Function<ClientRegistration, Converter<Map<String, Object>, Map<String, Object>>> claimTypeConverterFactory = (
|
90 | 92 | clientRegistration) -> DEFAULT_CLAIM_TYPE_CONVERTER;
|
91 | 93 |
|
| 94 | + private Function<ClientRegistration, RestOperations> restOperationsFactory = ( |
| 95 | + clientRegistration) -> new RestTemplate(); |
| 96 | + |
92 | 97 | /**
|
93 | 98 | * Returns the default {@link Converter}'s used for type conversion of claim values
|
94 | 99 | * for an {@link OidcIdToken}.
|
@@ -164,7 +169,10 @@ private NimbusJwtDecoder buildDecoder(ClientRegistration clientRegistration) {
|
164 | 169 | null);
|
165 | 170 | throw new OAuth2AuthenticationException(oauth2Error, oauth2Error.toString());
|
166 | 171 | }
|
167 |
| - return NimbusJwtDecoder.withJwkSetUri(jwkSetUri).jwsAlgorithm((SignatureAlgorithm) jwsAlgorithm).build(); |
| 172 | + return NimbusJwtDecoder.withJwkSetUri(jwkSetUri) |
| 173 | + .jwsAlgorithm((SignatureAlgorithm) jwsAlgorithm) |
| 174 | + .restOperations(restOperationsFactory.apply(clientRegistration)) |
| 175 | + .build(); |
168 | 176 | }
|
169 | 177 | if (jwsAlgorithm != null && MacAlgorithm.class.isAssignableFrom(jwsAlgorithm.getClass())) {
|
170 | 178 | // https://openid.net/specs/openid-connect-core-1_0.html#IDTokenValidation
|
@@ -237,4 +245,18 @@ public void setClaimTypeConverterFactory(
|
237 | 245 | this.claimTypeConverterFactory = claimTypeConverterFactory;
|
238 | 246 | }
|
239 | 247 |
|
| 248 | + /** |
| 249 | + * Sets the factory that provides a {@link RestOperations} used by |
| 250 | + * {@link NimbusJwtDecoder} to coordinate with the authorization servers indicated in |
| 251 | + * the <a href="https://tools.ietf.org/html/rfc7517#section-5">JWK Set</a> uri. |
| 252 | + * @param restOperationsFactory the factory that provides a {@link RestOperations} |
| 253 | + * used by {@link NimbusJwtDecoder} |
| 254 | + * |
| 255 | + * @since 6.3 |
| 256 | + */ |
| 257 | + public void setRestOperationsFactory(Function<ClientRegistration, RestOperations> restOperationsFactory) { |
| 258 | + Assert.notNull(restOperationsFactory, "restOperationsFactory cannot be null"); |
| 259 | + this.restOperationsFactory = restOperationsFactory; |
| 260 | + } |
| 261 | + |
240 | 262 | }
|
0 commit comments