You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@santuario.apache.org by co...@apache.org on 2016/04/18 11:09:27 UTC
svn commit: r1739711 - in /santuario/xml-security-java/trunk/src:
main/java/org/apache/jcp/xml/dsig/internal/dom/DOMKeyInfo.java
test/java/javax/xml/crypto/test/dsig/keyinfo/KeyInfoTest.java
Author: coheigea
Date: Mon Apr 18 09:09:27 2016
New Revision: 1739711
URL: http://svn.apache.org/viewvc?rev=1739711&view=rev
Log:
[SANTUARIO-439] - Handle nextSibling in KeyInfo marshalling
Modified:
santuario/xml-security-java/trunk/src/main/java/org/apache/jcp/xml/dsig/internal/dom/DOMKeyInfo.java
santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/keyinfo/KeyInfoTest.java
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/jcp/xml/dsig/internal/dom/DOMKeyInfo.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/jcp/xml/dsig/internal/dom/DOMKeyInfo.java?rev=1739711&r1=1739710&r2=1739711&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/jcp/xml/dsig/internal/dom/DOMKeyInfo.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/jcp/xml/dsig/internal/dom/DOMKeyInfo.java Mon Apr 18 09:09:27 2016
@@ -24,12 +24,17 @@
*/
package org.apache.jcp.xml.dsig.internal.dom;
-import javax.xml.crypto.*;
-import javax.xml.crypto.dsig.*;
-import javax.xml.crypto.dsig.keyinfo.KeyInfo;
-
import java.security.Provider;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import javax.xml.crypto.MarshalException;
+import javax.xml.crypto.XMLCryptoContext;
+import javax.xml.crypto.XMLStructure;
+import javax.xml.crypto.dsig.XMLSignature;
+import javax.xml.crypto.dsig.dom.DOMSignContext;
+import javax.xml.crypto.dsig.keyinfo.KeyInfo;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
@@ -155,7 +160,12 @@ public final class DOMKeyInfo extends Ba
Node pNode = parent.getNode();
String dsPrefix = DOMUtils.getSignaturePrefix(context);
- XmlWriterToTree xwriter = new XmlWriterToTree(Marshaller.getMarshallers(), pNode);
+ Node nextSibling = null;
+ if (context instanceof DOMSignContext) {
+ nextSibling = ((DOMSignContext)context).getNextSibling();
+ }
+
+ XmlWriterToTree xwriter = new XmlWriterToTree(Marshaller.getMarshallers(), pNode, nextSibling);
marshalInternal(xwriter, this, dsPrefix, context, true);
}
Modified: santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/keyinfo/KeyInfoTest.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/keyinfo/KeyInfoTest.java?rev=1739711&r1=1739710&r2=1739711&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/keyinfo/KeyInfoTest.java (original)
+++ santuario/xml-security-java/trunk/src/test/java/javax/xml/crypto/test/dsig/keyinfo/KeyInfoTest.java Mon Apr 18 09:09:27 2016
@@ -21,16 +21,20 @@
*/
package javax.xml.crypto.test.dsig.keyinfo;
-import java.util.*;
+import java.security.Key;
+import java.util.Collections;
+import java.util.List;
+
+import javax.xml.crypto.XMLStructure;
+import javax.xml.crypto.dom.DOMStructure;
+import javax.xml.crypto.dsig.dom.DOMSignContext;
+import javax.xml.crypto.dsig.keyinfo.KeyInfo;
+import javax.xml.crypto.dsig.keyinfo.KeyInfoFactory;
-import javax.xml.crypto.*;
-import javax.xml.crypto.dom.*;
-import javax.xml.crypto.dsig.keyinfo.*;
-
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
import org.apache.jcp.xml.dsig.internal.dom.DOMUtils;
import org.apache.xml.security.utils.XMLUtils;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
/**
* Unit test for javax.xml.crypto.dsig.keyinfo.KeyInfo
@@ -128,5 +132,37 @@ public class KeyInfoTest extends org.jun
if (!knElem.getLocalName().equals("KeyName")) {
fail("Should be KeyName element: " + knElem.getLocalName());
}
+
+ // check if key info is inserted before nextSibling
+ doc = XMLUtils.createDocumentBuilder(false).newDocument();
+ elem = doc.createElementNS("http://acme.org", "parent");
+ doc.appendChild(elem);
+ Element nextSib = doc.createElementNS("http://acme.org", "nextSib");
+ elem.appendChild(nextSib);
+
+ Key key = new Key() {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public String getAlgorithm() {
+ return null;
+ }
+
+ @Override
+ public byte[] getEncoded() {
+ return null;
+ }
+
+ @Override
+ public String getFormat() {
+ return null;
+ }
+ };
+
+ DOMSignContext ctx = new DOMSignContext(key, elem, nextSib);
+ parent = new DOMStructure(elem);
+ ki.marshal(parent, ctx);
+ // no need for catching/calling fail() explicitly ... if it fails, it fails ...
+ assertEquals(elem.getFirstChild().getLocalName(), "KeyInfo");
}
}