You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ws.apache.org by co...@apache.org on 2015/04/03 13:39:25 UTC

svn commit: r1671033 - in /webservices/wss4j/trunk: ws-security-dom/src/main/java/org/apache/wss4j/dom/ ws-security-dom/src/main/java/org/apache/wss4j/dom/handler/ ws-security-dom/src/main/java/org/apache/wss4j/dom/saml/ ws-security-dom/src/main/java/o...

Author: coheigea
Date: Fri Apr  3 11:39:25 2015
New Revision: 1671033

URL: http://svn.apache.org/r1671033
Log:
Removed methods to retrieve results via WSSecurityUtil

Modified:
    webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/wss4j/dom/WSSecurityEngine.java
    webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/wss4j/dom/handler/WSHandler.java
    webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/wss4j/dom/saml/DOMSAMLUtil.java
    webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/wss4j/dom/util/WSSecurityUtil.java
    webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/common/CustomHandler.java
    webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/handler/SignatureConfirmationTest.java
    webservices/wss4j/trunk/ws-security-stax/src/test/java/org/apache/wss4j/stax/test/AbstractTestBase.java

Modified: webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/wss4j/dom/WSSecurityEngine.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/wss4j/dom/WSSecurityEngine.java?rev=1671033&r1=1671032&r2=1671033&view=diff
==============================================================================
--- webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/wss4j/dom/WSSecurityEngine.java (original)
+++ webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/wss4j/dom/WSSecurityEngine.java Fri Apr  3 11:39:25 2015
@@ -453,15 +453,15 @@ public class WSSecurityEngine {
             }
         }
         
+        WSHandlerResult handlerResult = 
+            new WSHandlerResult(requestData.getActor(), returnResults, wsDocInfo.getActionResults());
+        
         // Validate SAML Subject Confirmation requirements
         if (wssConfig.isValidateSamlSubjectConfirmation()) {
             Element bodyElement = callbackLookupToUse.getSOAPBody();
-            DOMSAMLUtil.validateSAMLResults(returnResults, requestData.getTlsCerts(), bodyElement);
+            DOMSAMLUtil.validateSAMLResults(handlerResult, requestData.getTlsCerts(), bodyElement);
         }
         
-        WSHandlerResult handlerResult = 
-            new WSHandlerResult(requestData.getActor(), returnResults, wsDocInfo.getActionResults());
-        
         wsDocInfo.clear();
         
         return handlerResult;

