This is an automated email from the ASF dual-hosted git repository.

coheigea pushed a commit to branch coheigea/saml-refactor-new
in repository https://gitbox.apache.org/repos/asf/ws-wss4j.git


The following commit(s) were added to refs/heads/coheigea/saml-refactor-new by 
this push:
     new 828baf59d Moving XPath stuff to XMLUtils
828baf59d is described below

commit 828baf59d2b34d1c4c2f7a73aca1818fafaf858e
Author: Colm O hEigeartaigh <[email protected]>
AuthorDate: Mon Jun 23 15:42:17 2025 +0100

    Moving XPath stuff to XMLUtils
---
 .../org/apache/wss4j/common/util/XMLUtils.java     | 48 +++++++++++++++++++
 .../wss4j/dom/processor/SAMLTokenProcessor.java    |  4 +-
 .../wss4j/dom/processor/SignatureProcessor.java    |  3 +-
 .../org/apache/wss4j/dom/util/EncryptionUtils.java | 55 ++--------------------
 4 files changed, 54 insertions(+), 56 deletions(-)

diff --git 
a/ws-security-common/src/main/java/org/apache/wss4j/common/util/XMLUtils.java 
b/ws-security-common/src/main/java/org/apache/wss4j/common/util/XMLUtils.java
index ad9bb5e03..a62f5bb09 100644
--- 
a/ws-security-common/src/main/java/org/apache/wss4j/common/util/XMLUtils.java
+++ 
b/ws-security-common/src/main/java/org/apache/wss4j/common/util/XMLUtils.java
@@ -871,4 +871,52 @@ public final class XMLUtils {
         String ns = docElement.getNamespaceURI();
         return XMLUtils.getDirectChildElement(docElement, 
WSS4JConstants.ELEM_BODY, ns);
     }
+
+    /**
+     * @param decryptedNode the decrypted node
+     * @return a fully built xpath
+     *        (eg. 
&quot;/soapenv:Envelope/soapenv:Body/ns:decryptedElement&quot;)
+     *        if the decryptedNode is an Element or an Attr node and is not 
detached
+     *        from the document. <code>null</code> otherwise
+     */
+    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());
+        }
+    }
 }
diff --git 
a/ws-security-dom/src/main/java/org/apache/wss4j/dom/processor/SAMLTokenProcessor.java
 
b/ws-security-dom/src/main/java/org/apache/wss4j/dom/processor/SAMLTokenProcessor.java
index 8f61332cb..8206acb5a 100644
--- 
a/ws-security-dom/src/main/java/org/apache/wss4j/dom/processor/SAMLTokenProcessor.java
+++ 
b/ws-security-dom/src/main/java/org/apache/wss4j/dom/processor/SAMLTokenProcessor.java
@@ -43,13 +43,13 @@ import org.apache.wss4j.common.saml.SAMLKeyInfo;
 import org.apache.wss4j.common.saml.SAMLUtil;
 import org.apache.wss4j.common.saml.SamlAssertionWrapper;
 import org.apache.wss4j.common.util.DOM2Writer;
+import org.apache.wss4j.common.util.XMLUtils;
 import org.apache.wss4j.common.dom.WSConstants;
 import org.apache.wss4j.common.WSDataRef;
 import org.apache.wss4j.common.dom.engine.WSSecurityEngineResult;
 import org.apache.wss4j.common.dom.processor.Processor;
 import org.apache.wss4j.common.dom.RequestData;
 import org.apache.wss4j.dom.saml.WSSSAMLKeyInfoProcessor;
-import org.apache.wss4j.dom.util.EncryptionUtils;
 import org.apache.wss4j.common.dom.validate.Credential;
 import org.apache.wss4j.common.dom.validate.Validator;
 import org.opensaml.xmlsec.signature.KeyInfo;
@@ -278,7 +278,7 @@ public class SAMLTokenProcessor implements Processor {
                 }
                 ref.setTransformAlgorithms(transformAlgorithms);
 
-                ref.setXpath(EncryptionUtils.getXPath(token));
+                ref.setXpath(XMLUtils.getXPath(token));
                 protectedRefs.add(ref);
             }
         }
