cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cohei...@apache.org
Subject [3/3] cxf git commit: CXF-7220 - WS-Security StaX processing fails on whitespace after the SOAP Body opening tag
Date Fri, 20 Jan 2017 15:41:52 GMT
CXF-7220 - WS-Security StaX processing fails on whitespace after the SOAP Body opening tag


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/e0b8a8ad
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/e0b8a8ad
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/e0b8a8ad

Branch: refs/heads/3.1.x-fixes
Commit: e0b8a8ad939fcb63e405b7225a147e440da18289
Parents: 44879c4
Author: Colm O hEigeartaigh <coheigea@apache.org>
Authored: Fri Jan 20 15:41:03 2017 +0000
Committer: Colm O hEigeartaigh <coheigea@apache.org>
Committed: Fri Jan 20 15:41:44 2017 +0000

----------------------------------------------------------------------
 .../security/wss4j/WSS4JStaxInInterceptor.java  | 44 ++++++++++++++++++++
 .../ws/action/SignatureWhitespaceTest.java      | 37 +++++++++-------
 2 files changed, 67 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/e0b8a8ad/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/WSS4JStaxInInterceptor.java
----------------------------------------------------------------------
diff --git a/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/WSS4JStaxInInterceptor.java
b/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/WSS4JStaxInInterceptor.java
index b855505..a4ed602 100644
--- a/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/WSS4JStaxInInterceptor.java
+++ b/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/WSS4JStaxInInterceptor.java
@@ -32,6 +32,8 @@ import javax.xml.stream.util.StreamReaderDelegate;
 
 import org.apache.cxf.binding.soap.SoapFault;
 import org.apache.cxf.binding.soap.SoapMessage;
+import org.apache.cxf.binding.soap.interceptor.AbstractSoapInterceptor;
+import org.apache.cxf.binding.soap.interceptor.StartBodyInterceptor;
 import org.apache.cxf.common.classloader.ClassLoaderUtils;
 import org.apache.cxf.common.i18n.Message;
 import org.apache.cxf.common.logging.LogUtils;
@@ -96,6 +98,8 @@ public class WSS4JStaxInInterceptor extends AbstractWSS4JStaxInterceptor
{
         if (soapMessage.containsKey(SECURITY_PROCESSED) || isGET(soapMessage)) {
             return;
         }
+        
+        soapMessage.getInterceptorChain().add(new StaxStartBodyInterceptor());
 
         XMLStreamReader originalXmlStreamReader = soapMessage.getContent(XMLStreamReader.class);
         XMLStreamReader newXmlStreamReader;
@@ -421,5 +425,45 @@ public class WSS4JStaxInInterceptor extends AbstractWSS4JStaxInterceptor
{
             throw new WSSecurityException(WSSecurityException.ErrorCode.FAILURE, ex);
         }
     }
+    
+    /**
+     * This interceptor runs after the StartBodyInterceptor. It skips any white space after
the SOAP:Body start tag, 
+     * to make sure that the WSS4J OperationInputProcessor is triggered by the first SOAP
Body child (if it is not, 
+     * then WS-Security processing does not happen correctly).
+     */
+    private class StaxStartBodyInterceptor extends AbstractSoapInterceptor {
+        
+        StaxStartBodyInterceptor() {
+            super(Phase.READ);
+            super.addAfter(StartBodyInterceptor.class.getName());
+        }
+        
+        StaxStartBodyInterceptor(String phase) {
+            super(phase);
+        }
+
+        /** {@inheritDoc}*/
+        public void handleMessage(SoapMessage message) throws Fault {
+            if (isGET(message)) {
+                LOG.fine("StartBodyInterceptor skipped in HTTP GET method");
+                return;
+            }
+            XMLStreamReader xmlReader = message.getContent(XMLStreamReader.class);
+            try {
+                int i = xmlReader.getEventType();
+                while (i == XMLStreamReader.NAMESPACE
+                    || i == XMLStreamReader.ATTRIBUTE
+                    || i == XMLStreamReader.CHARACTERS) {
+                    i = xmlReader.next();
+                }
+            } catch (XMLStreamException e) {
+                throw new SoapFault(new Message("XML_STREAM_EXC", LOG, e.getMessage()), e,

+                                    message.getVersion().getSender());
+            }
+
+        }
+
+    }
+
 
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/e0b8a8ad/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/action/SignatureWhitespaceTest.java
----------------------------------------------------------------------
diff --git a/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/action/SignatureWhitespaceTest.java
b/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/action/SignatureWhitespaceTest.java
index 2f3cc43..bf768f4 100644
--- a/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/action/SignatureWhitespaceTest.java
+++ b/systests/ws-security/src/test/java/org/apache/cxf/systest/ws/action/SignatureWhitespaceTest.java
@@ -31,9 +31,13 @@ import javax.xml.ws.Service;
 
 import org.apache.cxf.Bus;
 import org.apache.cxf.bus.spring.SpringBusFactory;
