com.github.bjuvensjo.rsimulator.proxy.SecurityHandler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of rsimulator-proxy Show documentation
Show all versions of rsimulator-proxy Show documentation
${project.artifactId} module
The newest version!
package com.github.bjuvensjo.rsimulator.proxy;
import com.google.inject.Singleton;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.net.ssl.*;
@Singleton
public class SecurityHandler {
private final Logger log = LoggerFactory.getLogger(SecurityHandler.class);
public void initialize() {
// Create a trust manager that does not validate certificate chains
TrustManager[] trustAllCerts = new TrustManager[]{new X509TrustManager() {
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return null;
}
public void checkClientTrusted(java.security.cert.X509Certificate[] certs, String authType) {
}
public void checkServerTrusted(java.security.cert.X509Certificate[] certs, String authType) {
}
}};
// Install the all-trusting trust manager
try {
SSLContext sc = SSLContext.getInstance("SSL");
sc.init(null, trustAllCerts, new java.security.SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
HostnameVerifier hostnameVerifier = (s, sslSession) -> true;
HttpsURLConnection.setDefaultHostnameVerifier(hostnameVerifier);
} catch (Exception e) {
log.error("Can not initialize.", e);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy