java - cxf ws-security client does not bind the configuration file -
i try deploy ws-security soap web service using eclipse luna , wildfly 8.1. these sample codes
== sei ==
@webservice @policysets({"ws-sp-ex223_wss11_anonymous_x509_sign_encrypt"}) public interface ihelloworld { @webmethod @webresult public string sayhello(@webparam string name); }
== service bean ==
@webservice @endpointconfig(configfile = "web-inf/jaxws-endpoint-config.xml", configname = "custom ws-security endpoint") public class helloworld implements ihelloworld { @override public string sayhello(string name) { // todo auto-generated method stub return "hello " + name; } }
== jaxws-endpoint-config.xml ==
<jaxws-config xmlns="urn:jboss:jbossws-jaxws-config:4.0" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:javaee="http://java.sun.com/xml/ns/javaee" xsi:schemalocation="urn:jboss:jbossws-jaxws-config:4.0 schema/jbossws-jaxws-config_4_0.xsd"> <endpoint-config> <config-name>custom ws-security endpoint</config-name> <property> <property-name>ws-security.signature.properties</property-name> <property-value>meta-inf/server.properties</property-value> </property> <property> <property-name>ws-security.encryption.properties</property-name> <property-value>meta-inf/server.properties</property-value> </property> <property> <property-name>ws-security.signature.username</property-name> <property-value>server</property-value> </property> <property> <property-name>ws-security.encryption.username</property-name> <property-value>client</property-value> </property> <property> <property-name>ws-security.callback-handler</property-name> <property-value>com.aaa.soap.keystorepasswordcallback</property-value> </property> </endpoint-config> </jaxws-config>
== server.properties ==
org.apache.ws.security.crypto.provider=org.apache.ws.security.components.crypto.merlin org.apache.ws.security.crypto.merlin.keystore.type=jks org.apache.ws.security.crypto.merlin.keystore.password=password org.apache.ws.security.crypto.merlin.keystore.alias=server org.apache.ws.security.crypto.merlin.keystore.file=meta-inf/server.jks
i endorse related jar files , deployment successful. afraid client codes throw exception
== client.properties ==
org.apache.ws.security.crypto.provider=org.apache.ws.security.components.crypto.merlin org.apache.ws.security.crypto.merlin.keystore.type=jks org.apache.ws.security.crypto.merlin.keystore.password=password org.apache.ws.security.crypto.merlin.keystore.alias=client org.apache.ws.security.crypto.merlin.keystore.file=client.jks
== soapclient.java ==
public class soapclient { private final string serviceurl = "http://localhost:8080/soapsecureweb/helloworld"; private ihelloworld port; public soapclient() { try { qname servicename = new qname("http://soap.aaa.com/", "helloworldservice"); url wsdlurl = new url(serviceurl + "?wsdl"); service service = service.create(wsdlurl, servicename); port = (ihelloworld) service.getport(ihelloworld.class); ((bindingprovider) port).getrequestcontext().put(securityconstants.callback_handler, new keystorepasswordcallback()); ((bindingprovider) port).getrequestcontext().put(securityconstants.signature_properties, thread.currentthread().getcontextclassloader().getresource("client.properties")); ((bindingprovider) port).getrequestcontext().put(securityconstants.encrypt_properties, thread.currentthread().getcontextclassloader().getresource("client.properties")); ((bindingprovider) port).getrequestcontext().put(securityconstants.signature_username, "client"); ((bindingprovider) port).getrequestcontext().put(securityconstants.encrypt_username, "server"); } catch (exception e) { // todo auto-generated catch block e.printstacktrace(); } } // constructor throws no exception. public string callmethd(string name) { return port.sayhello("joseph"); // method throws exception } public static void main(string[] args) { // todo auto-generated method stub soapclient tc= new soapclient(); string result=tc.callmethd("joseph"); system.out.println(result); } }
the exceptions below :
exception in thread "main" javax.xml.ws.soap.soapfaultexception: these policy alternatives can not satisfied: {http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702}protectiontoken {http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702}includetimestamp: received timestamp not match requirements {http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702}symmetricbinding: received timestamp not match 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 @ org.apache.cxf.jaxws.jaxwsclientproxy.invoke(jaxwsclientproxy.java:157) @ com.sun.proxy.$proxy22.sayhello(unknown source) @ com.aaa.soap.soapclient.callmethd(soapclient.java:38) @ com.aaa.soap.soapclient.main(soapclient.java:44) caused by: org.apache.cxf.binding.soap.soapfault: these policy alternatives can not satisfied: {http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702}protectiontoken {http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702}includetimestamp: received timestamp not match requirements {http://docs.oasis-open.org/ws-sx/ws-securitypolicy/200702}symmetricbinding: received timestamp not match 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 @ org.apache.cxf.binding.soap.interceptor.soap11faultininterceptor.unmarshalfault(soap11faultininterceptor.java:84) @ org.apache.cxf.binding.soap.interceptor.soap11faultininterceptor.handlemessage(soap11faultininterceptor.java:51) @ org.apache.cxf.binding.soap.interceptor.soap11faultininterceptor.handlemessage(soap11faultininterceptor.java:40) @ org.apache.cxf.phase.phaseinterceptorchain.dointercept(phaseinterceptorchain.java:272) @ org.apache.cxf.interceptor.abstractfaultchaininitiatorobserver.onmessage(abstractfaultchaininitiatorobserver.java:113) @ org.apache.cxf.binding.soap.interceptor.checkfaultinterceptor.handlemessage(checkfaultinterceptor.java:69) @ org.apache.cxf.binding.soap.interceptor.checkfaultinterceptor.handlemessage(checkfaultinterceptor.java:34) @ org.apache.cxf.phase.phaseinterceptorchain.dointercept(phaseinterceptorchain.java:272) @ org.apache.cxf.endpoint.clientimpl.onmessage(clientimpl.java:845) @ org.apache.cxf.transport.http.httpconduit$wrappedoutputstream.handleresponseinternal(httpconduit.java:1624) @ org.apache.cxf.transport.http.httpconduit$wrappedoutputstream.handleresponse(httpconduit.java:1513) @ org.apache.cxf.transport.http.httpconduit$wrappedoutputstream.close(httpconduit.java:1318) @ org.apache.cxf.transport.abstractconduit.close(abstractconduit.java:56) @ org.apache.cxf.transport.http.httpconduit.close(httpconduit.java:632) @ org.apache.cxf.interceptor.messagesenderinterceptor$messagesenderendinginterceptor.handlemessage(messagesenderinterceptor.java:62) @ org.apache.cxf.phase.phaseinterceptorchain.dointercept(phaseinterceptorchain.java:272) @ org.apache.cxf.endpoint.clientimpl.doinvoke(clientimpl.java:570) @ org.apache.cxf.endpoint.clientimpl.invoke(clientimpl.java:479) @ org.apache.cxf.endpoint.clientimpl.invoke(clientimpl.java:382) @ org.apache.cxf.endpoint.clientimpl.invoke(clientimpl.java:335) @ org.apache.cxf.frontend.clientproxy.invokesync(clientproxy.java:96) @ org.apache.cxf.jaxws.jaxwsclientproxy.invoke(jaxwsclientproxy.java:135) ... 3 more
it seems client codes have problems in binding client.properties configuration file. advice appreciated. in advance.
try this:
<property> <property-name>ws-security.signature.properties</property-name> <property-value>server.properties</property-value> </property>
and put property files directly under src folder.
Comments
Post a Comment