Author: coheigea
Date: Wed Jul 1 10:51:27 2009
New Revision: 790111
URL: http://svn.apache.org/viewvc?rev=790111&view=rev
Log:
[WSS-198] - Forward merged to trunk.
Modified:
webservices/wss4j/trunk/src/org/apache/ws/security/WSDataRef.java
webservices/wss4j/trunk/src/org/apache/ws/security/WSEncryptionPart.java
webservices/wss4j/trunk/src/org/apache/ws/security/processor/ReferenceListProcessor.java
webservices/wss4j/trunk/test/wssec/TestWSSecurityEncryptionParts.java
Modified: webservices/wss4j/trunk/src/org/apache/ws/security/WSDataRef.java
URL:
http://svn.apache.org/viewvc/webservices/wss4j/trunk/src/org/apache/ws/security/WSDataRef.java?rev=790111&r1=790110&r2=790111&view=diff
==============================================================================
--- webservices/wss4j/trunk/src/org/apache/ws/security/WSDataRef.java (original)
+++ webservices/wss4j/trunk/src/org/apache/ws/security/WSDataRef.java Wed Jul
1 10:51:27 2009
@@ -43,6 +43,13 @@
private QName name;
/**
+ * An xpath expression pointing to the data element
+ */
+ private String xpath;
+
+ private boolean content;
+
+ /**
* The protected DOM element
*/
private Element protectedElement;
@@ -101,5 +108,32 @@
return protectedElement;
}
+ /**
+ * @return the xpath
+ */
+ public String getXpath() {
+ return xpath;
+ }
+
+ /**
+ * @param xpath the xpath to set
+ */
+ public void setXpath(String xpath) {
+ this.xpath = xpath;
+ }
+
+ /**
+ * @return the content
+ */
+ public boolean isContent() {
+ return content;
+ }
+
+ /**
+ * @param content the content to set
+ */
+ public void setContent(boolean content) {
+ this.content = content;
+ }
}
Modified:
webservices/wss4j/trunk/src/org/apache/ws/security/WSEncryptionPart.java
URL:
http://svn.apache.org/viewvc/webservices/wss4j/trunk/src/org/apache/ws/security/WSEncryptionPart.java?rev=790111&r1=790110&r2=790111&view=diff
==============================================================================
--- webservices/wss4j/trunk/src/org/apache/ws/security/WSEncryptionPart.java
(original)
+++ webservices/wss4j/trunk/src/org/apache/ws/security/WSEncryptionPart.java
Wed Jul 1 10:51:27 2009
@@ -31,6 +31,13 @@
private String id;
/**
+ * An xpath expression pointing to the data element
+ * that may be specified in case the encryption part is of type
+ * <code>org.apache.ws.security.WSConstants.PART_TYPE_ELEMENT</code>
+ */
+ private String xpath;
+
+ /**
* Constructor to initialize part structure with element, namespace, and
modifier.
*
* This constructor initializes the parts structure to lookup for a
@@ -125,4 +132,18 @@
return encId;
}
+ /**
+ * @return the xpath
+ */
+ public String getXpath() {
+ return xpath;
+ }
+
+ /**
+ * @param xpath the xpath to set
+ */
+ public void setXpath(String xpath) {
+ this.xpath = xpath;
+ }
+
}
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=790111&r1=790110&r2=790111&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
Wed Jul 1 10:51:27 2009
@@ -43,6 +43,7 @@
import org.apache.ws.security.util.WSSecurityUtil;
import org.apache.xml.security.encryption.XMLCipher;
import org.apache.xml.security.encryption.XMLEncryptionException;
+import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
@@ -221,6 +222,8 @@
WSDataRef dataRef = new WSDataRef();
dataRef.setWsuId(dataRefURI);
boolean content = X509Util.isContent(encData);
+ dataRef.setContent(content);
+
Node parent = encData.getParentNode();
Node previousSibling = encData.getPreviousSibling();
if (content) {
@@ -242,8 +245,10 @@
parent.getParentNode().appendChild(decryptedHeaderClone);
parent.getParentNode().removeChild(parent);
dataRef.setProtectedElement(decryptedHeaderClone);
+ dataRef.setXpath(getXPath(decryptedHeader));
} else if (content) {
dataRef.setProtectedElement(encData);
+ dataRef.setXpath(getXPath(encData));
} else {
Node decryptedNode;
if (previousSibling == null) {
@@ -254,6 +259,7 @@
if (decryptedNode != null && Node.ELEMENT_NODE ==
decryptedNode.getNodeType()) {
dataRef.setProtectedElement((Element)decryptedNode);
}
+ dataRef.setXpath(getXPath(decryptedNode));
}
return dataRef;
@@ -369,4 +375,53 @@
return WSSecurityUtil.prepareSecretKey(algorithm, decryptedData);
}
+
+ /**
+ * @param decryptedNode the decrypted node
+ * @return a fully built xpath
+ * (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();
+ result = prependFullPath(result,
((Attr)decryptedNode).getOwnerElement());
+ } else {
+ return null;
+ }
+
+ return result;
+ }
+
+
+ /**
+ * Recursively build an absolute xpath (starting with the root
"/")
+ *
+ * @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/test/wssec/TestWSSecurityEncryptionParts.java
URL:
http://svn.apache.org/viewvc/webservices/wss4j/trunk/test/wssec/TestWSSecurityEncryptionParts.java?rev=790111&r1=790110&r2=790111&view=diff
==============================================================================
--- webservices/wss4j/trunk/test/wssec/TestWSSecurityEncryptionParts.java
(original)
+++ webservices/wss4j/trunk/test/wssec/TestWSSecurityEncryptionParts.java Wed
Jul 1 10:51:27 2009
@@ -25,15 +25,18 @@
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;
import org.apache.ws.security.message.WSSecEncrypt;
import org.apache.ws.security.message.WSSecHeader;
+import org.apache.ws.security.message.token.Timestamp;
import org.apache.ws.security.util.WSSecurityUtil;
import org.w3c.dom.Document;
@@ -133,6 +136,17 @@
} catch (WSSecurityException ex) {
// expected
}
+
+ WSSecurityEngineResult actionResult =
+ WSSecurityUtil.fetchActionResult(results, WSConstants.ENCR);
+ 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: [email protected]
For additional commands, e-mail: [email protected]