[CXF-6991]WS-RM - Request context properties are lost when sending subsequent protocol message
Project: http://git-wip-us.apache.org/repos/asf/cxf/repo Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/7c303899 Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/7c303899 Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/7c303899 Branch: refs/heads/master-jaxrs-2.1 Commit: 7c3038997534a54fd36b372978bb18fe90e377ea Parents: 683bcab Author: Freeman Fang <[email protected]> Authored: Thu Aug 11 11:11:09 2016 +0800 Committer: Freeman Fang <[email protected]> Committed: Thu Aug 11 11:11:09 2016 +0800 ---------------------------------------------------------------------- .../main/java/org/apache/cxf/ws/rm/Proxy.java | 10 +++-- .../ws/rm/sec/WSRMWithWSSecurityPolicyTest.java | 45 ++++++++++++++++++++ .../cxf/systest/ws/rm/sec/client-policy.xml | 12 ++++++ 3 files changed, 64 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf/blob/7c303899/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/Proxy.java ---------------------------------------------------------------------- diff --git a/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/Proxy.java b/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/Proxy.java index 977ac55..77fb035 100644 --- a/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/Proxy.java +++ b/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/Proxy.java @@ -68,6 +68,9 @@ public class Proxy { // REVISIT assumption there is only a single outstanding offer private Identifier offeredIdentifier; + //hold the sequence message context + private Map<String, Object> sequenceContext; + public Proxy(RMEndpoint rme) { reliableEndpoint = rme; @@ -87,7 +90,7 @@ public class Proxy { RMConstants constants = protocol.getConstants(); OperationInfo oi = reliableEndpoint.getEndpoint(protocol).getEndpointInfo() .getService().getInterface().getOperation(constants.getSequenceAckOperationName()); - invoke(oi, protocol, new Object[] {ds}); + invoke(oi, protocol, new Object[] {ds}, this.sequenceContext); } void terminate(SourceSequence ss) throws RMException { @@ -100,7 +103,7 @@ public class Proxy { ts.setIdentifier(ss.getIdentifier()); ts.setLastMsgNumber(ss.getCurrentMessageNr()); EncoderDecoder codec = protocol.getCodec(); - invoke(oi, protocol, new Object[] {codec.convertToSend(ts)}); + invoke(oi, protocol, new Object[] {codec.convertToSend(ts)}, this.sequenceContext); } void terminate(DestinationSequence ds) throws RMException { @@ -113,7 +116,7 @@ public class Proxy { ts.setIdentifier(ds.getIdentifier()); ts.setLastMsgNumber(ds.getLastMessageNumber()); EncoderDecoder codec = protocol.getCodec(); - invoke(oi, protocol, new Object[] {codec.convertToSend(ts)}); + invoke(oi, protocol, new Object[] {codec.convertToSend(ts)}, this.sequenceContext); } void createSequenceResponse(final Object createResponse, ProtocolVariation protocol) throws RMException { @@ -131,6 +134,7 @@ public class Proxy { public CreateSequenceResponseType createSequence(EndpointReferenceType defaultAcksTo, RelatesToType relatesTo, boolean isServer, final ProtocolVariation protocol, final Exchange exchange, Map<String, Object> context) throws RMException { + this.sequenceContext = context; SourcePolicyType sp = reliableEndpoint.getManager().getSourcePolicy(); CreateSequenceType create = new CreateSequenceType(); http://git-wip-us.apache.org/repos/asf/cxf/blob/7c303899/systests/ws-rm/src/test/java/org/apache/cxf/systest/ws/rm/sec/WSRMWithWSSecurityPolicyTest.java ---------------------------------------------------------------------- diff --git a/systests/ws-rm/src/test/java/org/apache/cxf/systest/ws/rm/sec/WSRMWithWSSecurityPolicyTest.java b/systests/ws-rm/src/test/java/org/apache/cxf/systest/ws/rm/sec/WSRMWithWSSecurityPolicyTest.java index 4ba53f0..f3d2c19 100644 --- a/systests/ws-rm/src/test/java/org/apache/cxf/systest/ws/rm/sec/WSRMWithWSSecurityPolicyTest.java +++ b/systests/ws-rm/src/test/java/org/apache/cxf/systest/ws/rm/sec/WSRMWithWSSecurityPolicyTest.java @@ -19,17 +19,26 @@ package org.apache.cxf.systest.ws.rm.sec; +import java.util.HashMap; +import java.util.Map; import java.util.logging.Logger; +import javax.xml.namespace.QName; + import org.apache.cxf.Bus; import org.apache.cxf.BusFactory; import org.apache.cxf.bus.spring.SpringBusFactory; import org.apache.cxf.common.logging.LogUtils; +import org.apache.cxf.endpoint.Client; +import org.apache.cxf.frontend.ClientProxy; import org.apache.cxf.greeter_control.Greeter; +import org.apache.cxf.greeter_control.types.GreetMe; +import org.apache.cxf.service.model.BindingOperationInfo; import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase; import org.apache.cxf.testutil.common.AbstractBusTestServerBase; import org.apache.cxf.ws.rm.RMManager; +import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; @@ -83,4 +92,40 @@ public class WSRMWithWSSecurityPolicyTest extends AbstractBusClientServerTestBas context.close(); } + + @Test + public void testContextProperty() throws Exception { + ClassPathXmlApplicationContext context = + new ClassPathXmlApplicationContext("org/apache/cxf/systest/ws/rm/sec/client-policy.xml"); + Bus bus = (Bus)context.getBean("bus"); + BusFactory.setDefaultBus(bus); + BusFactory.setThreadDefaultBus(bus); + Greeter greeter = (Greeter)context.getBean("GreeterCombinedClientNoProperty"); + Client client = ClientProxy.getClient(greeter); + QName operationQName = new QName("http://cxf.apache.org/greeter_control", "greetMe"); + BindingOperationInfo boi = client.getEndpoint().getBinding().getBindingInfo().getOperation(operationQName); + Map<String, Object> invocationContext = new HashMap<String, Object>(); + Map<String, Object> requestContext = new HashMap<String, Object>(); + Map<String, Object> responseContext = new HashMap<String, Object>(); + invocationContext.put(Client.REQUEST_CONTEXT, requestContext); + invocationContext.put(Client.RESPONSE_CONTEXT, responseContext); + + requestContext.put("ws-security.username", "Alice"); + requestContext.put("ws-security.callback-handler", "org.apache.cxf.systest.ws.rm.sec.UTPasswordCallback"); + requestContext.put("ws-security.encryption.properties", "bob.properties"); + requestContext.put("ws-security.encryption.username", "bob"); + requestContext.put("ws-security.signature.properties", "alice.properties"); + requestContext.put("ws-security.signature.username", "alice"); + RMManager manager = bus.getExtension(RMManager.class); + boolean empty = manager.getRetransmissionQueue().isEmpty(); + assertTrue("RetransmissionQueue is not empty", empty); + GreetMe param = new GreetMe(); + param.setRequestType("testContextProperty"); + Object[] answer = client.invoke(boi, new Object[]{param}, invocationContext); + Assert.assertEquals("TESTCONTEXTPROPERTY", answer[0].toString()); + Thread.sleep(5000); + empty = manager.getRetransmissionQueue().isEmpty(); + assertTrue("RetransmissionQueue not empty", empty); + } + } http://git-wip-us.apache.org/repos/asf/cxf/blob/7c303899/systests/ws-rm/src/test/java/org/apache/cxf/systest/ws/rm/sec/client-policy.xml ---------------------------------------------------------------------- diff --git a/systests/ws-rm/src/test/java/org/apache/cxf/systest/ws/rm/sec/client-policy.xml b/systests/ws-rm/src/test/java/org/apache/cxf/systest/ws/rm/sec/client-policy.xml index c4a6083..0fcae05 100644 --- a/systests/ws-rm/src/test/java/org/apache/cxf/systest/ws/rm/sec/client-policy.xml +++ b/systests/ws-rm/src/test/java/org/apache/cxf/systest/ws/rm/sec/client-policy.xml @@ -60,6 +60,18 @@ under the License. <jaxws:client id="GreeterPlainClient" address="http://localhost:${testutil.ports.Server}/RMGreeterNoSecurity" serviceClass="org.apache.cxf.greeter_control.Greeter"> </jaxws:client> + <jaxws:client id="GreeterCombinedClientNoProperty" + address="http://localhost:${testutil.ports.Server}/RMGreeterAsymmetric" + serviceClass="org.apache.cxf.greeter_control.Greeter"> + <jaxws:features> + <p:policies> + <wsp:PolicyReference xmlns:wsp="http://www.w3.org/ns/ws-policy" + URI="#Combined" /> + </p:policies> + </jaxws:features> + </jaxws: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" wsu:Id="Combined"> <wsp:All> <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" wsu:Id="SEC">
