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.
INFO: Creating Service {http://service/}HelloWorld from class service.HelloWorld
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"); } }
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
Partager