2014-09-02 3 views
3

J'essaie d'implémenter un point de terminaison CXF avec WS-Security et de recevoir des demandes envoyées par soapUI. Le mot de passe pour UsernameToken est stocké dans le texte du plan. Je ne suis intéressé que par recevoir des demandes. J'utilise ServiceMix 5.0.0 avec CXF 2.7.10 et Camel 2.12.3.WS-Security avec Apache CXF

L'élément politique à partir du fichier WSDL:

<wsp:Policy wsu:Id="MyPolicy"> 
    <wsp:ExactlyOne> 
     <wsp:All> 
     <sp:TransportBinding 
      xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy"> 
      <wsp:Policy> 
      <sp:TransportToken> 
       <wsp:Policy> 
       <sp:HttpsToken RequireClientCertificate="false" /> 
       </wsp:Policy> 
      </sp:TransportToken> 
      <sp:AlgorithmSuite> 
       <wsp:Policy> 
       <sp:Basic256 /> 
       </wsp:Policy> 
      </sp:AlgorithmSuite> 
      <sp:Layout> 
       <wsp:Policy> 
       <sp:Lax /> 
       </wsp:Policy> 
      </sp:Layout> 
      <sp:IncludeTimestamp /> 
      </wsp:Policy> 
     </sp:TransportBinding> 
     <sp:SignedSupportingTokens 
      xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy"> 
      <wsp:Policy> 
      <sp:UsernameToken 
       sp:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/AlwaysToRecipient"> 
       <wsp:Policy> 
       <sp:WssUsernameToken10 /> 
       </wsp:Policy> 
      </sp:UsernameToken> 
      </wsp:Policy> 
     </sp:SignedSupportingTokens> 
     <sp:Wss10 xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy"> 
      <wsp:Policy /> 
     </sp:Wss10> 
     </wsp:All> 
    </wsp:ExactlyOne> 
    </wsp:Policy> 

Le message SOAP généré par soapUI:

<wsse:Security soapenv:mustUnderstand="1" 
    xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" 
    xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"> 

    <wsse:UsernameToken wsu:Id="UsernameToken-0784752F597FAC191C140966645160280"> 
    <wsse:Username>foo</wsse:Username> 
    <wsse:Password 
     Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">bar</wsse:Password> 
    <wsse:Nonce 
     EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">8C0iYAOWi3b+EgfDaY6n+Q==</wsse:Nonce> 
    <wsu:Created>2014-09-02T14:00:51.602Z</wsu:Created> 
    </wsse:UsernameToken> 
</wsse:Security> 

L'intercepteur WSS4JInInterceptor que j'ajouter à la CXF Endpoint Dans intercepteurs. C'est le seul intercepteur que j'ajoute explicitement.

private WSS4JInInterceptor getWssInInterceptor() { 
    Map<String, Object> propertiesMap = new HashMap<String, Object>(); 
    propertiesMap.put(WSHandlerConstants.ACTION, WSHandlerConstants.USERNAME_TOKEN); 
    propertiesMap.put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_TEXT); 
    propertiesMap.put(WSHandlerConstants.USER, "bar"); 
    propertiesMap.put(WSHandlerConstants.PW_CALLBACK_CLASS, ServerPasswordCallback.class.getName()); 
    return new WSS4JInInterceptor(propertiesMap); 
    } 

Le ServerPasswordCallback.class

public class ServerPasswordCallback implements CallbackHandler { 

    @Override 
    public void handle(Callback[] callbacks) throws IOException, 
     UnsupportedCallbackException { 

    for (int i = 0; i < callbacks.length; i++) { 

     WSPasswordCallback pc = (WSPasswordCallback) callbacks[i]; 

     if (pc.getUsage() == WSPasswordCallback.USERNAME_TOKEN) { 
     if (pc.getIdentifier().equalsIgnoreCase("foo")) 
      pc.setPassword("bar"); 
     } 
    } 

    } 

} 

J'utilise soapUI pour envoyer une demande au serveur, mais je reçois ce dans le journal des ServiceMix:

2014-09-02 17:00:44,630 | WARN | qtp32763811-5522 | PhaseInterceptorChain   | ?         ? | 129 - org.apache.cxf.cxf-api - 2.7.10 | Interceptor for {http://localhost/incoming}MyService#{http://localhost/incoming}IncomingChannel has thrown exception, unwinding now 
org.apache.cxf.ws.policy.PolicyException: These policy alternatives can not be satisfied: 
{http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702}TransportBinding 
{http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702}TransportToken 
{http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702}IncludeTimestamp 
{http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702}Layout 
{http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702}SignedSupportingTokens 
{http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702}UsernameToken 
{http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702}Wss10 
     at org.apache.cxf.ws.policy.AssertionInfoMap.checkEffectivePolicy(AssertionInfoMap.java:179)[161:org.apache.cxf.cxf-rt-ws-policy:2.7.10] 
     at org.apache.cxf.ws.policy.PolicyVerificationInInterceptor.handle(PolicyVerificationInInterceptor.java:101)[161:org.apache.cxf.cxf-rt-ws-policy:2.7.10] 
     at org.apache.cxf.ws.policy.AbstractPolicyInterceptor.handleMessage(AbstractPolicyInterceptor.java:44)[161:org.apache.cxf.cxf-rt-ws-policy:2.7.10] 
     at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:272)[129:org.apache.cxf.cxf-api:2.7.10] 
     at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)[129:org.apache.cxf.cxf-api:2.7.10] 

Q :

Si j'utilise les informations d'identification incorrectes dans la demande créée dans soapUI, j'obtiens l'exception attendue, c'est correct, mais h Comment ces règles peuvent-elles être satisfaites du côté serveur? Où puis-je trouver de la documentation/des exemples sur ces assertions politiques?

Merci!

Répondre

3

Il n'est pas nécessaire d'ajouter "WSS4JInInceptceptor". Le WSS4JInInceptceptor ne s'applique pas lorsque vous avez une WS-SecurityPolicy. Dans ce cas, CXF prend soin de configurer tous les intercepteurs pour vous. Vous n'avez qu'à fournir certains paramètres de configuration en tant que propriétés JAX-WS.

Voici quelques exemples au printemps:

https://git-wip-us.apache.org/repos/asf?p=cxf.git;a=blob_plain;f=systests/ws-security/src/test/resources/org/apache/cxf/systest/ws/ut/server.xml;hb=HEAD

En général, vous ne devez fournir un CallbackHandler ("ws-security.callback-gestionnaire") pour ce (UsernameToken) de cas d'utilisation.

BTW la demande ne correspond pas à la politique car elle n'inclut pas d'horodatage. Donc, soit supprimer la politique "IncludeTimestamp" ou bien en ajouter une à la demande dans SOAP-UI.

Colm.

+0

Oui, en supprimant le 'WSS4JInIncepteur', en ajoutant les accessoires et les fonctionnalités à l'extrémité comme dans le lien que vous avez fourni travaillé, merci! –

Questions connexes