2014-12-03 58 views
0

我有一個.jks文件,我需要使用JAX-RS簽名消息嗎?
我正在使用apache-cxf的rest實現。我已經通過apache cxf網站用於簽署郵件使用jax-rs,但我沒有明確的想法。
提供的信息非常少。所以,任何人都可以提供給我,我怎麼能做到這一點或任何解釋清楚的鏈接?使用Apache CXF的JAX-RS實現簽名消息

編碼:

String keystr = "src/main/resources/keystore.jks";     
    KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());    
     FileInputStream fis = new FileInputStream(keystr); 
     keyStore.load(fis, KEYSTORE_PWD.toCharArray()); 
     PrivateKey key = (PrivateKey) keyStore.getKey("", KEYSTORE_PWD.toCharArray()); 

     SSLContext sslCtxt= SSLContexts.custom().loadTrustMaterial(keyStore).build(); 
     SSLConnectionSocketFactory sslConn = new SSLConnectionSocketFactory(sslCtxt, SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); 

     CloseableHttpClient httpclient = HttpClients.custom().setSSLSocketFactory(sslConn).build(); 

     HttpGet getReq = new HttpGet("http://localhost:8080/xyz?sss=abc"); 
     CloseableHttpResponse response = httpclient.execute(getReq); 

     HttpEntity entity = response.getEntity(); 
      if (entity != null) { 
     BufferedReader br = new BufferedReader(new InputStreamReader(entity.getContent()));   
     StringBuffer result = new StringBuffer(); 
     String line = ""; 
     while ((line = br.readLine()) != null) { 
      result.append(line); 
      } 
     } 

感謝

+0

我認爲CXF的JAX RS文檔並不壞(http://cxf.apache.org/docs/jax-rs-xml-security.html)。您能否提供更多信息,您在哪裏得到錯誤/您在哪裏遇到文檔問題? – soilworker 2014-12-03 08:33:59

+1

也許我的英語太糟糕了,但我不明白「哪一個是擔保人」。但是,也許你在cxf的例子部分找到了一些有用的信息http://svn.apache.org/viewvc/cxf/trunk/distribution/src/main/release/samples/ – soilworker 2014-12-03 08:45:20

+0

我想當你說「我需要消費一個web服務「你想實現服務器端,所以你可以看一下serverconfig.xml。這只是示例,您也可以通過編程方式執行此配置,請按照cxf文檔的說明進行操作http://cxf.apache.org/docs/jaxrs-services-configuration.html – soilworker 2014-12-03 15:19:43

回答

0

簡單,最簡單的方式使用命名空間xmlns:http="http://cxf.apache.org/transports/http/configuration"您CXF confgiuration文件和負載JKS文件添加HTTP管道。請注意0​​這適用於所有傳出的cxf請求。你可以根據需要調整你的特定網址。有關詳情請參閱here

<http:conduit name="*.http-conduit"> 
      <http:tlsClientParameters> 
       <sec:keyManagers keyPassword="${'ssl.keystorepassword'}"> 
        <sec:keyStore type="JKS" password="${'ssl.keystorepassword'}" 
         file="${'ssl.keystorefile')}" /> 
       </sec:keyManagers> 
       <sec:trustManagers> 
        <sec:keyStore type="JKS" password="${'ssl.truststorepassword'}" 
         file="${'ssl.truststorefile'}" /> 
       </sec:trustManagers> 
       <sec:cipherSuitesFilter> 
        <sec:include>.*_EXPORT_.*</sec:include> 
        <sec:include>.*_EXPORT1024_.*</sec:include> 
        <sec:include>.*_WITH_DES_.*</sec:include> 
        <sec:include>.*_WITH_AES_.*</sec:include> 
        <sec:include>.*_WITH_NULL_.*</sec:include> 
        <sec:exclude>.*_DH_anon_.*</sec:exclude> 
       </sec:cipherSuitesFilter> 
      </http:tlsClientParameters> 
      <http:authorization> 
      </http:authorization> 
      <http:client AutoRedirect="true" Connection="Keep-Alive" /> 
    </http:conduit> 
+0

你使用的代碼不是cxf web客戶端。它的apache http客戶端,不確定配置 – 2014-12-05 10:26:38