|
66 | 66 | import org.springframework.http.MediaType;
|
67 | 67 | import org.springframework.http.RequestEntity;
|
68 | 68 | import org.springframework.http.ResponseEntity;
|
| 69 | +import org.springframework.http.client.SimpleClientHttpRequestFactory; |
69 | 70 | import org.springframework.security.oauth2.core.OAuth2Error;
|
70 | 71 | import org.springframework.security.oauth2.core.OAuth2TokenValidator;
|
71 | 72 | import org.springframework.security.oauth2.core.OAuth2TokenValidatorResult;
|
@@ -294,7 +295,7 @@ public static final class JwkSetUriJwtDecoderBuilder {
|
294 | 295 |
|
295 | 296 | private final Set<SignatureAlgorithm> signatureAlgorithms = new HashSet<>();
|
296 | 297 |
|
297 |
| - private RestOperations restOperations = new RestTemplate(); |
| 298 | + private RestOperations restOperations = new RestTemplateWithNimbusDefaultTimeouts(); |
298 | 299 |
|
299 | 300 | private Cache cache = new NoOpCache("default");
|
300 | 301 |
|
@@ -556,6 +557,21 @@ public void close() {
|
556 | 557 |
|
557 | 558 | }
|
558 | 559 |
|
| 560 | + /** |
| 561 | + * A RestTemplate with timeouts configured to avoid blocking indefinitely when |
| 562 | + * fetching JWK Sets while holding the reentrantLock. |
| 563 | + */ |
| 564 | + private static final class RestTemplateWithNimbusDefaultTimeouts extends RestTemplate { |
| 565 | + |
| 566 | + private RestTemplateWithNimbusDefaultTimeouts() { |
| 567 | + SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory(); |
| 568 | + requestFactory.setConnectTimeout(JWKSourceBuilder.DEFAULT_HTTP_CONNECT_TIMEOUT); |
| 569 | + requestFactory.setReadTimeout(JWKSourceBuilder.DEFAULT_HTTP_READ_TIMEOUT); |
| 570 | + setRequestFactory(requestFactory); |
| 571 | + } |
| 572 | + |
| 573 | + } |
| 574 | + |
559 | 575 | /**
|
560 | 576 | * A builder for creating {@link NimbusJwtDecoder} instances based on a public key.
|
561 | 577 | */
|
|
0 commit comments