[ACS-4460] hostname verification fix (#780)

This commit is contained in:
kcichonczyk
2023-04-12 14:37:34 +02:00
committed by GitHub
parent 47e3871241
commit b341e3e6be
3 changed files with 7 additions and 18 deletions

View File

@@ -121,13 +121,10 @@ public class MTLSConfig {
private RestTemplate createRestTemplateWithSslContext(SSLContextBuilder sslContextBuilder) throws NoSuchAlgorithmException, KeyManagementException {
SSLContext sslContext = sslContextBuilder.build();
SSLConnectionSocketFactory sslContextFactory = new SSLConnectionSocketFactory(sslContext);
SSLConnectionSocketFactory sslContextFactory = hostNameVerificationDisabled ? new SSLConnectionSocketFactory(sslContext, NoopHostnameVerifier.INSTANCE)
: new SSLConnectionSocketFactory(sslContext);
HttpClientBuilder httpClientBuilder = HttpClients.custom().setSSLSocketFactory(sslContextFactory);
if(hostNameVerificationDisabled)
{
httpClientBuilder.setSSLHostnameVerifier(new NoopHostnameVerifier());
}
CloseableHttpClient httpClient = httpClientBuilder.build();
ClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(httpClient);
return new RestTemplate(requestFactory);