Skip to content

Instantly share code, notes, and snippets.

@flox1an
Created January 25, 2019 12:07
Show Gist options
  • Save flox1an/3adb4b5205af904cc7be3ebd0a5944d9 to your computer and use it in GitHub Desktop.
Save flox1an/3adb4b5205af904cc7be3ebd0a5944d9 to your computer and use it in GitHub Desktop.
Java ignore SSL for OpenCMIS connections
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