Modified: webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/wss4j/dom/handler/WSHandler.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/wss4j/dom/handler/WSHandler.java?rev=1671033&r1=1671032&r2=1671033&view=diff
==============================================================================
--- webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/wss4j/dom/handler/WSHandler.java (original)
+++ webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/wss4j/dom/handler/WSHandler.java Fri Apr  3 11:39:25 2015
@@ -383,7 +383,7 @@ public abstract class WSHandler {
     @SuppressWarnings("unchecked")
     protected void checkSignatureConfirmation(
         RequestData reqData,
-        List<WSSecurityEngineResult> resultList
+        WSHandlerResult handlerResults
     ) throws WSSecurityException{
         if (doDebug) {
             LOG.debug("Check Signature confirmation");
@@ -399,7 +399,7 @@ public abstract class WSHandler {
         // have several security header blocks with different actors/roles)
         //
         List<WSSecurityEngineResult> sigConf = 
-            WSSecurityUtil.fetchAllActionResults(resultList, WSConstants.SC);
+            handlerResults.getActionResults().get(WSConstants.SC);
         //
         // now loop over all SignatureConfirmation results and check:
         // - if there is a signature value and no Signature value generated in request: error
@@ -407,35 +407,37 @@ public abstract class WSHandler {
         // 
         //  If a matching value found: remove from vector of stored signature values
         //
-        for (WSSecurityEngineResult result : sigConf) {
-            SignatureConfirmation sc = 
-                (SignatureConfirmation)result.get(
-                    WSSecurityEngineResult.TAG_SIGNATURE_CONFIRMATION
-                );
-
-            byte[] sigVal = sc.getSignatureValue();
-            if (sigVal != null) {
-                if (savedSignatures == null || savedSignatures.size() == 0) {
-                    //
-                    // If there are no stored signature values, and we've received a 
-                    // SignatureConfirmation element then throw an Exception
-                    //
-                    if (sigVal.length != 0) {
-                        throw new WSSecurityException(WSSecurityException.ErrorCode.INVALID_SECURITY, "empty",
-                                "Received a SignatureConfirmation element, but there are no stored"
-                             + " signature values"
-                        );
-                    }
-                } else {
-                    Integer hash = Arrays.hashCode(sigVal);
-                    if (savedSignatures.contains(hash)) {
-                        savedSignatures.remove(hash);
+        if (sigConf != null) {
+            for (WSSecurityEngineResult result : sigConf) {
+                SignatureConfirmation sc = 
+                    (SignatureConfirmation)result.get(
+                        WSSecurityEngineResult.TAG_SIGNATURE_CONFIRMATION
+                    );
+    
+                byte[] sigVal = sc.getSignatureValue();
+                if (sigVal != null) {
+                    if (savedSignatures == null || savedSignatures.size() == 0) {
+                        //
+                        // If there are no stored signature values, and we've received a 
+                        // SignatureConfirmation element then throw an Exception
+                        //
+                        if (sigVal.length != 0) {
+                            throw new WSSecurityException(WSSecurityException.ErrorCode.INVALID_SECURITY, "empty",
+                                    "Received a SignatureConfirmation element, but there are no stored"
+                                 + " signature values"
+                            );
+                        }
                     } else {
-                        throw new WSSecurityException(WSSecurityException.ErrorCode.FAILURE, "empty",
-                                "Received a SignatureConfirmation element, but there are no matching"
-                            + " stored signature values"
-                        );
-                    } 
+                        Integer hash = Arrays.hashCode(sigVal);
+                        if (savedSignatures.contains(hash)) {
+                            savedSignatures.remove(hash);
+                        } else {
+                            throw new WSSecurityException(WSSecurityException.ErrorCode.FAILURE, "empty",
+                                    "Received a SignatureConfirmation element, but there are no matching"
+                                + " stored signature values"
+                            );
+                        } 
+                    }
                 }
             }
         }

Modified: webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/wss4j/dom/saml/DOMSAMLUtil.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/wss4j/dom/saml/DOMSAMLUtil.java?rev=1671033&r1=1671032&r2=1671033&view=diff
==============================================================================
--- webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/wss4j/dom/saml/DOMSAMLUtil.java (original)
+++ webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/wss4j/dom/saml/DOMSAMLUtil.java Fri Apr  3 11:39:25 2015
@@ -35,7 +35,7 @@ import org.apache.wss4j.common.saml.Saml
 import org.apache.wss4j.dom.WSConstants;
 import org.apache.wss4j.dom.WSDataRef;
 import org.apache.wss4j.dom.WSSecurityEngineResult;
-import org.apache.wss4j.dom.util.WSSecurityUtil;
+import org.apache.wss4j.dom.handler.WSHandlerResult;
 import org.w3c.dom.Element;
 
 /**
@@ -51,25 +51,29 @@ public final class DOMSAMLUtil  {
     }
     
     public static void validateSAMLResults(
-        List<WSSecurityEngineResult> results,
+        WSHandlerResult handlerResults,
         Certificate[] tlsCerts,
         Element body
     ) throws WSSecurityException {
-        final List<Integer> samlActions = new ArrayList<>(2);
-        samlActions.add(WSConstants.ST_SIGNED);
-        samlActions.add(WSConstants.ST_UNSIGNED);
-        List<WSSecurityEngineResult> samlResults = 
-            WSSecurityUtil.fetchAllActionResults(results, samlActions);
+        List<WSSecurityEngineResult> samlResults = new ArrayList<>();
+        if (handlerResults.getActionResults().containsKey(WSConstants.ST_SIGNED)) {
+            samlResults.addAll(handlerResults.getActionResults().get(WSConstants.ST_SIGNED));
+        }
+        if (handlerResults.getActionResults().containsKey(WSConstants.ST_UNSIGNED)) {
+            samlResults.addAll(handlerResults.getActionResults().get(WSConstants.ST_UNSIGNED));
+        }
 
         if (samlResults.isEmpty()) {
             return;
         }
 
-        final List<Integer> signedActions = new ArrayList<>(2);
-        signedActions.add(WSConstants.SIGN);
-        signedActions.add(WSConstants.UT_SIGN);
-        List<WSSecurityEngineResult> signedResults = 
-            WSSecurityUtil.fetchAllActionResults(results, signedActions);
+        List<WSSecurityEngineResult> signedResults = new ArrayList<>();
+        if (handlerResults.getActionResults().containsKey(WSConstants.SIGN)) {
+            signedResults.addAll(handlerResults.getActionResults().get(WSConstants.SIGN));
+        }
+        if (handlerResults.getActionResults().containsKey(WSConstants.UT_SIGN)) {
+            signedResults.addAll(handlerResults.getActionResults().get(WSConstants.UT_SIGN));
+        }
 
         for (WSSecurityEngineResult samlResult : samlResults) {
             SamlAssertionWrapper assertionWrapper = 

Modified: webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/wss4j/dom/util/WSSecurityUtil.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/wss4j/dom/util/WSSecurityUtil.java?rev=1671033&r1=1671032&r2=1671033&view=diff
==============================================================================
--- webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/wss4j/dom/util/WSSecurityUtil.java (original)
+++ webservices/wss4j/trunk/ws-security-dom/src/main/java/org/apache/wss4j/dom/util/WSSecurityUtil.java Fri Apr  3 11:39:25 2015
@@ -384,81 +384,6 @@ public final class WSSecurityUtil {
         return getSOAPConstants(startElement).getEnvelopeURI();
     }
 
-    /**
-     * Fetch the result of a given action from a given result list
-     * 
-     * @param resultList The result list to fetch an action from
-     * @param action The action to fetch
-     * @return The last result fetched from the result list, null if the result
-     *         could not be found
-     */
-    public static WSSecurityEngineResult fetchActionResult(
-        List<WSSecurityEngineResult> resultList, 
-        int action
-    ) {
-        WSSecurityEngineResult returnResult = null;
-        
-        for (WSSecurityEngineResult result : resultList) {
-            //
-            // Check the result of every action whether it matches the given action
-            //
-            int resultAction =
-                    (Integer) result.get(WSSecurityEngineResult.TAG_ACTION);
-            if (resultAction == action) {
-                returnResult = result;
-            }
-        }
-
-        return returnResult;
-    }
-    
-    /**
-     * Fetch the result of a given action from a given result list.
-     * 
-     * @param resultList The result list to fetch an action from
-     * @param action The action to fetch
-     * @return The result fetched from the result list, null if the result
-     *         could not be found
-     */
-    public static List<WSSecurityEngineResult> fetchAllActionResults(
-        List<WSSecurityEngineResult> resultList,
-        int action
-    ) {
-        return fetchAllActionResults(resultList, Collections.singletonList(action));
-    }
-    
-    /**
-     * Fetch the results of a given number of actions action from a given result list.
-     * 
-     * @param resultList The result list to fetch an action from
-     * @param actions The list of actions to fetch
-     * @return The list of matching results fetched from the result list
-     */
-    public static List<WSSecurityEngineResult> fetchAllActionResults(
-        List<WSSecurityEngineResult> resultList,
-        List<Integer> actions
-    ) {
-        List<WSSecurityEngineResult> actionResultList = Collections.emptyList();
-        if (actions == null || actions.isEmpty()) {
-            return actionResultList;
-        }
-        
-        for (WSSecurityEngineResult result : resultList) {
-            //
-            // Check the result of every action whether it matches the given action
-            //
-            int resultAction =
-                    (Integer) result.get(WSSecurityEngineResult.TAG_ACTION);
-            if (actions.contains(resultAction)) {
-                if (actionResultList.isEmpty()) {
-                    actionResultList = new ArrayList<>();
-                }
-                actionResultList.add(result);
-            }
-        }
-        return actionResultList;
-    }
-
     public static List<Integer> decodeAction(String action) throws WSSecurityException {
         String actionToParse = action;
         if (actionToParse == null) {

Modified: webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/common/CustomHandler.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/common/CustomHandler.java?rev=1671033&r1=1671032&r2=1671033&view=diff
==============================================================================
--- webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/common/CustomHandler.java (original)
+++ webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/common/CustomHandler.java Fri Apr  3 11:39:25 2015
@@ -24,6 +24,7 @@ import org.apache.wss4j.common.ext.WSSec
 import org.apache.wss4j.dom.handler.HandlerAction;
 import org.apache.wss4j.dom.handler.WSHandler;
 import org.apache.wss4j.dom.handler.RequestData;
+import org.apache.wss4j.dom.handler.WSHandlerResult;
 import org.w3c.dom.Document;
 
 import java.util.HashMap;
@@ -104,9 +105,9 @@ public class CustomHandler extends WSHan
 
     public void signatureConfirmation(
         RequestData requestData,
-        List<WSSecurityEngineResult> results
+        WSHandlerResult handlerResults
     ) throws WSSecurityException {
-        checkSignatureConfirmation(requestData, results);
+        checkSignatureConfirmation(requestData, handlerResults);
     }
     
     public boolean checkResults(

Modified: webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/handler/SignatureConfirmationTest.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/handler/SignatureConfirmationTest.java?rev=1671033&r1=1671032&r2=1671033&view=diff
==============================================================================
--- webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/handler/SignatureConfirmationTest.java (original)
+++ webservices/wss4j/trunk/ws-security-dom/src/test/java/org/apache/wss4j/dom/handler/SignatureConfirmationTest.java Fri Apr  3 11:39:25 2015
@@ -268,7 +268,7 @@ public class SignatureConfirmationTest e
             results.getActionResults().get(WSConstants.SC).get(0);
         assertTrue(scResult != null);
         assertTrue(scResult.get(WSSecurityEngineResult.TAG_SIGNATURE_CONFIRMATION) != null);
-        handler.signatureConfirmation(reqData, results.getResults());
+        handler.signatureConfirmation(reqData, results);
     }
     
     

Modified: webservices/wss4j/trunk/ws-security-stax/src/test/java/org/apache/wss4j/stax/test/AbstractTestBase.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/ws-security-stax/src/test/java/org/apache/wss4j/stax/test/AbstractTestBase.java?rev=1671033&r1=1671032&r2=1671033&view=diff
==============================================================================
--- webservices/wss4j/trunk/ws-security-stax/src/test/java/org/apache/wss4j/stax/test/AbstractTestBase.java (original)
+++ webservices/wss4j/trunk/ws-security-stax/src/test/java/org/apache/wss4j/stax/test/AbstractTestBase.java Fri Apr  3 11:39:25 2015
@@ -515,7 +515,7 @@ public abstract class AbstractTestBase e
                 }
             }
             if (reqData.getWssConfig().isEnableSignatureConfirmation() && !isRequest) {
-                checkSignatureConfirmation(reqData, wsResult.getResults());
+                checkSignatureConfirmation(reqData, wsResult);
             }
 
             if (doDebug) {