You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ws.apache.org by dk...@apache.org on 2013/03/20 18:44:35 UTC

svn commit: r1458975 - /webservices/wss4j/branches/1_6_x-fixes/src/main/java/org/apache/ws/security/saml/ext/OpenSAMLUtil.java

Author: dkulp
Date: Wed Mar 20 17:44:35 2013
New Revision: 1458975

URL: http://svn.apache.org/r1458975
Log:
the new xmlsec version does extra validation that is causing SEVERE log warnings with the document optimizations when using the sun SAAJ impl.   Update the optimizations a bit to account for that.

Modified:
    webservices/wss4j/branches/1_6_x-fixes/src/main/java/org/apache/ws/security/saml/ext/OpenSAMLUtil.java

Modified: webservices/wss4j/branches/1_6_x-fixes/src/main/java/org/apache/ws/security/saml/ext/OpenSAMLUtil.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/1_6_x-fixes/src/main/java/org/apache/ws/security/saml/ext/OpenSAMLUtil.java?rev=1458975&r1=1458974&r2=1458975&view=diff
==============================================================================
--- webservices/wss4j/branches/1_6_x-fixes/src/main/java/org/apache/ws/security/saml/ext/OpenSAMLUtil.java (original)
+++ webservices/wss4j/branches/1_6_x-fixes/src/main/java/org/apache/ws/security/saml/ext/OpenSAMLUtil.java Wed Mar 20 17:44:35 2013
@@ -135,15 +135,26 @@ public final class OpenSAMLUtil {
         DocumentFragment frag = doc == null ? null : doc.createDocumentFragment();
         try {
             if (frag != null) {
+                String ns = null;
+                String nm = null;
+                if (doc.getDocumentElement() != null) {
+                    ns = doc.getDocumentElement().getNamespaceURI();
+                    nm = doc.getDocumentElement().getLocalName();
+                }
                 while (doc.getFirstChild() != null) {
                     frag.appendChild(doc.removeChild(doc.getFirstChild()));
                 }
+                if (nm != null) {
+                    doc.appendChild(doc.createElementNS(ns, nm));
+                }
             }
             try {
                 if (doc == null) {
                     element = marshaller.marshall(xmlObject);
-                } else {
+                } else if (doc.getDocumentElement() == null) {
                     element = marshaller.marshall(xmlObject, doc);
+                } else {
+                    element = marshaller.marshall(xmlObject, doc.getDocumentElement());
                 } 
             } catch (MarshallingException ex) {
                 throw new WSSecurityException("Error marshalling a SAML assertion", ex);
@@ -154,10 +165,15 @@ public final class OpenSAMLUtil {
             }
         } finally {
             if (frag != null) {
+                if (doc.getDocumentElement() != null
+                    && doc.getDocumentElement() != element) {
+                    doc.getDocumentElement().removeChild(element);
+                }
                 while (doc.getFirstChild() != null) {
                     doc.removeChild(doc.getFirstChild());
                 }
                 doc.appendChild(frag);
+                doc.getDocumentElement();
             }
         }
         return element;