Author: ay Date: Sun Sep 16 13:51:09 2012 New Revision: 1385266 URL: http://svn.apache.org/viewvc?rev=1385266&view=rev Log: Merged revisions 1385256 via svn merge from https://svn.apache.org/repos/asf/cxf/branches/2.6.x-fixes
........ r1385256 | ay | 2012-09-16 14:51:32 +0200 (Sun, 16 Sep 2012) | 9 lines Merged revisions 1384844 via svn merge from https://svn.apache.org/repos/asf/cxf/trunk ........ r1384844 | ay | 2012-09-14 18:47:42 +0200 (Fri, 14 Sep 2012) | 1 line [CXF-4505] Invalid WS-RM messages may not be rejected by WS-RM destination ........ ........ Modified: cxf/branches/2.5.x-fixes/ (props changed) cxf/branches/2.5.x-fixes/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/Messages.properties cxf/branches/2.5.x-fixes/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/RMInInterceptor.java cxf/branches/2.5.x-fixes/rt/ws/rm/src/test/java/org/apache/cxf/ws/rm/RMInInterceptorTest.java cxf/branches/2.5.x-fixes/systests/ws-rm/src/test/java/org/apache/cxf/systest/ws/rm/ProtocolVariationsTest.java Propchange: cxf/branches/2.5.x-fixes/ ('svn:mergeinfo' removed) Propchange: cxf/branches/2.5.x-fixes/ ------------------------------------------------------------------------------ Binary property 'svnmerge-integrated' - no diff available. Modified: cxf/branches/2.5.x-fixes/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/Messages.properties URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/Messages.properties?rev=1385266&r1=1385265&r2=1385266&view=diff ============================================================================== --- cxf/branches/2.5.x-fixes/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/Messages.properties (original) +++ cxf/branches/2.5.x-fixes/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/Messages.properties Sun Sep 16 13:51:09 2012 @@ -37,6 +37,7 @@ INVALID_ACK_EXC = The SequenceAcknowledg MESSAGE_NR_ROLLOVER_EXC = The maximum value for wsrm:MessageNumber has been exceeded. SEQUENCE_CLOSED_EXC = The Sequence has been closed. WSRM_REQUIRED_EXC = WS-ReliableMessaging is required by this endpoint. +WSA_REQUIRED_EXC = WS-Addressing is required by this endpoint. UNSUPPORTED_NAMESPACE = WS-Addressing namespace {0} is not supported with WS-ReliableMessaging namespace {1}. CREATE_SEQ_REFUSED = The create sequence request has been refused by the RM destination. CREATE_SEQ_ANON_TARGET = It is not possible to send a create sequence request to the anonymous address {0} Modified: cxf/branches/2.5.x-fixes/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/RMInInterceptor.java URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/RMInInterceptor.java?rev=1385266&r1=1385265&r2=1385266&view=diff ============================================================================== --- cxf/branches/2.5.x-fixes/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/RMInInterceptor.java (original) +++ cxf/branches/2.5.x-fixes/rt/ws/rm/src/main/java/org/apache/cxf/ws/rm/RMInInterceptor.java Sun Sep 16 13:51:09 2012 @@ -61,13 +61,23 @@ public class RMInInterceptor extends Abs protected void handle(Message message) throws SequenceFault, RMException { LOG.entering(getClass().getName(), "handleMessage"); + boolean isServer = RMContextUtils.isServerSide(message); + LOG.fine("isServerSide: " + isServer); + RMProperties rmps = RMContextUtils.retrieveRMProperties(message, false); // message addressing properties may be null, e.g. in case of a runtime fault // on the server side final AddressingProperties maps = ContextUtils.retrieveMAPs(message, false, false, false); if (null == maps) { - return; + if (isServer) { + org.apache.cxf.common.i18n.Message msg = new org.apache.cxf.common.i18n.Message( + "WSA_REQUIRED_EXC", LOG); + LOG.log(Level.INFO, msg.toString()); + throw new RMException(msg); + } else { + return; + } } String action = null; @@ -84,13 +94,23 @@ public class RMInInterceptor extends Abs LOG.fine("Restoring original requestor role to: " + originalRequestor); message.put(Message.REQUESTOR_ROLE, originalRequestor); } + + // get the wsa and wsrm namespaces from the message + String rmUri = rmps.getNamespaceURI(); + String addrUri = maps.getNamespaceURI(); + + ProtocolVariation protocol = ProtocolVariation.findVariant(rmUri, addrUri); + if (null == protocol) { + org.apache.cxf.common.i18n.Message msg = new org.apache.cxf.common.i18n.Message( + "WSRM_REQUIRED_EXC", LOG, rmUri, addrUri); + LOG.log(Level.INFO, msg.toString()); + throw new RMException(msg); + } // Destination destination = getManager().getDestination(message); // RMEndpoint rme = getManager().getReliableEndpoint(message); // Servant servant = new Servant(rme); - boolean isServer = RMContextUtils.isServerSide(message); - LOG.fine("isServerSide: " + isServer); boolean isApplicationMessage = !RMContextUtils.isRMProtocolMessage(action); LOG.fine("isApplicationMessage: " + isApplicationMessage); @@ -165,7 +185,7 @@ public class RMInInterceptor extends Abs if (robust) { // set this property to change the acknlowledging behavior message.put(RMMessageConstants.DELIVERING_ROBUST_ONEWAY, Boolean.TRUE); - } + } destination.acknowledge(message); } Modified: cxf/branches/2.5.x-fixes/rt/ws/rm/src/test/java/org/apache/cxf/ws/rm/RMInInterceptorTest.java URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/rt/ws/rm/src/test/java/org/apache/cxf/ws/rm/RMInInterceptorTest.java?rev=1385266&r1=1385265&r2=1385266&view=diff ============================================================================== --- cxf/branches/2.5.x-fixes/rt/ws/rm/src/test/java/org/apache/cxf/ws/rm/RMInInterceptorTest.java (original) +++ cxf/branches/2.5.x-fixes/rt/ws/rm/src/test/java/org/apache/cxf/ws/rm/RMInInterceptorTest.java Sun Sep 16 13:51:09 2012 @@ -36,6 +36,7 @@ import org.apache.cxf.ws.addressing.Addr import org.apache.cxf.ws.addressing.AttributedURIType; import org.apache.cxf.ws.addressing.JAXWSAConstants; import org.apache.cxf.ws.addressing.MAPAggregator; +import org.apache.cxf.ws.addressing.VersionTransformer.Names200408; import org.apache.cxf.ws.policy.AssertionInfoMap; import org.apache.cxf.ws.rm.v200702.CreateSequenceResponseType; import org.apache.cxf.ws.rm.v200702.Identifier; @@ -293,6 +294,7 @@ public class RMInInterceptorTest extends EasyMock.expect(message.get(Message.REQUESTOR_ROLE)).andReturn(!serverSide); AddressingPropertiesImpl maps = control.createMock(AddressingPropertiesImpl.class); + EasyMock.expect(maps.getNamespaceURI()).andReturn(Names200408.WSA_NAMESPACE_NAME).anyTimes(); EasyMock.expect(message.get(JAXWSAConstants.SERVER_ADDRESSING_PROPERTIES_INBOUND)).andReturn(maps); AttributedURIType actionURI = control.createMock(AttributedURIType.class); @@ -307,9 +309,16 @@ public class RMInInterceptorTest extends EasyMock.expect(exchange.getDestination()).andReturn(td); manager = control.createMock(RMManager.class); + EasyMock.expect(manager.getRMNamespace(EasyMock.same(message))) + .andReturn(RM10Constants.NAMESPACE_URI).anyTimes(); + EasyMock.expect(manager.getAddressingNamespace(EasyMock.same(message))) + .andReturn(Names200408.WSA_NAMESPACE_NAME).anyTimes(); interceptor.setManager(manager); rme = control.createMock(RMEndpoint.class); EasyMock.expect(manager.getReliableEndpoint(message)).andReturn(rme); + + EasyMock.expect(rmps.getNamespaceURI()).andReturn(RM10Constants.NAMESPACE_URI).anyTimes(); + return message; } -} \ No newline at end of file +} Modified: cxf/branches/2.5.x-fixes/systests/ws-rm/src/test/java/org/apache/cxf/systest/ws/rm/ProtocolVariationsTest.java URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/systests/ws-rm/src/test/java/org/apache/cxf/systest/ws/rm/ProtocolVariationsTest.java?rev=1385266&r1=1385265&r2=1385266&view=diff ============================================================================== --- cxf/branches/2.5.x-fixes/systests/ws-rm/src/test/java/org/apache/cxf/systest/ws/rm/ProtocolVariationsTest.java (original) +++ cxf/branches/2.5.x-fixes/systests/ws-rm/src/test/java/org/apache/cxf/systest/ws/rm/ProtocolVariationsTest.java Sun Sep 16 13:51:09 2012 @@ -19,6 +19,8 @@ package org.apache.cxf.systest.ws.rm; +import java.util.HashMap; +import java.util.Map; import java.util.concurrent.Executor; import java.util.logging.Logger; @@ -28,6 +30,7 @@ import javax.xml.ws.Endpoint; import org.apache.cxf.Bus; import org.apache.cxf.BusFactory; +import org.apache.cxf.binding.soap.SoapFault; import org.apache.cxf.bus.spring.SpringBusFactory; import org.apache.cxf.common.logging.LogUtils; import org.apache.cxf.endpoint.Client; @@ -36,6 +39,7 @@ import org.apache.cxf.greeter_control.Co import org.apache.cxf.greeter_control.ControlService; import org.apache.cxf.greeter_control.Greeter; import org.apache.cxf.greeter_control.GreeterService; +import org.apache.cxf.interceptor.transform.TransformOutInterceptor; import org.apache.cxf.jaxws.DispatchImpl; import org.apache.cxf.systest.ws.util.ConnectionHelper; import org.apache.cxf.systest.ws.util.MessageFlow; @@ -192,19 +196,106 @@ public class ProtocolVariationsTest exte try { greeter.greetMe("one"); - fail("invalid namespace combination"); + fail("invalid namespace combination accepted"); } catch (Exception e) { assertTrue(e.getCause() instanceof RMException); // verify a partial error text match to exclude an unexpected exception // (see UNSUPPORTED_NAMESPACE in Messages.properties) final String text = Names200408.WSA_NAMESPACE_NAME + " is not supported"; assertTrue(e.getCause().getMessage() != null - && e.getCause().getMessage().indexOf(text) > 0); + && e.getCause().getMessage().indexOf(text) >= 0); } } @Test + public void testInvalidRM11WSA200408OnReceive() throws Exception { + init("org/apache/cxf/systest/ws/rm/rminterceptors.xml", false); + + // WS-RM 1.0 using the WS-A 1.0 namespace + Client client = ClientProxy.getClient(greeter); + client.getRequestContext().put(RMManager.WSRM_VERSION_PROPERTY, RM10Constants.NAMESPACE_URI); + client.getRequestContext().put(RMManager.WSRM_WSA_VERSION_PROPERTY, Names200408.WSA_NAMESPACE_NAME); + + // rewrite the outgoing message's WS-RM namespace to 1.1 + TransformOutInterceptor trans = new TransformOutInterceptor(); + Map<String, String> outElements = new HashMap<String, String>(); + outElements.put("{" + RM10Constants.NAMESPACE_URI + "}*", "{" + RM11Constants.NAMESPACE_URI + "}*"); + trans.setOutTransformElements(outElements); + + client.getOutInterceptors().add(trans); + try { + greeter.greetMe("one"); + fail("invalid namespace combination accepted"); + } catch (Exception e) { + assertTrue(e.getCause() instanceof SoapFault); + // verify a partial error text match to exclude an unexpected exception + // (see WSRM_REQUIRED_EXC in Messages.properties) + final String text = "WS-ReliableMessaging is required"; + assertTrue(e.getCause().getMessage() != null + && e.getCause().getMessage().indexOf(text) >= 0); + } + } + + @Test + public void testInvalidWSAOnReceive() throws Exception { + init("org/apache/cxf/systest/ws/rm/rminterceptors.xml", false); + + // WS-RM 1.0 using the WS-A 1.0 namespace + Client client = ClientProxy.getClient(greeter); + client.getRequestContext().put(RMManager.WSRM_VERSION_PROPERTY, RM10Constants.NAMESPACE_URI); + client.getRequestContext().put(RMManager.WSRM_WSA_VERSION_PROPERTY, Names200408.WSA_NAMESPACE_NAME); + + // rewrite the outgoing message's WS-A namespace to an invalid one + TransformOutInterceptor trans = new TransformOutInterceptor(); + Map<String, String> outElements = new HashMap<String, String>(); + outElements.put("{" + Names200408.WSA_NAMESPACE_NAME + "}*", "{http://cxf.apache.org/invalid}*"); + trans.setOutTransformElements(outElements); + + client.getOutInterceptors().add(trans); + try { + greeter.greetMe("one"); + fail("invalid wsa header accepted"); + } catch (Exception e) { + assertTrue(e.getCause() instanceof SoapFault); + // verify a partial error text match to exclude an unexpected exception + // (see WSA_REQUIRED_EXC in Messages.properties) + final String text = "WS-Addressing is required"; + assertTrue(e.getCause().getMessage() != null + && e.getCause().getMessage().indexOf(text) >= 0); + } + } + + @Test + public void testInvalidWRMOnReceive() throws Exception { + init("org/apache/cxf/systest/ws/rm/rminterceptors.xml", false); + + // WS-RM 1.0 using the WS-A 1.0 namespace + Client client = ClientProxy.getClient(greeter); + client.getRequestContext().put(RMManager.WSRM_VERSION_PROPERTY, RM10Constants.NAMESPACE_URI); + client.getRequestContext().put(RMManager.WSRM_WSA_VERSION_PROPERTY, Names200408.WSA_NAMESPACE_NAME); + + // rewrite the outgoing message's WS-RM namespace to an invalid one + TransformOutInterceptor trans = new TransformOutInterceptor(); + Map<String, String> outElements = new HashMap<String, String>(); + outElements.put("{" + RM10Constants.NAMESPACE_URI + "}*", "{http://cxf.apache.org/invalid}*"); + trans.setOutTransformElements(outElements); + + client.getOutInterceptors().add(trans); + try { + greeter.greetMe("one"); + fail("invalid wsrm header"); + } catch (Exception e) { + assertTrue(e.getCause() instanceof SoapFault); + // verify a partial error text match to exclude an unexpected exception + // (see WSRM_REQUIRED_EXC in Messages.properties) + final String text = "WS-ReliableMessaging is required"; + assertTrue(e.getCause().getMessage() != null + && e.getCause().getMessage().indexOf(text) >= 0); + } + } + + @Test public void testDefaultDecoupled() throws Exception { init("org/apache/cxf/systest/ws/rm/rminterceptors.xml", true);
