diff --git a/oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization/authentication/JwtClientAssertionDecoderFactory.java b/oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization/authentication/JwtClientAssertionDecoderFactory.java index f0362ba8b..bb57bcbb8 100644 --- a/oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization/authentication/JwtClientAssertionDecoderFactory.java +++ b/oauth2-authorization-server/src/main/java/org/springframework/security/oauth2/server/authorization/authentication/JwtClientAssertionDecoderFactory.java @@ -88,13 +88,16 @@ public final class JwtClientAssertionDecoderFactory implements JwtDecoderFactory mappings.put(MacAlgorithm.HS512, "HmacSHA512"); JCA_ALGORITHM_MAPPINGS = Collections.unmodifiableMap(mappings); } + private static final RestTemplate rest = new RestTemplate(); + static { SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory(); requestFactory.setConnectTimeout(15_000); requestFactory.setReadTimeout(15_000); rest.setRequestFactory(requestFactory); } + private final Map jwtDecoders = new ConcurrentHashMap<>(); private Function> jwtValidatorFactory = DEFAULT_JWT_VALIDATOR_FACTORY; @@ -132,7 +135,8 @@ private static NimbusJwtDecoder buildDecoder(RegisteredClient registeredClient) JWT_CLIENT_AUTHENTICATION_ERROR_URI); throw new OAuth2AuthenticationException(oauth2Error); } - return NimbusJwtDecoder.withJwkSetUri(jwkSetUrl).jwsAlgorithm((SignatureAlgorithm) jwsAlgorithm).restOperations(rest).build(); + return NimbusJwtDecoder.withJwkSetUri(jwkSetUrl).jwsAlgorithm((SignatureAlgorithm) jwsAlgorithm) + .restOperations(rest).build(); } if (jwsAlgorithm instanceof MacAlgorithm) { String clientSecret = registeredClient.getClientSecret();