SAAJ包括客户证书

时间:2014-06-09 06:58:12

标签: java server-side jaas sslsocketfactory

我想通过https呼叫Web服务,我需要包含客户端证书。我是用SAAJ做的那样

SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
conn = soapConnectionFactory.createConnection();
URL endpoint = new URL(urlEndPoint);
SOAPMessage response = conn.call(msg, endpoint);

但如何包含客户证书?

1 个答案:

答案 0 :(得分:0)

我创建

KeyManagerFactory kmf = csm.getKeyManagerFactory();
TrustManagerFactory tmf = csm.getTrustManagerFactory();

SSLContext sslcontext = SSLContexts.custom().useProtocol("SSL").build();

sslcontext.init(kmf.getKeyManagers(), tmf.getTrustManagers(), new SecureRandom());

然后我setDefaultSSLSocketFactory

HttpsURLConnection.setDefaultSSLSocketFactory(sslcontext.getSocketFactory());