Skip to content

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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");

Expand Down Expand Up @@ -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 {
Copy link
Contributor

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.


private RestTemplateWithTimeouts () {
SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
requestFactory.setConnectTimeout(RemoteJWKSet.DEFAULT_HTTP_CONNECT_TIMEOUT);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's please set this value to JWKSourceBuilder.DEFAULT_HTTP_CONNECT_TIMEOUT since RemoteJWKSet is deprecated.

requestFactory.setReadTimeout(RemoteJWKSet.DEFAULT_HTTP_READ_TIMEOUT);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's please set this value to JWKSourceBuilder.DEFAULT_HTTP_READ_TIMEOUT since RemoteJWKSet is deprecated.

setRequestFactory(requestFactory);
}

}

/**
* A builder for creating {@link NimbusJwtDecoder} instances based on a public key.
*/
Expand Down