2016-08-05 246 views
0

我們有一個基於spring-boot的web應用程序並使用WSO2 CEP框架。我們如何忽略AXIS2客戶端的主機名驗證或設置自定義主機名驗證程序?如何在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)); 
+0

這會有幫助嗎? http://grepcode.com/file/repo1.maven.org/maven2/org.apache.axis2/axis2-kernel/1.4/org/apache/axis2/transport/nhttp/HttpCoreNIOSSLSender.java – ycr

+0

感謝您的回覆,ycr 。如果我可以擴展它並定製verify(),這可能會很有用。但是,我們使用的wso2-cep-client 1.0.10與axis2-kernel 1.6.4存在依賴關係。似乎沒有HttpCoreNIOSSLSender了? – Bruce

+0

我該怎麼做才能在設置SSLIOSessionHandler後得到它?謝謝 – Bruce

回答

0

您可以使用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

+0

嗨Bhathiya,謝謝你的回答。我已經在我們的開發項目中做到了。但是爲了生產,我們需要驗證服務器證書是否出於安全原因。但有時可能有這種情況是主機名不匹配或我們需要匹配通配符證書。 – Bruce

+0

爲什麼你不能用通配符創建證書? – Bee

+0

我們可能會有證書(two.abc.com),但主機名不匹配(例如,從本地主機連接)或通配符證書(*。two.abc.com),但從one.two.abc連接.com和/或two.abc.com。 – Bruce