2011-10-24 53 views
5

我已經編寫了Jersey RESTful客戶端,他們利用Dumb X509TrustManager和HostnameVerifier信任我們實驗室系統中的所有SSL證書,以便更輕鬆地處理自簽名的證書。CXF RESTful客戶端 - 如何信任所有證書?

 ClientConfig config = new DefaultClientConfig(); 
     SSLContext context = null; 
     try 
     { 
      context = SSLContext.getInstance("SSL"); 
      context.init(null, 
        new TrustManager[] { new DumbX509TrustManager() }, 
        null); 
      config.getProperties() 
        .put(HTTPSProperties.PROPERTY_HTTPS_PROPERTIES, 
          new HTTPSProperties(this.getHostnameVerifier(), 
            context)); 
      webClient = Client.create(config); 
     } 
     .... 

有沒有辦法讓我用CXF做類似的事情?

回答

6

這是來自CXF郵件列表。請注意,我沒有把它貫徹由於其他系統更新,所以這是理論:

WebClient webClient = WebClient.create(this.serviceURL, 
    this.username, 
    this.password, 
    null); // Spring config file - we don't use this 

if (trustAllCerts) 
{ 
    HTTPConduit conduit = WebClient.getConfig(webClient) 
     .getHttpConduit(); 

    TLSClientParameters params = 
     conduit.getTlsClientParameters(); 

    if (params == null) 
    { 
     params = new TLSClientParameters(); 
     conduit.setTlsClientParameters(params); 
    } 

    params.setTrustManagers(new TrustManager[] { new 
     DumbX509TrustManager() }); 

    params.setDisableCNCheck(true); 
} 
+0

[這個答案](http://stackoverflow.com/a/6755459/150992)的細節,你會如何建立一個盲目接受證書的虛擬TrustManager。 (當然,你可能不想在生產中使用類似的東西) – Eyal