2017-07-27 1 views
1

Ich entwickle eine Web-Service-cliente gegen eine WSDL-Datei, die die folgenden RichtlinienSatisfy Politik in CXF Client

<wsp:Policy xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:sp="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702" wsu:Id="SecurityServiceSignThenEncryptPolicy"> 
<wsp:ExactlyOne> 
    <wsp:All> 
     <sp:AsymmetricBinding> 
      <wsp:Policy> 
       <sp:InitiatorToken> 
        <wsp:Policy> 
         <sp:X509Token sp:IncludeToken="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702/IncludeToken/AlwaysToRecipient"> 
          <wsp:Policy> 
           <sp:WssX509V3Token10/> 
           <sp:WssX509V3Token11/> 
          </wsp:Policy> 
         </sp:X509Token> 
        </wsp:Policy> 
       </sp:InitiatorToken> 
       <sp:RecipientToken> 
        <wsp:Policy> 
         <sp:X509Token sp:IncludeToken="http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702/IncludeToken/Always"> 
          <wsp:Policy> 
           <sp:WssX509V3Token10/> 
           <sp:WssX509V3Token11/> 
          </wsp:Policy> 
         </sp:X509Token> 
        </wsp:Policy> 
       </sp:RecipientToken> 
       <sp:AlgorithmSuite> 
        <wsp:Policy> 
         <sp:Basic128Rsa15/> 
         <sp:Basic256Rsa15/> 
         <sp:Basic128Sha256Rsa15/> 
         <sp:Basic256Sha256Rsa15/> 
        </wsp:Policy> 
       </sp:AlgorithmSuite> 
       <sp:Layout> 
        <wsp:Policy> 
         <sp:Lax/> 
        </wsp:Policy> 
       </sp:Layout> 
       <sp:IncludeTimestamp/> 
       <sp:ProtectTokens/> 
       <sp:OnlySignEntireHeadersAndBody/> 
      </wsp:Policy> 
     </sp:AsymmetricBinding> 
     <sp:Wss10> 
      <wsp:Policy> 
       <sp:MustSupportRefKeyIdentifier/> 
       <sp:MustSupportRefIssuerSerial/> 
       <sp:MustSupportRefThumbprint/> 
       <sp:MustSupportRefEncryptedKey/> 
      </wsp:Policy> 
     </sp:Wss10> 
     <sp:Wss11> 
      <wsp:Policy> 
       <sp:MustSupportRefKeyIdentifier/> 
       <sp:MustSupportRefIssuerSerial/> 
       <sp:MustSupportRefThumbprint/> 
       <sp:MustSupportRefEncryptedKey/> 
       <sp:RequireSignatureConfirmation/> 
      </wsp:Policy> 
     </sp:Wss11> 
    </wsp:All> 
</wsp:ExactlyOne> 
<wsp:Policy wsu:Id="InputBindingPolicy"> 
    <wsp:ExactlyOne> 
     <wsp:All> 
      <sp:EncryptedParts> 
       <sp:Body/> 
      </sp:EncryptedParts> 
      <sp:SignedParts> 
       <sp:Body/> 
      </sp:SignedParts> 
     </wsp:All> 
    </wsp:ExactlyOne> 
</wsp:Policy> 
<wsp:Policy wsu:Id="OutputBindingPolicy"> 
    <wsp:ExactlyOne> 
     <wsp:All> 
      <sp:EncryptedParts> 
       <sp:Body/> 
      </sp:EncryptedParts> 
      <sp:SignedParts> 
       <sp:Body/> 
      </sp:SignedParts> 
     </wsp:All> 
    </wsp:ExactlyOne> 
</wsp:Policy> 

hat, wenn ich eine Anfrage mit SOAP ui schickte ich

