Skip to content

Commit 24fd19b

Browse files
MrJovanovic13jzheaux
authored andcommitted
Add Default Timeout to JwtDecoders RestTemplate
Closes gh-14269
1 parent a4dbf45 commit 24fd19b

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

Diff for: oauth2/oauth2-jose/src/main/java/org/springframework/security/oauth2/jwt/JwtDecoderProviderConfigurationUtils.java

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -39,6 +39,7 @@
3939
import org.springframework.core.ParameterizedTypeReference;
4040
import org.springframework.http.RequestEntity;
4141
import org.springframework.http.ResponseEntity;
42+
import org.springframework.http.client.SimpleClientHttpRequestFactory;
4243
import org.springframework.security.oauth2.jose.jws.SignatureAlgorithm;
4344
import org.springframework.util.Assert;
4445
import org.springframework.web.client.HttpClientErrorException;
@@ -65,6 +66,15 @@ final class JwtDecoderProviderConfigurationUtils {
6566

6667
private static final RestTemplate rest = new RestTemplate();
6768

69+
static {
70+
int connectTimeout = Integer.parseInt(System.getProperty("sun.net.client.defaultConnectTimeout", "30000"));
71+
int readTimeout = Integer.parseInt(System.getProperty("sun.net.client.defaultReadTimeout", "30000"));
72+
SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
73+
requestFactory.setConnectTimeout(connectTimeout);
74+
requestFactory.setReadTimeout(readTimeout);
75+
rest.setRequestFactory(requestFactory);
76+
}
77+
6878
private static final ParameterizedTypeReference<Map<String, Object>> STRING_OBJECT_MAP = new ParameterizedTypeReference<Map<String, Object>>() {
6979
};
7080

0 commit comments

Comments
 (0)