|
1 | 1 | /* |
2 | | - * Copyright 2020-2022 the original author or authors. |
| 2 | + * Copyright 2020-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. |
|
28 | 28 |
|
29 | 29 | import javax.crypto.spec.SecretKeySpec; |
30 | 30 |
|
| 31 | +import org.springframework.http.client.SimpleClientHttpRequestFactory; |
31 | 32 | import org.springframework.security.oauth2.core.ClientAuthenticationMethod; |
32 | 33 | import org.springframework.security.oauth2.core.DelegatingOAuth2TokenValidator; |
33 | 34 | import org.springframework.security.oauth2.core.OAuth2AuthenticationException; |
|
51 | 52 | import org.springframework.util.Assert; |
52 | 53 | import org.springframework.util.CollectionUtils; |
53 | 54 | import org.springframework.util.StringUtils; |
| 55 | +import org.springframework.web.client.RestTemplate; |
54 | 56 | import org.springframework.web.util.UriComponentsBuilder; |
55 | 57 |
|
56 | 58 | /** |
@@ -87,6 +89,15 @@ public final class JwtClientAssertionDecoderFactory implements JwtDecoderFactory |
87 | 89 | JCA_ALGORITHM_MAPPINGS = Collections.unmodifiableMap(mappings); |
88 | 90 | } |
89 | 91 |
|
| 92 | + private static final RestTemplate restTemplate = new RestTemplate(); |
| 93 | + |
| 94 | + static { |
| 95 | + SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory(); |
| 96 | + requestFactory.setConnectTimeout(15_000); |
| 97 | + requestFactory.setReadTimeout(15_000); |
| 98 | + restTemplate.setRequestFactory(requestFactory); |
| 99 | + } |
| 100 | + |
90 | 101 | private final Map<String, JwtDecoder> jwtDecoders = new ConcurrentHashMap<>(); |
91 | 102 | private Function<RegisteredClient, OAuth2TokenValidator<Jwt>> jwtValidatorFactory = DEFAULT_JWT_VALIDATOR_FACTORY; |
92 | 103 |
|
@@ -124,7 +135,8 @@ private static NimbusJwtDecoder buildDecoder(RegisteredClient registeredClient) |
124 | 135 | JWT_CLIENT_AUTHENTICATION_ERROR_URI); |
125 | 136 | throw new OAuth2AuthenticationException(oauth2Error); |
126 | 137 | } |
127 | | - return NimbusJwtDecoder.withJwkSetUri(jwkSetUrl).jwsAlgorithm((SignatureAlgorithm) jwsAlgorithm).build(); |
| 138 | + return NimbusJwtDecoder.withJwkSetUri(jwkSetUrl).jwsAlgorithm((SignatureAlgorithm) jwsAlgorithm) |
| 139 | + .restOperations(restTemplate).build(); |
128 | 140 | } |
129 | 141 | if (jwsAlgorithm instanceof MacAlgorithm) { |
130 | 142 | String clientSecret = registeredClient.getClientSecret(); |
|
0 commit comments