Skip to content

Commit

Permalink
Add reasonable timeout to JwtDecoderProviderConfigurationUtils and Ni…
Browse files Browse the repository at this point in the history
…mbusJwtDecoder
  • Loading branch information
MrJovanovic13 committed Apr 11, 2024
1 parent 61eba00 commit 4afa21c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.RequestEntity;
import org.springframework.http.ResponseEntity;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.security.oauth2.jose.jws.SignatureAlgorithm;
import org.springframework.util.Assert;
import org.springframework.web.client.HttpClientErrorException;
Expand All @@ -65,6 +66,15 @@ final class JwtDecoderProviderConfigurationUtils {

private static final RestTemplate rest = new RestTemplate();

static {
int connectTimeout = Integer.parseInt(System.getProperty("sun.net.client.defaultConnectTimeout", "30000"));
int readTimeout = Integer.parseInt(System.getProperty("sun.net.client.defaultReadTimeout", "30000"));
SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
requestFactory.setConnectTimeout(connectTimeout);
requestFactory.setReadTimeout(readTimeout);
rest.setRequestFactory(requestFactory);
}

private static final ParameterizedTypeReference<Map<String, Object>> STRING_OBJECT_MAP = new ParameterizedTypeReference<Map<String, Object>>() {
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,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 @@ -271,7 +272,16 @@ public static final class JwkSetUriJwtDecoderBuilder {

private Set<SignatureAlgorithm> signatureAlgorithms = new HashSet<>();

private RestOperations restOperations = new RestTemplate();
private RestOperations restOperations = this.buildRestTemplateWithDefaultTimeoutValues();

private RestTemplate buildRestTemplateWithDefaultTimeoutValues() {
int connectTimeout = Integer.parseInt(System.getProperty("sun.net.client.defaultConnectTimeout", "30000"));
int readTimeout = Integer.parseInt(System.getProperty("sun.net.client.defaultReadTimeout", "30000"));
SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
requestFactory.setConnectTimeout(connectTimeout);
requestFactory.setReadTimeout(readTimeout);
return new RestTemplate(requestFactory);
}

private Cache cache;

Expand Down

0 comments on commit 4afa21c

Please sign in to comment.