You are viewing a plain text version of this content. The canonical link for it is here.
Posted to wss4j-dev@ws.apache.org by co...@apache.org on 2009/07/09 13:31:58 UTC

svn commit: r792505 - in /webservices/wss4j/trunk: src/org/apache/ws/security/processor/ReferenceListProcessor.java src/org/apache/ws/security/processor/SignatureProcessor.java test/wssec/TestWSSecuritySignatureParts.java

Author: coheigea
Date: Thu Jul  9 11:31:58 2009
New Revision: 792505

URL: http://svn.apache.org/viewvc?rev=792505&view=rev
Log:
[WSS-198] - Updated SignatureProcessor to store an xpath expression to the signed element, as well as the signed element.
 - Removed some tabs that crept in the last commit

Modified:
    webservices/wss4j/trunk/src/org/apache/ws/security/processor/ReferenceListProcessor.java
    webservices/wss4j/trunk/src/org/apache/ws/security/processor/SignatureProcessor.java
    webservices/wss4j/trunk/test/wssec/TestWSSecuritySignatureParts.java

Modified: webservices/wss4j/trunk/src/org/apache/ws/security/processor/ReferenceListProcessor.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/src/org/apache/ws/security/processor/ReferenceListProcessor.java?rev=792505&r1=792504&r2=792505&view=diff
==============================================================================
--- webservices/wss4j/trunk/src/org/apache/ws/security/processor/ReferenceListProcessor.java (original)
+++ webservices/wss4j/trunk/src/org/apache/ws/security/processor/ReferenceListProcessor.java Thu Jul  9 11:31:58 2009
@@ -382,46 +382,46 @@
      *        (eg. "/soapenv:Envelope/soapenv:Body/ns:decryptedElement")
      *        if the decryptedNode is an Element or an Attr node and is not detached
      *        from the document. <code>null</code> otherwise
-	 */
-	private static String getXPath(Node decryptedNode) {
-	    if (decryptedNode == null) {
-	        return null;
-	    }
-	    
-	    String result = "";
-	    if (Node.ELEMENT_NODE == decryptedNode.getNodeType()) {
-	        result = decryptedNode.getNodeName();
-	        result = prependFullPath(result, decryptedNode.getParentNode());
-	    } else if (Node.ATTRIBUTE_NODE == decryptedNode.getNodeType()) {
-	        result = "@" + decryptedNode.getNodeName();
+     */
+    public static String getXPath(Node decryptedNode) {
+        if (decryptedNode == null) {
+            return null;
+        }
+        
+        String result = "";
+        if (Node.ELEMENT_NODE == decryptedNode.getNodeType()) {
+            result = decryptedNode.getNodeName();
+            result = prependFullPath(result, decryptedNode.getParentNode());
+        } else if (Node.ATTRIBUTE_NODE == decryptedNode.getNodeType()) {
+            result = "@" + decryptedNode.getNodeName();
             result = prependFullPath(result, ((Attr)decryptedNode).getOwnerElement());
-	    } else {
-	        return null;
-	    }
-	    
-	    return result;
-	}
-	
-	
-	/**
-	 * Recursively build an absolute xpath (starting with the root &quot;/&quot;)
-	 * 
-	 * @param xpath the xpath expression built so far
-	 * @param node the current node whose name is to be prepended
-	 * @return a fully built xpath
-	 */
-	private static String prependFullPath(String xpath, Node node) {
-	    if (node == null) {
-	        // probably a detached node... not really useful
-	        return null;
-	    } else if (Node.ELEMENT_NODE == node.getNodeType()) {
-	        xpath = node.getNodeName() + "/" + xpath;
-	        return prependFullPath(xpath, node.getParentNode());
-	    } else if (Node.DOCUMENT_NODE == node.getNodeType()) {
-	        return "/" + xpath;
-	    } else {
-	        return prependFullPath(xpath, node.getParentNode());
-	    }
-	}
-	
+        } else {
+            return null;
+        }
+        
+        return result;
+    }
+
+
+    /**
+     * Recursively build an absolute xpath (starting with the root &quot;/&quot;)
+     * 
+     * @param xpath the xpath expression built so far
+     * @param node the current node whose name is to be prepended
+     * @return a fully built xpath
+     */
+    private static String prependFullPath(String xpath, Node node) {
+        if (node == null) {
+            // probably a detached node... not really useful
+            return null;
+        } else if (Node.ELEMENT_NODE == node.getNodeType()) {
+            xpath = node.getNodeName() + "/" + xpath;
+            return prependFullPath(xpath, node.getParentNode());
+        } else if (Node.DOCUMENT_NODE == node.getNodeType()) {
+            return "/" + xpath;
+        } else {
+            return prependFullPath(xpath, node.getParentNode());
+        }
+    }
+
 }

Modified: webservices/wss4j/trunk/src/org/apache/ws/security/processor/SignatureProcessor.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/src/org/apache/ws/security/processor/SignatureProcessor.java?rev=792505&r1=792504&r2=792505&view=diff
==============================================================================
--- webservices/wss4j/trunk/src/org/apache/ws/security/processor/SignatureProcessor.java (original)
+++ webservices/wss4j/trunk/src/org/apache/ws/security/processor/SignatureProcessor.java Thu Jul  9 11:31:58 2009
@@ -678,6 +678,7 @@
                 WSDataRef ref = new WSDataRef();
                 ref.setWsuId(uri);
                 ref.setProtectedElement(se);
+                ref.setXpath(ReferenceListProcessor.getXPath(se));
                 protectedRefs.add(ref);
             }
         }

Modified: webservices/wss4j/trunk/test/wssec/TestWSSecuritySignatureParts.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/trunk/test/wssec/TestWSSecuritySignatureParts.java?rev=792505&r1=792504&r2=792505&view=diff
==============================================================================
--- webservices/wss4j/trunk/test/wssec/TestWSSecuritySignatureParts.java (original)
+++ webservices/wss4j/trunk/test/wssec/TestWSSecuritySignatureParts.java Thu Jul  9 11:31:58 2009
@@ -25,10 +25,12 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.ws.security.SOAPConstants;
+import org.apache.ws.security.WSDataRef;
 import org.apache.ws.security.WSEncryptionPart;
 import org.apache.ws.security.WSPasswordCallback;
 import org.apache.ws.security.WSSecurityEngine;
 import org.apache.ws.security.WSConstants;
+import org.apache.ws.security.WSSecurityEngineResult;
 import org.apache.ws.security.WSSecurityException;
 import org.apache.ws.security.components.crypto.Crypto;
 import org.apache.ws.security.components.crypto.CryptoFactory;
@@ -132,6 +134,16 @@
         } catch (WSSecurityException ex) {
             // expected
         }
+        
+        WSSecurityEngineResult actionResult = 
+            WSSecurityUtil.fetchActionResult(results, WSConstants.SIGN);
+        assertTrue(actionResult != null);
+        final java.util.List refs =
+            (java.util.List) actionResult.get(WSSecurityEngineResult.TAG_DATA_REF_URIS);
+        assertTrue(actionResult != null && !actionResult.isEmpty());
+        WSDataRef wsDataRef = (WSDataRef)refs.get(0);
+        String xpath = wsDataRef.getXpath();
+        assertEquals("/soapenv:Envelope/soapenv:Header/foo:foobar", xpath);
     }
     
     /**



---------------------------------------------------------------------
To unsubscribe, e-mail: wss4j-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: wss4j-dev-help@ws.apache.org