如何在AXIS2客户端中忽略主机名验证或设置验证程序

时间:2016-08-05 02:26:16

标签: ssl wso2 axis2 hostname httpconnection

我们有一个基于Spring-boot的Web应用程序并使用WSO2 CEP框架。我们如何忽略AXIS2客户端的主机名验证或设置自定义主机名验证器?

我们可以为Java HttpsURLConnection

执行此操作
HttpsURLConnection.setDefaultHostnameVerifier(new WildcardHostnameVerifier());

或者apache HttpClient

的方式
    // setup a WildcardHostNameVerifier for support verifying the hostname of wildcard certificate
    sslsf = new SSLConnectionSocketFactory(sslcontext, new WildcardHostnameVerifier());
    CloseableHttpClient httpClient = HttpClients.custom().setSSLSocketFactory(sslsf).build();

但是不知道如何为AXIS2客户端做什么,我们找到了一种方法来设置自定义的trustManger。

final SSLContext sslCtx = SSLContext.getInstance("TLSv1.2");
sslCtx.init(null, new TrustManager[] { new CustomX509TrustManager() }, new SecureRandom());

stub._getServiceClient().getOptions().setProperty(HTTPConstants.CUSTOM_PROTOCOL_HANDLER, new Protocol("https",
            (ProtocolSocketFactory) new SSLProtocolSocketFactory(sslCtx), 443));

1 个答案:

答案 0 :(得分:1)

您可以使用TrustAllTrustManager

SSLContext sslCtx = SSLContext.getInstance("http");
sslCtx.init(null, new TrustManager[] {new TrustAllTrustManager()}, null);
stub._getServiceClient().getOptions().setProperty(HTTPConstants.CUSTOM_PROTOCOL_HANDLER, 
          new Protocol("https",(ProtocolSocketFactory)new SSLProtocolSocketFactory(sslCtx),443));

请参阅this blog post