[java-opensaml] 01/02: OSJ-324: XMLObjectSupport cloneXMLObject should not marshall input ...
Brent Putman
putmanb at georgetown.edu
Fri Oct 2 03:10:38 UTC 2020
This is an automated email from the git hooks/post-receive script.
putmanb pushed a commit to branch main
in repository java-opensaml.
View the commit online:
http://git.shibboleth.net/view/?p=java-opensaml.git;a=commit;h=acac7226ed1094e44a4161afbcf1341fd273e68b
commit acac7226ed1094e44a4161afbcf1341fd273e68b
Author: Brent Putman <putmanb at georgetown.edu>
AuthorDate: Thu Oct 1 23:06:27 2020 -0400
OSJ-324: XMLObjectSupport cloneXMLObject should not marshall input ...
XMLObjectSupport cloneXMLObject should not marshall input if DOM already
exists.
---
.../opensaml/core/xml/util/XMLObjectSupport.java | 15 +++++++----
.../core/xml/util/XMLObjectSupportTest.java | 30 ++++++++++++++++++++++
2 files changed, 40 insertions(+), 5 deletions(-)
diff --git a/opensaml-core/src/main/java/org/opensaml/core/xml/util/XMLObjectSupport.java b/opensaml-core/src/main/java/org/opensaml/core/xml/util/XMLObjectSupport.java
index 4b53d8b2a..44574bc3d 100644
--- a/opensaml-core/src/main/java/org/opensaml/core/xml/util/XMLObjectSupport.java
+++ b/opensaml-core/src/main/java/org/opensaml/core/xml/util/XMLObjectSupport.java
@@ -130,12 +130,17 @@ public final class XMLObjectSupport {
return null;
}
- final Marshaller marshaller = getMarshaller(originalXMLObject);
- if (marshaller == null) {
- throw new MarshallingException("Unable to obtain Marshaller for XMLObject: "
- + originalXMLObject.getElementQName());
+ Element origElement = null;
+ if (originalXMLObject.getDOM() == null) {
+ final Marshaller marshaller = getMarshaller(originalXMLObject);
+ if (marshaller == null) {
+ throw new MarshallingException("Unable to obtain Marshaller for XMLObject: "
+ + originalXMLObject.getElementQName());
+ }
+ origElement = marshaller.marshall(originalXMLObject);
+ } else {
+ origElement = originalXMLObject.getDOM();
}
- final Element origElement = marshaller.marshall(originalXMLObject);
Element clonedElement = null;
diff --git a/opensaml-core/src/test/java/org/opensaml/core/xml/util/XMLObjectSupportTest.java b/opensaml-core/src/test/java/org/opensaml/core/xml/util/XMLObjectSupportTest.java
index 6c8509d46..9f9692570 100644
--- a/opensaml-core/src/test/java/org/opensaml/core/xml/util/XMLObjectSupportTest.java
+++ b/opensaml-core/src/test/java/org/opensaml/core/xml/util/XMLObjectSupportTest.java
@@ -30,6 +30,8 @@ import org.opensaml.core.xml.schema.XSString;
import org.opensaml.core.xml.util.XMLObjectSupport.CloneOutputOption;
import org.testng.Assert;
import org.testng.annotations.Test;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
/**
* Tests of XMLObjectHelper utility methods.
@@ -149,6 +151,34 @@ public class XMLObjectSupportTest extends XMLObjectBaseTestCase {
"Cloned object was not the new Document root");
}
+ @Test
+ public void testXMLObjectCloneInputMarshalling() throws MarshallingException, UnmarshallingException {
+ SimpleXMLObjectBuilder sxoBuilder = (SimpleXMLObjectBuilder) XMLObjectProviderRegistrySupport.getBuilderFactory()
+ .getBuilder(SimpleXMLObject.ELEMENT_NAME);
+
+ SimpleXMLObject origChildObj = sxoBuilder.buildObject();
+ origChildObj.setValue("FooBarBaz");
+
+ SimpleXMLObject origParentObj = sxoBuilder.buildObject();
+ origParentObj.getSimpleXMLObjects().add(origChildObj);
+
+ Assert.assertNull(origParentObj.getDOM());
+
+ SimpleXMLObject clonedParentObj = XMLObjectSupport.cloneXMLObject(origParentObj, CloneOutputOption.DropDOM);
+ Assert.assertNotNull(clonedParentObj);
+
+ Assert.assertNotNull(origParentObj.getDOM());
+ Element preCloneElement = origParentObj.getDOM();
+ Document preCloneDocument = origParentObj.getDOM().getOwnerDocument();
+
+ clonedParentObj = XMLObjectSupport.cloneXMLObject(origParentObj, CloneOutputOption.DropDOM);
+ Assert.assertNotNull(clonedParentObj);
+
+ Assert.assertNotNull(origParentObj.getDOM());
+ Assert.assertTrue(preCloneElement.isSameNode(origParentObj.getDOM()));
+ Assert.assertTrue(preCloneDocument.isSameNode(origParentObj.getDOM().getOwnerDocument()));
+ }
+
@Test
public void testBuildXMLObject() {
try {
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list