IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Services Web Java Discussion :

Problème WS-Security sous CXF


Sujet :

Services Web Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Inscrit en
    Octobre 2006
    Messages
    32
    Détails du profil
    Informations forums :
    Inscription : Octobre 2006
    Messages : 32
    Par défaut Problème WS-Security sous CXF
    Bonjour,

    Je cherche à protéger un WS sous CXF par authentification à l'aide de WS-Security. J'essaie actuellement de reproduire la démo qu'on peut trouver sur le site de cxf [1], mais je me heurte à une erreur HIERARCHY_REQUEST_ERR. Apparemment le header de mon objet SOAP est incorrect, ce qui voudrait dire que mon client n'envoie pas les infos qu'il devrait.

    Si quelqu'un a des notions en WSS ou a déjà rencontré ce type d'erreur je suis preneur, j'avoue ne pas bien comprendre quelle est la cause du problème.

    Je joins le code de mon client et l'erreur retournée.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    public class ClientJAXWSWithAuth {
     
        private static final QName SERVICE_NAME 
        = new QName("http://service/", "HelloWorld");
    	private static final QName PORT_NAME 
    	    = new QName("http://service/", "HelloWorldPort");
     
     
    	private ClientJAXWSWithAuth() {
    	} 
     
    	public static void main(String args[]) throws Exception {
    		Service service = Service.create(SERVICE_NAME);
    	    // Endpoint Address
    	    String endpointAddress = "http://localhost:9091/helloWorld";
     
    	    // Add a port to the Service
    	    service.addPort(PORT_NAME, SOAPBinding.SOAP11HTTP_BINDING, endpointAddress);
     
    	    HelloWorld hw = service.getPort(HelloWorld.class);	    
     
    	    Client client = ClientProxy.getClient(hw);
    	    Endpoint cxfEndpoint = client.getEndpoint();
     
    	    Map<String,Object> outProps= new HashMap<String,Object>();
     
    	    WSS4JOutInterceptor wssOut = new WSS4JOutInterceptor(outProps);
    	    cxfEndpoint.getOutInterceptors().add(wssOut);
    	    //cxfEndpoint.getOutInterceptors().add(new SAAJOutInterceptor());
     
    	    outProps.put(WSHandlerConstants.ACTION, WSHandlerConstants.USERNAME_TOKEN);
    	    //	  Specify our username
    		outProps.put(WSHandlerConstants.USER, "flo");
    		//	  Password type : plain text
    		outProps.put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_TEXT);
    		//	  for hashed password use:
    		//	 properties.put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_DIGEST);
    		//	  Callback used to retrieve password for given user.
    		outProps.put(WSHandlerConstants.PW_CALLBACK_CLASS, ClientPasswordCallback.class.getName());
     
    		System.out.println(hw.sayHi("World with Auth."));
    	}
     
    }
     
     
    //this class is used for the WS-Security
    public class ClientPasswordCallback implements CallbackHandler {
     
    	public ClientPasswordCallback() {
    	}
     
    	public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
     
    		WSPasswordCallback pc = (WSPasswordCallback) callbacks[0];
    		// set the password for our message.
    		pc.setPassword("password");
    	}
     
    }
    INFO: Creating Service {http://service/}HelloWorld from class service.HelloWorld
    8 juil. 2008 15:42:22 org.apache.cxf.phase.PhaseInterceptorChain doIntercept
    INFO: Interceptor has thrown exception, unwinding now
    org.w3c.dom.DOMException: HIERARCHY_REQUEST_ERR: Tentative d'insertion d'un noeud ? un emplacement o? cette op?ration n'est pas permise.
    at org.apache.xerces.dom.CoreDocumentImpl.insertBefore(Unknown Source)
    at org.apache.xerces.dom.NodeImpl.appendChild(Unknown Source)
    at com.ibm.ws.webservices.engine.xmlsoap.SOAPPart.appendChild(SOAPPart.java:244)
    at org.apache.cxf.staxutils.W3CDOMStreamWriter.newChild(W3CDOMStreamWriter.java:81)
    at org.apache.cxf.staxutils.W3CDOMStreamWriter.writeStartElement(W3CDOMStreamWriter.java:98)
    at org.apache.cxf.binding.soap.interceptor.SoapOutInterceptor.writeSoapEnvelopeStart(SoapOutInterceptor.java:95)
    at org.apache.cxf.binding.soap.interceptor.SoapOutInterceptor.handleMessage(SoapOutInterceptor.java:76)
    at org.apache.cxf.binding.soap.interceptor.SoapOutInterceptor.handleMessage(SoapOutInterceptor.java:57)
    at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:221)
    at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:296)
    at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:242)
    at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:73)
    at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:178)
    at $Proxy31.sayHi(Unknown Source)
    at client.ClientJAXWSWithAuth.main(ClientJAXWSWithAuth.java:59)


    [1] http://cwiki.apache.org/CXF20DOC/ws-security.html

  2. #2
    oca
    oca est déconnecté
    Membre chevronné
    Profil pro
    Inscrit en
    Octobre 2004
    Messages
    354
    Détails du profil
    Informations personnelles :
    Âge : 52
    Localisation : Suisse

    Informations forums :
    Inscription : Octobre 2004
    Messages : 354
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
     //cxfEndpoint.getOutInterceptors().add(new SAAJOutInterceptor());
    Hello, je pense qu'il faut remettre cette ligne.
    A+

  3. #3
    Membre averti
    Inscrit en
    Octobre 2006
    Messages
    32
    Détails du profil
    Informations forums :
    Inscription : Octobre 2006
    Messages : 32
    Par défaut
    Salut Oca,

    En fait cette ligne n'est nécessaire que pour les versions de CXF antérieures à 2.1, sachant que je suis sur la 2.1.1.

    En l'ajoutant l'erreur est exactement la même.

  4. #4
    oca
    oca est déconnecté
    Membre chevronné
    Profil pro
    Inscrit en
    Octobre 2004
    Messages
    354
    Détails du profil
    Informations personnelles :
    Âge : 52
    Localisation : Suisse

    Informations forums :
    Inscription : Octobre 2004
    Messages : 354
    Par défaut
    Voila un jar avec un petit projet que j'avais fait pour tester ws-security et CXF.
    il faut d'abord lancer la classe oca.server.TestCXFServer,
    puis le client : oca.client.TestCXFClient

    A+
    Fichiers attachés Fichiers attachés

  5. #5
    Membre averti
    Inscrit en
    Octobre 2006
    Messages
    32
    Détails du profil
    Informations forums :
    Inscription : Octobre 2006
    Messages : 32
    Par défaut
    Merci pour ton aide Oca

    Alors ton serveur se lance sans problème (comme le mien) mais le client plante de la même manière
    Je suppose que ça marchait chez toi, donc le problème doit venir de mon environnement de travail, mais je ne vois pas vraiment d'où...
    Est-ce que ça pourrait être un problème de jar manquant ou de conflit entre librairies?
    Ou bien un changement récent de CXF (je suis sur la toute dernière version) qui est la cause de tout ça?

    Là je sèche, d'autant plus que mes connaissances sur le sujet sont assez limitées.

    Je te joins l'erreur retournée à l'exécution du Client, moi ça ne m'avance pas beaucoup, mais on ne sait jamais.

    INFO: Creating Service {http://common/}IService from class common.IService
    8 juil. 2008 17:11:00 org.apache.cxf.phase.PhaseInterceptorChain doIntercept
    INFO: Interceptor has thrown exception, unwinding now
    org.w3c.dom.DOMException: HIERARCHY_REQUEST_ERR: Tentative d'insertion d'un noeud ? un emplacement o? cette op?ration n'est pas permise.
    at org.apache.xerces.dom.CoreDocumentImpl.insertBefore(Unknown Source)
    at org.apache.xerces.dom.NodeImpl.appendChild(Unknown Source)
    at com.ibm.ws.webservices.engine.xmlsoap.SOAPPart.appendChild(SOAPPart.java:244)
    at org.apache.cxf.staxutils.W3CDOMStreamWriter.newChild(W3CDOMStreamWriter.java:81)
    at org.apache.cxf.staxutils.W3CDOMStreamWriter.writeStartElement(W3CDOMStreamWriter.java:98)
    at org.apache.cxf.binding.soap.interceptor.SoapOutInterceptor.writeSoapEnvelopeStart(SoapOutInterceptor.java:95)
    at org.apache.cxf.binding.soap.interceptor.SoapOutInterceptor.handleMessage(SoapOutInterceptor.java:76)
    at org.apache.cxf.binding.soap.interceptor.SoapOutInterceptor.handleMessage(SoapOutInterceptor.java:57)
    at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:221)
    at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:296)
    at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:242)
    at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:73)
    at org.apache.cxf.frontend.ClientProxy.invoke(ClientProxy.java:68)
    at $Proxy38.sayHello(Unknown Source)
    at client.TestCXFClient.main(TestCXFClient.java:50)
    Exception in thread "main" org.w3c.dom.DOMException: HIERARCHY_REQUEST_ERR: Tentative d'insertion d'un noeud ? un emplacement o? cette op?ration n'est pas permise.
    at org.apache.xerces.dom.CoreDocumentImpl.insertBefore(Unknown Source)
    at org.apache.xerces.dom.NodeImpl.appendChild(Unknown Source)
    at com.ibm.ws.webservices.engine.xmlsoap.SOAPPart.appendChild(SOAPPart.java:244)
    at org.apache.cxf.staxutils.W3CDOMStreamWriter.newChild(W3CDOMStreamWriter.java:81)
    at org.apache.cxf.staxutils.W3CDOMStreamWriter.writeStartElement(W3CDOMStreamWriter.java:98)
    at org.apache.cxf.binding.soap.interceptor.SoapOutInterceptor.writeSoapEnvelopeStart(SoapOutInterceptor.java:95)
    at org.apache.cxf.binding.soap.interceptor.SoapOutInterceptor.handleMessage(SoapOutInterceptor.java:76)
    at org.apache.cxf.binding.soap.interceptor.SoapOutInterceptor.handleMessage(SoapOutInterceptor.java:57)
    at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:221)
    at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:296)
    at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:242)
    at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:73)
    at org.apache.cxf.frontend.ClientProxy.invoke(ClientProxy.java:68)
    at $Proxy38.sayHello(Unknown Source)
    at client.TestCXFClient.main(TestCXFClient.java:50)

  6. #6
    oca
    oca est déconnecté
    Membre chevronné
    Profil pro
    Inscrit en
    Octobre 2004
    Messages
    354
    Détails du profil
    Informations personnelles :
    Âge : 52
    Localisation : Suisse

    Informations forums :
    Inscription : Octobre 2004
    Messages : 354
    Par défaut
    Bizarre, j'ai essayé avec succès avec les version 2.0.5 et 2.1.1 de CXF...
    A+

  7. #7
    Membre averti
    Inscrit en
    Octobre 2006
    Messages
    32
    Détails du profil
    Informations forums :
    Inscription : Octobre 2006
    Messages : 32
    Par défaut
    Ok j'y suis finalement arrivé. Apparemment le problème venait d'un conflit entre les librairies du projet et celles de WAS 6.1 que j'utilisais pour des tests parallèles avec Spring.

    Le problème est que la finalité pour moi est d'utiliser WAS 6.1 et Spring pour les WS, et pas le frontend fourni par CXF. Je vais donc chercher d'où vient le conflit. Je posterai ici ce que je trouve, ça peut toujours servir.

    Encore merci pour ton aide Oca!

  8. #8
    Membre averti
    Inscrit en
    Octobre 2006
    Messages
    32
    Détails du profil
    Informations forums :
    Inscription : Octobre 2006
    Messages : 32
    Par défaut
    Si jamais ça intéresse quelqu'un, concernant l'utilisation de CXF couplé à WS-Security sous Websphere: le problème vient du fait que IBM a ré-implémenté nombre de classes SUN, ce qui créé des problèmes avec CXF, qui en est dépendant.

    La solution consiste donc à intégrer ces classes au CLASSPATH et à forcer leur utilisation prioritaire lors du déploiement. Ca se fait en réglant le mode du chargeur de classe du .war sur "PARENT_LAST". Accessible via le fichier application.xml de l'EAR de l'appli.

    Jar nécessaires sous WAS 6.1 avec CXF 2.1.1:
    - xercesImpl-1.5.jar
    - jaxb-xalan.jar

  9. #9
    Membre averti
    Profil pro
    Inscrit en
    Août 2008
    Messages
    14
    Détails du profil
    Informations personnelles :
    Âge : 40
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations forums :
    Inscription : Août 2008
    Messages : 14
    Par défaut Erreur provenant du client
    Bonjour à tous,
    et merci à oca pour tes sources.

    J'essaie actuellement d'intégrer le WSS à mon Web Service sous CXF.

    J'ai téléchargé tes sources,
    lancé le serveur : ok,
    lancé le client : pb :
    Exception in thread "main" org.apache.cxf.binding.soap.SoapFault: object is not an instance of declaring class while invoking public abstract java.lang.String oca.IService.sayHello(java.lang.String,java.lang.String) with params [Hello, oca!!!].
    at org.apache.cxf.binding.soap.interceptor.Soap11FaultInInterceptor.handleMessage(Soap11FaultInInterceptor.java:70)
    at org.apache.cxf.binding.soap.interceptor.Soap11FaultInInterceptor.handleMessage(Soap11FaultInInterceptor.java:35)
    at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:220)
    at org.apache.cxf.interceptor.AbstractFaultChainInitiatorObserver.onMessage(AbstractFaultChainInitiatorObserver.java:96)
    at org.apache.cxf.binding.soap.interceptor.CheckFaultInterceptor.handleMessage(CheckFaultInterceptor.java:69)
    at org.apache.cxf.binding.soap.interceptor.CheckFaultInterceptor.handleMessage(CheckFaultInterceptor.java:34)
    at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:220)
    at org.apache.cxf.endpoint.ClientImpl.onMessage(ClientImpl.java:449)
    at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponse(HTTPConduit.java:2029)
    at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1865)
    at org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:66)
    at org.apache.cxf.transport.http.HTTPConduit.close(HTTPConduit.java:593)
    at org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:62)
    at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:220)
    at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:296)
    at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:242)
    at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:73)
    at org.apache.cxf.frontend.ClientProxy.invoke(ClientProxy.java:68)
    at $Proxy39.sayHello(Unknown Source)
    at oca.client.TestCXFClient.main(TestCXFClient.java:56)

    Ce problème intervient au moment de l'appel du client :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    System.out.println(client.sayHello("Hello", "oca!!!"));
    Je ne sais pas si quelqu'un saurait pourquoi j'ai cette erreur ? (avec le code d'OCA, je le rappelle, si des fois d'autres voulaient tester)

    Merci d'avance


    ______________

    J'ai résolu le problème sans être réellement sûr de ce que j'ai fait .
    ça proviendrait surement d'un cast mal fait sur le
    IService client = (IService) factory.create();

    Encore merci

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Problème DBExpress et sous requêtes ???
    Par Trulane dans le forum Bases de données
    Réponses: 5
    Dernier message: 26/03/2004, 14h40
  2. [Install] Problème de lancement sous debian sid
    Par SoaR245 dans le forum Eclipse Java
    Réponses: 1
    Dernier message: 18/02/2004, 10h01
  3. problème de compilation sous visual C++
    Par fabmili dans le forum MFC
    Réponses: 4
    Dernier message: 08/02/2004, 19h52
  4. Problème d'include sous Dev-c++ 4.9.8.0
    Par Argonz dans le forum Dev-C++
    Réponses: 16
    Dernier message: 20/11/2003, 17h36
  5. Problème avec CopyDir sous D5
    Par Houben Jacques dans le forum Langage
    Réponses: 3
    Dernier message: 26/05/2003, 22h02

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo