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
commit 07aa714ba5f735ed3cf08154a788e59414cbb113 Author: Colm O hEigeartaigh <[email protected]> AuthorDate: Fri Jun 20 11:59:56 2025 +0100 Moving method from WSSecurityUtil into WSEncryptionPart --- .../org/apache/wss4j/common/WSEncryptionPart.java | 30 ++++++++++++++++++++++ .../org/apache/wss4j/dom/message/Encryptor.java | 3 +-- .../wss4j/dom/message/WSSecSignatureBase.java | 2 +- .../org/apache/wss4j/dom/util/WSSecurityUtil.java | 30 ---------------------- 4 files changed, 32 insertions(+), 33 deletions(-) diff --git a/ws-security-common/src/main/java/org/apache/wss4j/common/WSEncryptionPart.java b/ws-security-common/src/main/java/org/apache/wss4j/common/WSEncryptionPart.java index 95912eccf..41a5f0afd 100644 --- a/ws-security-common/src/main/java/org/apache/wss4j/common/WSEncryptionPart.java +++ b/ws-security-common/src/main/java/org/apache/wss4j/common/WSEncryptionPart.java @@ -19,6 +19,11 @@ package org.apache.wss4j.common; +import java.util.Collections; +import java.util.List; + +import org.apache.wss4j.common.dom.callback.CallbackLookup; +import org.apache.wss4j.common.ext.WSSecurityException; import org.w3c.dom.Element; @@ -187,4 +192,29 @@ public class WSEncryptionPart { this.required = required; } + /** + * Find the DOM Element in the SOAP Envelope that is referenced by this WSEncryptionPart. + * The "Id" is used before the Element localname/namespace. + * + * @param callbackLookup The CallbackLookup object used to find Elements + * @return the DOM Element in the SOAP Envelope that is found + */ + public List<Element> findElements( + CallbackLookup callbackLookup + ) throws WSSecurityException { + // See if the DOM Element is stored in the WSEncryptionPart first + if (getElement() != null) { + return Collections.singletonList(getElement()); + } + + // Next try to find the Element via its wsu:Id + String id = getId(); + if (id != null) { + Element foundElement = callbackLookup.getElement(id, null, false); + return Collections.singletonList(foundElement); + } + // Otherwise just lookup all elements with the localname/namespace + return callbackLookup.getElements(getName(), getNamespace()); + } + } diff --git a/ws-security-dom/src/main/java/org/apache/wss4j/dom/message/Encryptor.java b/ws-security-dom/src/main/java/org/apache/wss4j/dom/message/Encryptor.java index 9c6f35259..93fdefa68 100644 --- a/ws-security-dom/src/main/java/org/apache/wss4j/dom/message/Encryptor.java +++ b/ws-security-dom/src/main/java/org/apache/wss4j/dom/message/Encryptor.java @@ -116,8 +116,7 @@ public class Encryptor { if (callbackLookup == null) { callbackLookup = new DOMCallbackLookup(doc); } - List<Element> elementsToEncrypt = - WSSecurityUtil.findElements(encPart, callbackLookup); + List<Element> elementsToEncrypt = encPart.findElements(callbackLookup); if (elementsToEncrypt == null || elementsToEncrypt.isEmpty()) { if (!encPart.isRequired()) { continue; diff --git a/ws-security-dom/src/main/java/org/apache/wss4j/dom/message/WSSecSignatureBase.java b/ws-security-dom/src/main/java/org/apache/wss4j/dom/message/WSSecSignatureBase.java index f37e86b41..893406a10 100644 --- a/ws-security-dom/src/main/java/org/apache/wss4j/dom/message/WSSecSignatureBase.java +++ b/ws-security-dom/src/main/java/org/apache/wss4j/dom/message/WSSecSignatureBase.java @@ -176,7 +176,7 @@ public class WSSecSignatureBase extends WSSecBase { if (callbackLookup == null) { callbackLookup = new DOMCallbackLookup(doc); } - elementsToSign = WSSecurityUtil.findElements(encPart, callbackLookup); + elementsToSign = encPart.findElements(callbackLookup); } if (elementsToSign == null || elementsToSign.isEmpty()) { if (!encPart.isRequired()) { diff --git a/ws-security-dom/src/main/java/org/apache/wss4j/dom/util/WSSecurityUtil.java b/ws-security-dom/src/main/java/org/apache/wss4j/dom/util/WSSecurityUtil.java index 67c826499..52852c572 100644 --- a/ws-security-dom/src/main/java/org/apache/wss4j/dom/util/WSSecurityUtil.java +++ b/ws-security-dom/src/main/java/org/apache/wss4j/dom/util/WSSecurityUtil.java @@ -22,7 +22,6 @@ package org.apache.wss4j.dom.util; import org.apache.wss4j.common.dom.WSConstants; import org.apache.wss4j.common.dom.engine.WSSConfig; import org.apache.wss4j.common.WSEncryptionPart; -import org.apache.wss4j.common.dom.callback.CallbackLookup; import org.apache.wss4j.common.ext.WSSecurityException; import org.apache.wss4j.common.util.AttachmentUtils; import org.apache.wss4j.common.util.XMLUtils; @@ -172,35 +171,6 @@ public final class WSSecurityUtil { return XMLUtils.getDirectChildElement(docElement, WSConstants.ELEM_BODY, ns); } - - /** - * Find the DOM Element in the SOAP Envelope that is referenced by the - * WSEncryptionPart argument. The "Id" is used before the Element localname/namespace. - * - * @param part The WSEncryptionPart object corresponding to the DOM Element(s) we want - * @param callbackLookup The CallbackLookup object used to find Elements - * @return the DOM Element in the SOAP Envelope that is found - */ - public static List<Element> findElements( - WSEncryptionPart part, CallbackLookup callbackLookup - ) throws WSSecurityException { - // See if the DOM Element is stored in the WSEncryptionPart first - if (part.getElement() != null) { - return Collections.singletonList(part.getElement()); - } - - // Next try to find the Element via its wsu:Id - String id = part.getId(); - if (id != null) { - Element foundElement = callbackLookup.getElement(id, null, false); - return Collections.singletonList(foundElement); - } - // Otherwise just lookup all elements with the localname/namespace - return callbackLookup.getElements(part.getName(), part.getNamespace()); - } - - - /** * Get the default encryption part - the SOAP Body of type "Content". */
