cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject [5/6] git commit: [CXF-5874] Add ability to turn on a strict Action checking
Date Fri, 11 Jul 2014 18:36:00 GMT
[CXF-5874] Add ability to turn on a strict Action checking

Conflicts:
	services/sts/systests/basic/src/test/java/org/apache/cxf/systest/sts/symmetric/SymmetricBindingTest.java


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

Branch: refs/heads/2.7.x-fixes
Commit: 7d7072dc78a35243adde9ad7caf43ccdcebcff1b
Parents: 06203d8
Author: Daniel Kulp <dkulp@apache.org>
Authored: Fri Jul 11 14:03:24 2014 -0400
Committer: Daniel Kulp <dkulp@apache.org>
Committed: Fri Jul 11 14:34:57 2014 -0400

----------------------------------------------------------------------
 .../interceptor/SoapActionInInterceptor.java    | 98 +++++++++++++++-----
 .../apache/cxf/ws/addressing/soap/MAPCodec.java |  5 +-
 2 files changed, 81 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/7d7072dc/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/SoapActionInInterceptor.java
----------------------------------------------------------------------
diff --git a/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/SoapActionInInterceptor.java
b/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/SoapActionInInterceptor.java
index b1a3cce..00be38c 100644
--- a/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/SoapActionInInterceptor.java
+++ b/rt/bindings/soap/src/main/java/org/apache/cxf/binding/soap/interceptor/SoapActionInInterceptor.java
@@ -46,6 +46,7 @@ public class SoapActionInInterceptor extends AbstractSoapInterceptor {
     
     private static final Logger LOG = LogUtils.getL7dLogger(SoapActionInInterceptor.class);
     private static final String ALLOW_NON_MATCHING_TO_DEFAULT = "allowNonMatchingToDefaultSoapAction";
+    private static final String CALCULATED_WSA_ACTION = SoapActionInInterceptor.class.getName()
+ ".ACTION";
     
     public SoapActionInInterceptor() {
         super(Phase.READ);
@@ -110,6 +111,9 @@ public class SoapActionInInterceptor extends AbstractSoapInterceptor {
     }
     
     public static void getAndSetOperation(SoapMessage message, String action) {
+        getAndSetOperation(message, action, true);
+    }
+    public static void getAndSetOperation(SoapMessage message, String action, boolean strict)
{
         if (StringUtils.isEmpty(action)) {
             return;
         }
@@ -133,11 +137,7 @@ public class SoapActionInInterceptor extends AbstractSoapInterceptor
{
                     }
                     bindingOp = boi;
                 }
-                Object o = boi.getOperationInfo().getInput().getExtensionAttribute(JAXWSAConstants.WSAM_ACTION_QNAME);
-                if (o == null) {
-                    o = boi.getOperationInfo().getInput().getExtensionAttribute(JAXWSAConstants.WSAW_ACTION_QNAME);
-                }
-                if (o != null && action.equals(o.toString())) {
+                if (matchWSAAction(boi, action)) {
                     if (bindingOp != null && bindingOp != boi) {
                         //more than one op with the same action, will need to parse normally
                         return;
@@ -148,44 +148,100 @@ public class SoapActionInInterceptor extends AbstractSoapInterceptor
{
         }
         
         if (bindingOp == null) {
-            //we didn't match the an operation, we'll try again later to make
-            //sure the incoming message did end up matching an operation.
-            //This could occur in some cases like WS-RM and WS-SecConv that will
-            //intercept the message with a new endpoint/operation
-            message.getInterceptorChain().add(new SoapActionInAttemptTwoInterceptor());
+            if (strict) {
+                //we didn't match the an operation, we'll try again later to make
+                //sure the incoming message did end up matching an operation.
+                //This could occur in some cases like WS-RM and WS-SecConv that will
+                //intercept the message with a new endpoint/operation
+                message.getInterceptorChain().add(new SoapActionInAttemptTwoInterceptor(action));
+            }
             return;
         }
         
         ex.put(BindingOperationInfo.class, bindingOp);
         ex.put(OperationInfo.class, bindingOp.getOperationInfo());
     }
+    private static boolean matchWSAAction(BindingOperationInfo boi, String action) {
+        Object o = getWSAAction(boi);
+        if (o != null) {
+            String oa = o.toString();
+            if (action.equals(oa)
+                || action.equals(oa + "Request")
+                || oa.equals(action + "Request")) {
+                return true;
+            }
+        }
+        return false;
+    }
+    
+    private static String getWSAAction(BindingOperationInfo boi) {
+        Object o = boi.getOperationInfo().getInput().getProperty(CALCULATED_WSA_ACTION);
+        if (o == null) {
+            o = boi.getOperationInfo().getInput().getExtensionAttribute(JAXWSAConstants.WSAM_ACTION_QNAME);
+            if (o == null) {
+                o = boi.getOperationInfo().getInput().getExtensionAttribute(JAXWSAConstants.WSAW_ACTION_QNAME);
+            }
+            if (o == null) {
+                String start = getActionBaseUri(boi.getOperationInfo());
+                if (null == boi.getOperationInfo().getInputName()) {
+                    o = addPath(start, boi.getOperationInfo().getName().getLocalPart());
+                } else {
+                    o = addPath(start, boi.getOperationInfo().getInputName());
+                }
+            }
+            if (o != null) {
+                boi.getOperationInfo().getInput().setProperty(CALCULATED_WSA_ACTION, o);
+            }
+        }
+        return o == null ? null : o.toString();
+    }
+    private static String getActionBaseUri(final OperationInfo operation) {
+        String interfaceName = operation.getInterface().getName().getLocalPart();
+        return addPath(operation.getName().getNamespaceURI(), interfaceName);
+    }
+    private static String getDelimiter(String uri) {
+        if (uri.startsWith("urn")) {
+            return ":";
+        }
+        return "/";
+    }
+
+    private static String addPath(String uri, String path) {
+        StringBuilder buffer = new StringBuilder();
+        buffer.append(uri);
+        String delimiter = getDelimiter(uri);
+        if (!uri.endsWith(delimiter) && !path.startsWith(delimiter)) {
+            buffer.append(delimiter);
+        }
+        buffer.append(path);
+        return buffer.toString();
+    }
+
     
     public static class SoapActionInAttemptTwoInterceptor extends AbstractSoapInterceptor
{
-        public SoapActionInAttemptTwoInterceptor() {
-            super(Phase.PRE_LOGICAL);
+        final String action;
+        public SoapActionInAttemptTwoInterceptor(String action) {
+            super(action, Phase.PRE_LOGICAL);
+            this.action = action;
         }
         public void handleMessage(SoapMessage message) throws Fault {
             BindingOperationInfo boi = message.getExchange().getBindingOperationInfo();
             if (boi == null) {
                 return;
             }
-            String action = getSoapAction(message);
             if (StringUtils.isEmpty(action)) {
                 return;
             }
             if (isActionMatch(message, boi, action)) {
                 return;
             }
-
-            Object o = boi.getOperationInfo().getInput().getExtensionAttribute(JAXWSAConstants.WSAM_ACTION_QNAME);
-            if (o == null) {
-                o = boi.getOperationInfo().getInput().getExtensionAttribute(JAXWSAConstants.WSAW_ACTION_QNAME);
-            }
-            if (o != null && action.equals(o.toString())) {
+            if (matchWSAAction(boi, action)) {
                 return;
             }
-            
-            throw new Fault("SOAP_ACTION_MISMATCH", LOG, null, action);
+            boolean synthetic = Boolean.TRUE.equals(boi.getProperty("operation.is.synthetic"));
+            if (!synthetic) {
+                throw new Fault("SOAP_ACTION_MISMATCH", LOG, null, action);
+            }
         }
     }
 

http://git-wip-us.apache.org/repos/asf/cxf/blob/7d7072dc/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/soap/MAPCodec.java
----------------------------------------------------------------------
diff --git a/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/soap/MAPCodec.java b/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/soap/MAPCodec.java
index eebd53b..9bd9ad8 100644
--- a/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/soap/MAPCodec.java
+++ b/rt/ws/addr/src/main/java/org/apache/cxf/ws/addressing/soap/MAPCodec.java
@@ -182,7 +182,10 @@ public class MAPCodec extends AbstractSoapInterceptor {
                     //try and use the Action from the maps to find the operation
                     String action = maps.getAction().getValue();
                     if (action != null) {
-                        SoapActionInInterceptor.getAndSetOperation(message, action);
+                        boolean strict = MessageUtils.getContextualBoolean(message, 
+                                                                           "ws-addressing.strict.action.checking",

+                                                                           false);
+                        SoapActionInInterceptor.getAndSetOperation(message, action, strict);
                     }
                 }
             }


Mime
View raw message