Skip to content

Instantly share code, notes, and snippets.

@matthewromano
Last active October 14, 2021 16:01
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save matthewromano/4178946 to your computer and use it in GitHub Desktop.
Save matthewromano/4178946 to your computer and use it in GitHub Desktop.
Trust Manager to trust all SSL certificates
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import javax.net.ssl.X509TrustManager;
public class BlindTrustManager implements X509TrustManager {
public X509Certificate[] getAcceptedIssuers() {
return null;
}
public void checkClientTrusted(X509Certificate[] chain, String authType)
throws CertificateException {
}
public void checkServerTrusted(X509Certificate[] chain, String authType)
throws CertificateException {
}
}
private SSLSocketFactory buildSocketFactory() throws KeyManagementException, NoSuchAlgorithmException {
SSLContext ctx = SSLContext.getInstance("TLS");
ctx.init(null, new TrustManager[] { new BlindTrustManager() }, null);
return ctx.getSocketFactory();
}
SSLSocketFactory sslSocketFactory = buildSocketFactory();
MyJAXService service = new MyJAXService();
MyServicePortProxy serviceProxy = service.getMyServicePortProxy();
Map<String, Object> requestContext = ((BindingProvider) serviceProxy).getRequestContext();
requestContext.put(BindingProviderProperties.SSL_SOCKET_FACTORY, sslSocketFactory);
@crusy
Copy link

crusy commented Apr 28, 2020

What's mode in BuildSocketFactory?

@matthewromano
Copy link
Author

What's mode in BuildSocketFactory?

Old code, most likely

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment