Created
January 25, 2019 12:07
-
-
Save flox1an/3adb4b5205af904cc7be3ebd0a5944d9 to your computer and use it in GitHub Desktop.
Java ignore SSL for OpenCMIS connections
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void acceptSelfSignedCertificates() { | |
TrustManager[] trustAllCerts = new TrustManager[]{new X509TrustManager() { | |
public X509Certificate[] getAcceptedIssuers() { | |
return null; | |
} | |
public void checkClientTrusted(X509Certificate[] certs, String authType) { | |
} | |
public void checkServerTrusted(X509Certificate[] certs, String authType) { | |
} | |
}}; | |
try { | |
SSLContext sc = SSLContext.getInstance("SSL"); | |
sc.init(null, trustAllCerts, new java.security.SecureRandom()); | |
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); | |
HostnameVerifier allHostsValid = new HostnameVerifier() { | |
public boolean verify(String hostname, SSLSession session) { | |
return true; | |
} | |
}; | |
HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid); | |
} catch (Exception e) { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment