mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-10 07:25:44 +01:00
added options to disable ssl verification
This commit is contained in:
@@ -64,6 +64,10 @@ import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.TrustManager;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
@@ -383,6 +387,39 @@ public class URLHttpClient implements HttpClient
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param request
|
||||
* @param connection
|
||||
*/
|
||||
private void applySSLSettings(HttpRequest request,
|
||||
HttpsURLConnection connection)
|
||||
{
|
||||
if (request.isDisableCertificateValidation())
|
||||
{
|
||||
try
|
||||
{
|
||||
TrustManager[] trustAllCerts = new TrustManager[] {
|
||||
new TrustAllTrustManager() };
|
||||
SSLContext sc = SSLContext.getInstance("SSL");
|
||||
|
||||
sc.init(null, trustAllCerts, new java.security.SecureRandom());
|
||||
connection.setSSLSocketFactory(sc.getSocketFactory());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.error("could not disable certificate validation", ex);
|
||||
}
|
||||
}
|
||||
|
||||
if (request.isDisableHostnameValidation())
|
||||
{
|
||||
connection.setHostnameVerifier(new TrustAllHostnameVerifier());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
@@ -514,6 +551,11 @@ public class URLHttpClient implements HttpClient
|
||||
connection = (HttpURLConnection) url.openConnection();
|
||||
}
|
||||
|
||||
if (connection instanceof HttpsURLConnection)
|
||||
{
|
||||
applySSLSettings(request, (HttpsURLConnection) connection);
|
||||
}
|
||||
|
||||
connection.setReadTimeout(TIMEOUT_RAED);
|
||||
connection.setConnectTimeout(TIMEOUT_CONNECTION);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user