+import org.apache.cxf.endpoint.Client;
+import org.apache.cxf.jaxws.DispatchImpl;
 import org.apache.cxf.systest.ws.common.SecurityTestUtil;
 import org.apache.cxf.systest.ws.common.TestParam;
 import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
+import org.apache.cxf.transport.http.HTTPConduit;
+import org.apache.cxf.transports.http.configuration.HTTPClientPolicy;
 import org.example.contract.doubleit.DoubleItPortType;
 import org.junit.BeforeClass;
 import org.junit.runner.RunWith;
@@ -49,6 +53,12 @@ public class SignatureWhitespaceTest extends AbstractBusClientServerTestBase
{
 
     private static final String NAMESPACE = "http://www.example.org/contract/DoubleIt";
     private static final QName SERVICE_QNAME = new QName(NAMESPACE, "DoubleItService");
+
+    final TestParam test;
+
+    public SignatureWhitespaceTest(TestParam type) {
+        this.test = type;
+    }
     
     @BeforeClass
     public static void startServers() throws Exception {
@@ -66,12 +76,6 @@ public class SignatureWhitespaceTest extends AbstractBusClientServerTestBase
{
         );
     }
     
-    final TestParam test;
-    
-    public SignatureWhitespaceTest(TestParam type) {
-        this.test = type;
-    }
-    
     @org.junit.AfterClass
     public static void cleanup() throws Exception {
         SecurityTestUtil.cleanup();
@@ -111,10 +115,7 @@ public class SignatureWhitespaceTest extends AbstractBusClientServerTestBase
{
     
     @org.junit.Test
     public void testTrailingWhitespaceInSOAPBody() throws Exception {
-        // TODO Bug
-        if (STAX_PORT.equals(test.getPort())) {
-            return;
-        }
+
         SpringBusFactory bf = new SpringBusFactory();
         URL busFile = SignatureWhitespaceTest.class.getResource("client.xml");
 
@@ -129,6 +130,16 @@ public class SignatureWhitespaceTest extends AbstractBusClientServerTestBase
{
         Dispatch<StreamSource> dispatch = 
             service.createDispatch(portQName, StreamSource.class, Service.Mode.MESSAGE);
         
+        Client client = ((DispatchImpl<StreamSource>) dispatch).getClient();
+
+        HTTPConduit http = (HTTPConduit) client.getConduit();
+
+        HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
+        httpClientPolicy.setConnectionTimeout(0);
+        httpClientPolicy.setReceiveTimeout(0);
+        http.setClient(httpClientPolicy);
+
+        
         // Creating a DOMSource Object for the request
         
         URL requestFile = 
@@ -145,10 +156,7 @@ public class SignatureWhitespaceTest extends AbstractBusClientServerTestBase
{
     
     @org.junit.Test
     public void testAddedCommentsInSOAPBody() throws Exception {
-        // TODO Bug
-        if (STAX_PORT.equals(test.getPort())) {
-            return;
-        }
+
         SpringBusFactory bf = new SpringBusFactory();
         URL busFile = SignatureWhitespaceTest.class.getResource("client.xml");
 
@@ -176,4 +184,5 @@ public class SignatureWhitespaceTest extends AbstractBusClientServerTestBase
{
         StreamSource response = dispatch.invoke(request);
         assertNotNull(response);
     }
+    
 }


Mime
View raw message