[ACS-4460] add no hostname verification remove com.google.collections dependencies (#770)

This commit is contained in:
kcichonczyk
2023-03-29 13:45:01 +02:00
committed by GitHub
parent 9223dc170d
commit 23cd052cd9
5 changed files with 50 additions and 13 deletions

View File

@@ -26,8 +26,10 @@
*/
package org.alfresco.transformer.config;
import org.apache.http.conn.ssl.NoopHostnameVerifier;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.ssl.SSLContextBuilder;
import org.springframework.beans.factory.annotation.Value;
@@ -70,6 +72,9 @@ public class MTLSConfig {
@Value("${client.ssl.trust-store-type:}")
private String trustStoreType;
@Value("${client.ssl.hostname-verification-disabled:false}")
private boolean hostNameVerificationDisabled;
@Bean
public RestTemplate restTemplate(SSLContextBuilder apacheSSLContextBuilder) throws IOException, CertificateException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException, UnrecoverableKeyException
{
@@ -117,7 +122,13 @@ public class MTLSConfig {
private RestTemplate createRestTemplateWithSslContext(SSLContextBuilder sslContextBuilder) throws NoSuchAlgorithmException, KeyManagementException {
SSLContext sslContext = sslContextBuilder.build();
SSLConnectionSocketFactory sslContextFactory = new SSLConnectionSocketFactory(sslContext);
CloseableHttpClient httpClient = HttpClients.custom().setSSLSocketFactory(sslContextFactory).build();
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);
}