|
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;
|
@@ -293,7 +294,7 @@ public static final class JwkSetUriJwtDecoderBuilder {
|
293 | 294 |
|
294 | 295 | private final Set<SignatureAlgorithm> signatureAlgorithms = new HashSet<>();
|
295 | 296 |
|
296 |
| - private RestOperations restOperations = new RestTemplate(); |
| 297 | + private RestOperations restOperations = new RestTemplateWithNimbusDefaultTimeouts(); |
297 | 298 |
|
298 | 299 | private Cache cache = new NoOpCache("default");
|
299 | 300 |
|
@@ -545,6 +546,21 @@ public void close() {
|
545 | 546 |
|
546 | 547 | }
|
547 | 548 |
|
| 549 | + /** |
| 550 | + * A RestTemplate with timeouts configured to avoid blocking indefinitely when |
| 551 | + * fetching JWK Sets while holding the reentrantLock. |
| 552 | + */ |
| 553 | + private static final class RestTemplateWithNimbusDefaultTimeouts extends RestTemplate { |
| 554 | + |
| 555 | + private RestTemplateWithNimbusDefaultTimeouts() { |
| 556 | + SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory(); |
| 557 | + requestFactory.setConnectTimeout(JWKSourceBuilder.DEFAULT_HTTP_CONNECT_TIMEOUT); |
| 558 | + requestFactory.setReadTimeout(JWKSourceBuilder.DEFAULT_HTTP_READ_TIMEOUT); |
| 559 | + setRequestFactory(requestFactory); |
| 560 | + } |
| 561 | + |
| 562 | + } |
| 563 | + |
548 | 564 | /**
|
549 | 565 | * A builder for creating {@link NimbusJwtDecoder} instances based on a public key.
|
550 | 566 | */
|
|
0 commit comments