From 24fd19b107a16659b52c2ce47fe362c6f75ca3d6 Mon Sep 17 00:00:00 2001 From: MrJovanovic13 <34819606+MrJovanovic13@users.noreply.github.com> Date: Wed, 17 Apr 2024 23:40:42 +0200 Subject: [PATCH] Add Default Timeout to JwtDecoders RestTemplate Closes gh-14269 --- .../jwt/JwtDecoderProviderConfigurationUtils.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/oauth2/oauth2-jose/src/main/java/org/springframework/security/oauth2/jwt/JwtDecoderProviderConfigurationUtils.java b/oauth2/oauth2-jose/src/main/java/org/springframework/security/oauth2/jwt/JwtDecoderProviderConfigurationUtils.java index 47a068dd751..36ca9b68689 100644 --- a/oauth2/oauth2-jose/src/main/java/org/springframework/security/oauth2/jwt/JwtDecoderProviderConfigurationUtils.java +++ b/oauth2/oauth2-jose/src/main/java/org/springframework/security/oauth2/jwt/JwtDecoderProviderConfigurationUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -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; @@ -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> STRING_OBJECT_MAP = new ParameterizedTypeReference>() { };