-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Align NimbusJwtDecoder HTTP timeout defaults with Nimbus by setting to 500ms #17669
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,7 @@ | |
import com.nimbusds.jose.jwk.source.JWKSetSource; | ||
import com.nimbusds.jose.jwk.source.JWKSource; | ||
import com.nimbusds.jose.jwk.source.JWKSourceBuilder; | ||
import com.nimbusds.jose.jwk.source.RemoteJWKSet; | ||
import com.nimbusds.jose.proc.DefaultJOSEObjectTypeVerifier; | ||
import com.nimbusds.jose.proc.JOSEObjectTypeVerifier; | ||
import com.nimbusds.jose.proc.JWSKeySelector; | ||
|
@@ -66,6 +67,7 @@ | |
import org.springframework.http.MediaType; | ||
import org.springframework.http.RequestEntity; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.http.client.SimpleClientHttpRequestFactory; | ||
import org.springframework.security.oauth2.core.OAuth2Error; | ||
import org.springframework.security.oauth2.core.OAuth2TokenValidator; | ||
import org.springframework.security.oauth2.core.OAuth2TokenValidatorResult; | ||
|
@@ -293,7 +295,7 @@ public static final class JwkSetUriJwtDecoderBuilder { | |
|
||
private final Set<SignatureAlgorithm> signatureAlgorithms = new HashSet<>(); | ||
|
||
private RestOperations restOperations = new RestTemplate(); | ||
private RestOperations restOperations = new RestTemplateWithTimeouts(); | ||
|
||
private Cache cache = new NoOpCache("default"); | ||
|
||
|
@@ -545,6 +547,21 @@ public void close() { | |
|
||
} | ||
|
||
/** | ||
* A RestTemplate with timeouts configured to avoid blocking indefinitely when | ||
* fetching JWK Sets while holding the reentrantLock. | ||
*/ | ||
private static final class RestTemplateWithTimeouts extends RestTemplate { | ||
|
||
private RestTemplateWithTimeouts () { | ||
SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory(); | ||
requestFactory.setConnectTimeout(RemoteJWKSet.DEFAULT_HTTP_CONNECT_TIMEOUT); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's please set this value to |
||
requestFactory.setReadTimeout(RemoteJWKSet.DEFAULT_HTTP_READ_TIMEOUT); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's please set this value to |
||
setRequestFactory(requestFactory); | ||
} | ||
|
||
} | ||
|
||
/** | ||
* A builder for creating {@link NimbusJwtDecoder} instances based on a public key. | ||
*/ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To make the intent of this class clearer, will you please name it
RestTemplateWithNimbusDefaultTimeouts
.Please also remove the extra whitespace between
class
and the class name.