diff --git 
a/ws-security-dom/src/main/java/org/apache/wss4j/dom/processor/SignatureProcessor.java
 
b/ws-security-dom/src/main/java/org/apache/wss4j/dom/processor/SignatureProcessor.java
index 93747ae65..b307a8e81 100644
--- 
a/ws-security-dom/src/main/java/org/apache/wss4j/dom/processor/SignatureProcessor.java
+++ 
b/ws-security-dom/src/main/java/org/apache/wss4j/dom/processor/SignatureProcessor.java
@@ -78,7 +78,6 @@ import org.apache.wss4j.dom.str.SignatureSTRParser;
 import 
org.apache.wss4j.common.dom.transform.AttachmentContentSignatureTransform;
 import org.apache.wss4j.common.dom.transform.STRTransform;
 import org.apache.wss4j.common.dom.transform.STRTransformUtil;
-import org.apache.wss4j.dom.util.EncryptionUtils;
 import org.apache.wss4j.dom.util.WSSecurityUtil;
 import org.apache.wss4j.dom.util.X509Util;
 import org.apache.wss4j.common.dom.validate.Credential;
@@ -573,7 +572,7 @@ public class SignatureProcessor implements Processor {
                 }
                 ref.setTransformAlgorithms(transformAlgorithms);
 
-                ref.setXpath(EncryptionUtils.getXPath(se));
+                ref.setXpath(XMLUtils.getXPath(se));
                 protectedRefs.add(ref);
             }
         }
diff --git 
a/ws-security-dom/src/main/java/org/apache/wss4j/dom/util/EncryptionUtils.java 
b/ws-security-dom/src/main/java/org/apache/wss4j/dom/util/EncryptionUtils.java
index 977e652a5..63dd98c3f 100644
--- 
a/ws-security-dom/src/main/java/org/apache/wss4j/dom/util/EncryptionUtils.java
+++ 
b/ws-security-dom/src/main/java/org/apache/wss4j/dom/util/EncryptionUtils.java
@@ -35,7 +35,6 @@ import org.apache.xml.security.encryption.XMLCipher;
 import org.apache.xml.security.encryption.XMLEncryptionException;
 import org.apache.xml.security.parser.XMLParserException;
 import org.apache.xml.security.utils.JavaUtils;
-import org.w3c.dom.Attr;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.NamedNodeMap;
@@ -223,10 +222,10 @@ public final class EncryptionUtils {
             soapHeader.replaceChild(decryptedHeader, parent);
 
             dataRef.setProtectedElement((Element)decryptedHeader);
-            dataRef.setXpath(getXPath(decryptedHeader));
+            dataRef.setXpath(XMLUtils.getXPath(decryptedHeader));
         } else if (content) {
             dataRef.setProtectedElement(encData);
-            dataRef.setXpath(getXPath(encData));
+            dataRef.setXpath(XMLUtils.getXPath(encData));
         } else {
             if (decryptedNode == null) {
                 if (previousSibling == null) {
@@ -238,7 +237,7 @@ public final class EncryptionUtils {
             if (decryptedNode != null && Node.ELEMENT_NODE == 
decryptedNode.getNodeType()) {
                 dataRef.setProtectedElement((Element)decryptedNode);
             }
-            dataRef.setXpath(getXPath(decryptedNode));
+            dataRef.setXpath(XMLUtils.getXPath(decryptedNode));
         }
 
         return dataRef;
@@ -446,54 +445,6 @@ public final class EncryptionUtils {
         return prefix.toString() + suffix.toString();
     }
 
-    /**
-     * @param decryptedNode the decrypted node
-     * @return a fully built xpath
-     *        (eg. 
&quot;/soapenv:Envelope/soapenv:Body/ns:decryptedElement&quot;)
-     *        if the decryptedNode is an Element or an Attr node and is not 
detached
-     *        from the document. <code>null</code> otherwise
-     */
-    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());
-        }
-    }
-
     public static String getDigestAlgorithm(Node encBodyData) throws 
WSSecurityException {
         Element tmpE =
             XMLUtils.getDirectChildElement(

Reply via email to