use of io.fabric8.utils.ssl.AllCertificatesTrustManager in project fabric8 by fabric8io.
the class URLUtils method prepareForSSL.
/**
* Prepares an url connection for authentication if necessary.
*
* @param connection the connection to be prepared
* @return the prepared conection
*/
public static URLConnection prepareForSSL(final URLConnection connection) {
NullArgumentException.validateNotNull(connection, "url connection cannot be null");
URLConnection conn = connection;
if (conn instanceof JarURLConnection) {
try {
conn = ((JarURLConnection) connection).getJarFileURL().openConnection();
conn.connect();
} catch (IOException e) {
throw new RuntimeException("Could not prepare connection for HTTPS.", e);
}
}
if (conn instanceof HttpsURLConnection) {
try {
SSLContext ctx = SSLContext.getInstance("SSLv3");
ctx.init(null, new TrustManager[] { new AllCertificatesTrustManager() }, null);
((HttpsURLConnection) conn).setSSLSocketFactory(ctx.getSocketFactory());
} catch (KeyManagementException e) {
throw new RuntimeException("Could not prepare connection for HTTPS.", e);
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException("Could not prepare connection for HTTPS.", e);
}
}
return connection;
}
use of io.fabric8.utils.ssl.AllCertificatesTrustManager in project fabric8 by jboss-fuse.
the class URLUtils method prepareForSSL.
/**
* Prepares an url connection for authentication if necessary.
*
* @param connection the connection to be prepared
* @return the prepared conection
*/
public static URLConnection prepareForSSL(final URLConnection connection) {
NullArgumentException.validateNotNull(connection, "url connection cannot be null");
URLConnection conn = connection;
if (conn instanceof JarURLConnection) {
try {
conn = ((JarURLConnection) connection).getJarFileURL().openConnection();
conn.connect();
} catch (IOException e) {
throw new RuntimeException("Could not prepare connection for HTTPS.", e);
}
}
if (conn instanceof HttpsURLConnection) {
try {
SSLContext ctx = SSLContext.getInstance("SSLv3");
ctx.init(null, new TrustManager[] { new AllCertificatesTrustManager() }, null);
((HttpsURLConnection) conn).setSSLSocketFactory(ctx.getSocketFactory());
} catch (KeyManagementException e) {
throw new RuntimeException("Could not prepare connection for HTTPS.", e);
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException("Could not prepare connection for HTTPS.", e);
}
}
return connection;
}
Aggregations