1

我試圖創建一個啓用了安全性的JAX-WS webservice。我跟着this 教程,並完成它與我以前建立的webservice我自己的。這只是一個簡單的web服務,返回當前時間。因此,客戶端是一個獨立的Java應用程序和客戶端代碼去爲:JAX-WS web服務安全問題

public class CallWS { 
    public static void main(String[] args) { 
     TimeService ts = new TimeService(); 
     Time time = ts.getTimePort(); 
     System.out.println(time.timeOfDay()); 
    } 
} 

,但我發現以下異常:

SEVERE: WSSTUBE0023: Error in creating new instance of SecurityClientTube 
java.lang.RuntimeException: WSSTUBE0016: TrustStore URL was obtained as NULL from ConfigAssertion. 
    at com.sun.xml.wss.jaxws.impl.SecurityTubeBase.populateTruststoreProps(SecurityTubeBase.java:1411) 
    at com.sun.xml.wss.jaxws.impl.SecurityTubeBase.populateConfigProperties(SecurityTubeBase.java:1314) 
    at com.sun.xml.wss.jaxws.impl.SecurityClientTube.configureClientHandler(SecurityClientTube.java:779) 
    at com.sun.xml.wss.jaxws.impl.SecurityClientTube.<init>(SecurityClientTube.java:170) 
    at com.sun.xml.wss.provider.wsit.SecurityTubeFactory.createTube(SecurityTubeFactory.java:227) 
    at com.sun.xml.ws.assembler.TubeCreator.createTube(TubeCreator.java:77) 
    at com.sun.xml.ws.assembler.TubelineAssemblerFactoryImpl$MetroTubelineAssembler.createClient(TubelineAssemblerFactoryImpl.java:121) 
    at com.sun.xml.ws.client.Stub.createPipeline(Stub.java:224) 
    at com.sun.xml.ws.client.Stub.<init>(Stub.java:201) 
    at com.sun.xml.ws.client.Stub.<init>(Stub.java:174) 
    at com.sun.xml.ws.client.sei.SEIStub.<init>(SEIStub.java:81) 
    at com.sun.xml.ws.client.WSServiceDelegate.createEndpointIFBaseProxy(WSServiceDelegate.java:602) 
    at com.sun.xml.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:344) 
    at com.sun.xml.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:326) 
    at com.sun.xml.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:308) 
    at javax.xml.ws.Service.getPort(Service.java:99) 
    at wsclient.TimeService.getTimePort(TimeService.java:72) 
    at main.CallWS.main(CallWS.java:19) 

Exception in thread "main" java.lang.RuntimeException: WSSTUBE0023: Error in creating new instance of SecurityClientTube 
    at com.sun.xml.wss.jaxws.impl.SecurityClientTube.<init>(SecurityClientTube.java:175) 
    at com.sun.xml.wss.provider.wsit.SecurityTubeFactory.createTube(SecurityTubeFactory.java:227) 
    at com.sun.xml.ws.assembler.TubeCreator.createTube(TubeCreator.java:77) 
    at com.sun.xml.ws.assembler.TubelineAssemblerFactoryImpl$MetroTubelineAssembler.createClient(TubelineAssemblerFactoryImpl.java:121) 
    at com.sun.xml.ws.client.Stub.createPipeline(Stub.java:224) 
    at com.sun.xml.ws.client.Stub.<init>(Stub.java:201) 
    at com.sun.xml.ws.client.Stub.<init>(Stub.java:174) 
    at com.sun.xml.ws.client.sei.SEIStub.<init>(SEIStub.java:81) 
    at com.sun.xml.ws.client.WSServiceDelegate.createEndpointIFBaseProxy(WSServiceDelegate.java:602) 
    at com.sun.xml.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:344) 
    at com.sun.xml.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:326) 
    at com.sun.xml.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:308) 
    at javax.xml.ws.Service.getPort(Service.java:99) 
    at wsclient.TimeService.getTimePort(TimeService.java:72) 
    at main.CallWS.main(CallWS.java:19) 
Caused by: java.lang.RuntimeException: WSSTUBE0016: TrustStore URL was obtained as NULL from ConfigAssertion. 
    at com.sun.xml.wss.jaxws.impl.SecurityTubeBase.populateTruststoreProps(SecurityTubeBase.java:1411) 
    at com.sun.xml.wss.jaxws.impl.SecurityTubeBase.populateConfigProperties(SecurityTubeBase.java:1314) 
    at com.sun.xml.wss.jaxws.impl.SecurityClientTube.configureClientHandler(SecurityClientTube.java:779) 
    at com.sun.xml.wss.jaxws.impl.SecurityClientTube.<init>(SecurityClientTube.java:170) 
    ... 14 more 