faultstring>These policy alternatives can not be satisfied: 
{http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702}AsymmetricBinding: Received Timestamp does not match the requirements 
{http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702}X509Token: The received token does not match the token inclusion requirement 
{http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702}InitiatorToken 
{http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702}RecipientToken 
{http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702}IncludeTimestamp: Received Timestamp does not match the requirements 
{http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702}EncryptedParts: 
{http://schemas.xmlsoap.org/soap/envelope/}Body not ENCRYPTED 
{http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702}SignedParts: 
{http://schemas.xmlsoap.org/soap/envelope/}Body not SIGNED</faultstring> 

Also habe ich einen CXF-Client gestartet, das ist mein Code

public static void main(String[] args) throws MalformedURLException { 
    URL wsdlURL = new URL("http://localhost:8080/pathToWsdl?wsdl"); 
    QName SERVICE_NAME = new QName("http://webservices.provider.com/", "serviceClient"); 
    Service service = Service.create(wsdlURL, SERVICE_NAME); 

    executeCall(service); 
} 

public static void executeCall(Service service) { 
    //code to get clientInterface; 

    Client client = ClientProxy.getClient(clientInterface); 
    Endpoint cxfEndpoint = client.getEndpoint(); 

    Map<String, Object> inProps = new HashMap<String, Object>(); 
    WSS4JInInterceptor wssIn = new WSS4JInInterceptor(inProps); 
    cxfEndpoint.getInInterceptors().add(wssIn); 
    Map<String, Object> outProps = new HashMap<String, Object>(); 

    outProps.put(WSHandlerConstants.ACTION, 
      WSHandlerConstants.TIMESTAMP + " " + WSHandlerConstants.SIGNATURE + " " + WSHandlerConstants.ENCRYPT); 

    outProps.put(WSHandlerConstants.USER, "keycliente"); 
    outProps.put(WSHandlerConstants.PW_CALLBACK_CLASS, KeystorePasswordCallback.class.getName()); 

    outProps.put(WSHandlerConstants.SIG_PROP_FILE, "client-crypto.properties"); 
    outProps.put(WSHandlerConstants.ENC_PROP_FILE, "client-crypto.properties"); 
    outProps.put(WSHandlerConstants.SIG_KEY_ID, "DirectReference"); 
    outProps.put(WSHandlerConstants.ENCRYPTION_USER, "tobias"); 

    outProps.put(WSHandlerConstants.ENC_KEY_TRANSPORT, WSConstants.KEYTRANSPORT_RSA15); 

    WSS4JOutInterceptor wssOut = new WSS4JOutInterceptor(outProps); 

    cxfEndpoint.getOutInterceptors().add(wssOut); 

    ServiceRequest request= buildRequest(); 
    serviceInterface.method(request); 
} 

Nach dem Ausführen dieses Clients konnte ich einen Schritt weiter gehen, mein Problem ist im Moment mit den Remanet-Richtlinien verbunden, die ich nicht erfüllen kann.

{http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702}AsymmetricBinding: Received Timestamp does not match the requirements 
{http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702}InitiatorToken 
{http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702}RecipientToken 
{http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702}IncludeTimestamp: Received Timestamp does not match the requirements 

Mit diesem erros zumindest weiß ich, dass das Signieren und Verschlüsseln Teil funktionieren, Aber ich habe keine Ahnung, wie den Empfänger-Token und die andere Sache bauen.

Antwort

0

Ich habe das funktioniert. Das Problem hängt damit zusammen, wie ich den Client programmiert habe. WENN DIE POLITIK IN DER WSDL KONFIGURIERT WIRD, ist es am besten, sie zu laden und CXF zu lassen, um die Magie zu wirken. Wenn ich einen Interceptor hinzufüge, scheint es, dass es CXF-Schritte überschreibt, oder CXF macht keine Schritte. Mit diesem Code konnte ich es zum Laufen bringen.

public static void main(String[] args) throws MalformedURLException, DatatypeConfigurationException { 

    URL wsdlURL = new File("ApiBancosClients.wsdl").toURI().toURL(); 
    QName SERVICE_NAME = new QName("http://webservices.apibancos.debin.com/", "ApiBancosClient"); 
    Service service = Service.create(wsdlURL, SERVICE_NAME); 

    callApiBancosClientService(service); 
} 

public static void callApiBancosClientService(Service service) throws DatatypeConfigurationException { 
    ApiBancosClientInterface apiBancosClientInterface = service.getPort(ApiBancosClientInterface.class); 

    Client client = ClientProxy.getClient(apiBancosClientInterface); 
    client.getRequestContext().put(SecurityConstants.ENCRYPT_PROPERTIES, "client-crypto.properties"); 
    client.getRequestContext().put(SecurityConstants.SIGNATURE_PROPERTIES, "client-crypto.properties"); 
    client.getRequestContext().put(SecurityConstants.CALLBACK_HANDLER, "com.bp.KeystorePasswordCallback"); 
    client.getRequestContext().put(SecurityConstants.SIGNATURE_USERNAME, "keycliente"); 
    client.getRequestContext().put(SecurityConstants.ENCRYPT_USERNAME, "keyserver"); 

    client.getResponseContext().put(SecurityConstants.ENCRYPT_PROPERTIES, "client-crypto.properties"); 
    client.getResponseContext().put(SecurityConstants.SIGNATURE_PROPERTIES, "client-crypto.properties"); 
    client.getResponseContext().put(SecurityConstants.CALLBACK_HANDLER, "com.bp.KeystorePasswordCallback"); 

    Endpoint cxfEndpoint = client.getEndpoint(); 
    Map<String, Object> inProps = new HashMap<String, Object>(); 
    AvisoNuevoDebinRequest avisoDeNuevoDebin = buildRequest(); 
    apiBancosClientInterface.avisoDeNuevoDebin(avisoDeNuevoDebin); 
    System.out.println("FINISH"); 
} 
Verwandte Themen