From b43fa21fd8bc3a99b7d283b28423fe1fff9936df Mon Sep 17 00:00:00 2001 From: Olga Maciaszek-Sharma Date: Tue, 2 Jul 2024 14:55:22 +0200 Subject: [PATCH] Handle TLS settings for Eureka Server's JerseyClient. (#4285) --- .../server/EurekaServerAutoConfiguration.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/spring-cloud-netflix-eureka-server/src/main/java/org/springframework/cloud/netflix/eureka/server/EurekaServerAutoConfiguration.java b/spring-cloud-netflix-eureka-server/src/main/java/org/springframework/cloud/netflix/eureka/server/EurekaServerAutoConfiguration.java index 38d345726..748f85a25 100644 --- a/spring-cloud-netflix-eureka-server/src/main/java/org/springframework/cloud/netflix/eureka/server/EurekaServerAutoConfiguration.java +++ b/spring-cloud-netflix-eureka-server/src/main/java/org/springframework/cloud/netflix/eureka/server/EurekaServerAutoConfiguration.java @@ -21,6 +21,7 @@ import java.net.MalformedURLException; import java.net.URL; import java.net.UnknownHostException; +import java.security.GeneralSecurityException; import java.util.Collection; import java.util.Collections; import java.util.HashSet; @@ -88,6 +89,8 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.web.servlet.FilterRegistrationBean; import org.springframework.cloud.client.actuator.HasFeatures; +import org.springframework.cloud.configuration.SSLContextFactory; +import org.springframework.cloud.configuration.TlsProperties; import org.springframework.cloud.context.environment.EnvironmentChangeEvent; import org.springframework.cloud.netflix.eureka.EurekaConstants; import org.springframework.cloud.netflix.eureka.EurekaInstanceConfigBean; @@ -112,6 +115,7 @@ * @author Fahim Farook * @author Weix Sun * @author Robert Bleyl + * @author Olga Maciaszek-Sharma */ @Configuration(proxyBeanMethods = false) @Import(EurekaServerInitializerConfiguration.class) @@ -205,8 +209,14 @@ public Jersey3EurekaServerHttpClientFactory jersey3EurekaServerHttpClientFactory @Bean @ConditionalOnMissingBean(AbstractDiscoveryClientOptionalArgs.class) - public Jersey3DiscoveryClientOptionalArgs jersey3DiscoveryClientOptionalArgs() { - return new Jersey3DiscoveryClientOptionalArgs(); + public Jersey3DiscoveryClientOptionalArgs jersey3DiscoveryClientOptionalArgs( + @Autowired(required = false) TlsProperties tlsProperties) throws GeneralSecurityException, IOException { + Jersey3DiscoveryClientOptionalArgs optionalArgs = new Jersey3DiscoveryClientOptionalArgs(); + if (tlsProperties != null && tlsProperties.isEnabled()) { + SSLContextFactory factory = new SSLContextFactory(tlsProperties); + optionalArgs.setSSLContext(factory.createSSLContext()); + } + return optionalArgs; } @Bean