Java Result: 1 

我使用了相同的安全機制,如提教程(用對稱密鑰進行用戶名認證),並遵循客戶端和服務器端環境完全相同的步驟。

我使用

  • 的Netbeans 7.0.1
  • Glassfish的3.1
  • 的Java EE 6
  • JDK 7
  • 地鐵2.0庫

WSIT-ws.Time

<?xml version="1.0" encoding="UTF-8"?> 
<definitions 
xmlns="http://schemas.xmlsoap.org/wsdl/" 
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" 
xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" name="TimeService" targetNamespace="http%3A%2F%2Fns.soacookbook.com" xmlns:tns="http%3A%2F%2Fns.soacookbook.com" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:sp="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702" xmlns:sc="http://schemas.sun.com/2006/03/wss/server" xmlns:wspp="http://java.sun.com/xml/ns/wsit/policy" xmlns:wsp1="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsaw="http://www.w3.org/2005/08/addressing" xmlns:fi="http://java.sun.com/xml/ns/wsit/2006/09/policy/fastinfoset/service" xmlns:tcp="http://java.sun.com/xml/ns/wsit/2006/09/policy/soaptcp/service" xmlns:sp1="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy" 
> 
    <message name="timeOfDay"/> 
    <message name="timeOfDayResponse"/> 
    <portType name="Time"> 
     <operation name="timeOfDay"> 
      <input message="tns:timeOfDay"/> 
      <output message="tns:timeOfDayResponse"/> 
     </operation> 
    </portType> 
    <binding name="TimePortBinding" type="tns:Time"> 
     <wsp1:PolicyReference URI="#TimePortBindingPolicy"/> 
     <operation name="timeOfDay"> 
      <input> 
       <wsp1:PolicyReference URI="#TimePortBinding_timeOfDay_Input_Policy"/> 
      </input> 
      <output> 
       <wsp1:PolicyReference URI="#TimePortBinding_timeOfDay_Output_Policy"/> 
      </output> 
     </operation> 
    </binding> 
    <service name="TimeService"> 
     <port name="TimePort" binding="tns:TimePortBinding"/> 
    </service> 
    <wsp1:Policy wsu:Id="TimePortBindingPolicy"> 
     <wsp1:ExactlyOne> 
      <wsp1:All> 
       <wsaw:UsingAddressing xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" wsp1:Optional="false"/> 
       <sp1:SymmetricBinding> 
        <wsp1:Policy> 
         <sp1:ProtectionToken> 
          <wsp1:Policy> 
           <sp1:X509Token sp1:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/Never"> 
            <wsp1:Policy> 
             <sp1:WssX509V3Token10/> 
             <sp1:RequireIssuerSerialReference/> 
            </wsp1:Policy> 
           </sp1:X509Token> 
          </wsp1:Policy> 
         </sp1:ProtectionToken> 
         <sp1:Layout> 
          <wsp1:Policy> 
           <sp1:Strict/> 
          </wsp1:Policy> 
         </sp1:Layout> 
         <sp1:IncludeTimestamp/> 
         <sp1:OnlySignEntireHeadersAndBody/> 
         <sp1:AlgorithmSuite> 
          <wsp1:Policy> 
           <sp1:Basic128/> 
          </wsp1:Policy> 
         </sp1:AlgorithmSuite> 
        </wsp1:Policy> 
       </sp1:SymmetricBinding> 
       <sp1:Wss11> 
        <wsp1:Policy> 
         <sp1:MustSupportRefIssuerSerial/> 
         <sp1:MustSupportRefThumbprint/> 
         <sp1:MustSupportRefEncryptedKey/> 
        </wsp1:Policy> 
       </sp1:Wss11> 
       <sp1:SignedSupportingTokens> 
        <wsp1:Policy> 
         <sp1:UsernameToken sp1:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/AlwaysToRecipient"> 
          <wsp1:Policy> 
           <sp1:WssUsernameToken10/> 
          </wsp1:Policy> 
         </sp1:UsernameToken> 
        </wsp1:Policy> 
       </sp1:SignedSupportingTokens> 
       <sc:KeyStore wspp:visibility="private" location="/home/oshadha/.netbeans/7.0/config/GF3_113/domain1/config/keystore.jks" type="JKS" storepass="changeit" alias="xws-security-server"/> 
      </wsp1:All> 
     </wsp1:ExactlyOne> 
    </wsp1:Policy> 
    <wsp1:Policy wsu:Id="TimePortBinding_timeOfDay_Input_Policy"> 
     <wsp1:ExactlyOne> 
      <wsp1:All> 
       <sp1:EncryptedParts> 
        <sp1:Body/> 
       </sp1:EncryptedParts> 
       <sp1:SignedParts> 
        <sp1:Body/> 
        <sp1:Header Name="To" Namespace="http://www.w3.org/2005/08/addressing"/> 
        <sp1:Header Name="From" Namespace="http://www.w3.org/2005/08/addressing"/> 
        <sp1:Header Name="FaultTo" Namespace="http://www.w3.org/2005/08/addressing"/> 
        <sp1:Header Name="ReplyTo" Namespace="http://www.w3.org/2005/08/addressing"/> 
        <sp1:Header Name="MessageID" Namespace="http://www.w3.org/2005/08/addressing"/> 
        <sp1:Header Name="RelatesTo" Namespace="http://www.w3.org/2005/08/addressing"/> 
        <sp1:Header Name="Action" Namespace="http://www.w3.org/2005/08/addressing"/> 
        <sp1:Header Name="AckRequested" Namespace="http://schemas.xmlsoap.org/ws/2005/02/rm"/> 
        <sp1:Header Name="SequenceAcknowledgement" Namespace="http://schemas.xmlsoap.org/ws/2005/02/rm"/> 
        <sp1:Header Name="Sequence" Namespace="http://schemas.xmlsoap.org/ws/2005/02/rm"/> 
        <sp1:Header Name="CreateSequence" Namespace="http://schemas.xmlsoap.org/ws/2005/02/rm"/> 
       </sp1:SignedParts> 
      </wsp1:All> 
     </wsp1:ExactlyOne> 
    </wsp1:Policy> 
    <wsp1:Policy wsu:Id="TimePortBinding_timeOfDay_Output_Policy"> 
     <wsp1:ExactlyOne> 
      <wsp1:All> 
       <sp1:EncryptedParts> 
        <sp1:Body/> 
       </sp1:EncryptedParts> 
       <sp1:SignedParts> 
        <sp1:Body/> 
        <sp1:Header Name="To" Namespace="http://www.w3.org/2005/08/addressing"/> 
        <sp1:Header Name="From" Namespace="http://www.w3.org/2005/08/addressing"/> 
        <sp1:Header Name="FaultTo" Namespace="http://www.w3.org/2005/08/addressing"/> 
        <sp1:Header Name="ReplyTo" Namespace="http://www.w3.org/2005/08/addressing"/> 
        <sp1:Header Name="MessageID" Namespace="http://www.w3.org/2005/08/addressing"/> 
        <sp1:Header Name="RelatesTo" Namespace="http://www.w3.org/2005/08/addressing"/> 
        <sp1:Header Name="Action" Namespace="http://www.w3.org/2005/08/addressing"/> 
        <sp1:Header Name="AckRequested" Namespace="http://schemas.xmlsoap.org/ws/2005/02/rm"/> 
        <sp1:Header Name="SequenceAcknowledgement" Namespace="http://schemas.xmlsoap.org/ws/2005/02/rm"/> 
        <sp1:Header Name="Sequence" Namespace="http://schemas.xmlsoap.org/ws/2005/02/rm"/> 
        <sp1:Header Name="CreateSequence" Namespace="http://schemas.xmlsoap.org/ws/2005/02/rm"/> 
       </sp1:SignedParts> 
      </wsp1:All> 
     </wsp1:ExactlyOne> 
    </wsp1:Policy> 
</definitions> 
+0

爲什麼在UT不需要TrustStore URL時拋出異常?我對這個問題沒有太多的想法,但可能是你應該檢查你的安全配置! – 2012-04-01 07:17:45

回答

2

當您配置使用Web服務客戶Netbeans的(如發展默認值)證書有時正確的配置將不寫入配置文件。所以在這種情況下,您必須手動添加正確的配置。

在這種情況下,丟失的情況是位於客戶端配置內的密鑰庫文件。因此,您必須將位置明確添加到wsit-client.xml或從中導入的其他配置文件。

<sc:KeyStore wspp:visibility="private" location="/home/username/.netbeans/7.0/config/GF3_113/domain1/config/keystore.jks" type="JKS" storepass="changeit" alias="xws-security-server"/> 

這可以從Netbeans的提供的UI界面來完成,也可以隨時使用文件編輯器。該位置可從wsit-ws。[Servicename]從webservice實現中獲得。

+0

不要忘記[將此帖標記爲答案](http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work/5235#5235)。 – 2012-04-01 15:37:56

+0

必須等兩天才能接受我自己的回答:) – Switch 2012-04-01 16:12:52

+0

哦好吧別擔心,只是不要忘了它請 – 2012-04-01 16:15:36