mirror of
https://github.com/Alfresco/alfresco-transform-core.git
synced 2025-05-12 17:04:48 +00:00
[ACS-4460] MtlsTestUtils simplified
This commit is contained in:
parent
807699beda
commit
3706bef72b
@ -1,7 +1,6 @@
|
|||||||
package org.alfresco.transform.base;
|
package org.alfresco.transform.base;
|
||||||
|
|
||||||
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
|
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
|
||||||
import org.apache.http.conn.ssl.TrustAllStrategy;
|
|
||||||
import org.apache.http.impl.client.CloseableHttpClient;
|
import org.apache.http.impl.client.CloseableHttpClient;
|
||||||
import org.apache.http.impl.client.HttpClients;
|
import org.apache.http.impl.client.HttpClients;
|
||||||
import org.apache.http.ssl.SSLContextBuilder;
|
import org.apache.http.ssl.SSLContextBuilder;
|
||||||
@ -10,6 +9,7 @@ import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
|
|||||||
import org.springframework.web.client.RestTemplate;
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
|
||||||
import javax.net.ssl.SSLContext;
|
import javax.net.ssl.SSLContext;
|
||||||
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
@ -27,8 +27,8 @@ public class MtlsTestUtils {
|
|||||||
return Boolean.parseBoolean(System.getProperty("mtls-enabled"));
|
return Boolean.parseBoolean(System.getProperty("mtls-enabled"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static CloseableHttpClient httpClientWithMtls() throws NoSuchAlgorithmException, KeyManagementException, UnrecoverableKeyException, KeyStoreException, IOException, CertificateException {
|
public static CloseableHttpClient httpClientWithMtls() throws NoSuchAlgorithmException, KeyManagementException, UnrecoverableKeyException, KeyStoreException, IOException, CertificateException
|
||||||
|
{
|
||||||
String keyStoreFile = System.getProperty("mtls-keystore-file");
|
String keyStoreFile = System.getProperty("mtls-keystore-file");
|
||||||
String keyStoreType = System.getProperty("mtls-keystore-type");
|
String keyStoreType = System.getProperty("mtls-keystore-type");
|
||||||
char[] keyStorePassword = System.getProperty("mtls-keystore-password").toCharArray();
|
char[] keyStorePassword = System.getProperty("mtls-keystore-password").toCharArray();
|
||||||
@ -44,12 +44,8 @@ public class MtlsTestUtils {
|
|||||||
sslContextBuilder.loadKeyMaterial(keyStore, keyStorePassword);
|
sslContextBuilder.loadKeyMaterial(keyStore, keyStorePassword);
|
||||||
}
|
}
|
||||||
|
|
||||||
KeyStore trustStore = KeyStore.getInstance(trustStoreType);
|
File trustStore = new File(trustStoreFile);
|
||||||
try (InputStream trustStoreInputStream = new FileInputStream(trustStoreFile))
|
sslContextBuilder.loadTrustMaterial(trustStore, trustStorePassword);
|
||||||
{
|
|
||||||
trustStore.load(trustStoreInputStream, trustStorePassword);
|
|
||||||
sslContextBuilder.loadTrustMaterial(trustStore, TrustAllStrategy.INSTANCE);
|
|
||||||
}
|
|
||||||
|
|
||||||
SSLContext sslContext = sslContextBuilder.build();
|
SSLContext sslContext = sslContextBuilder.build();
|
||||||
SSLConnectionSocketFactory sslContextFactory = new SSLConnectionSocketFactory(sslContext);
|
SSLConnectionSocketFactory sslContextFactory = new SSLConnectionSocketFactory(sslContext);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user