changeset 4570:7617df64c231

7094155: JSR105 code throws javax.xml.crypto.URIReferenceException when running into Java 7 VM Reviewed-by: xuelei
author mullan
date Fri, 13 Jan 2012 09:47:49 -0500
parents 9f9912af74d4
children d57776c3ab22
files src/share/classes/com/sun/org/apache/xml/internal/security/utils/IdResolver.java test/javax/xml/crypto/dsig/GenerationTests.java
diffstat 2 files changed, 51 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/sun/org/apache/xml/internal/security/utils/IdResolver.java	Thu Jan 12 17:42:40 2012 +0400
+++ b/src/share/classes/com/sun/org/apache/xml/internal/security/utils/IdResolver.java	Fri Jan 13 09:47:49 2012 -0500
@@ -248,6 +248,8 @@
                     int index=s==null ? elementIndex : names.indexOf(n.getNamespaceURI());
                     index=(index<0) ? namesLength : index;
                     String name=n.getLocalName();
+                    if (name == null)
+                        name = n.getName();
                     if (name.length()>2)
                         continue;
                     String value=n.getNodeValue();
--- a/test/javax/xml/crypto/dsig/GenerationTests.java	Thu Jan 12 17:42:40 2012 +0400
+++ b/test/javax/xml/crypto/dsig/GenerationTests.java	Fri Jan 13 09:47:49 2012 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2009, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -23,7 +23,7 @@
 
 /**
  * @test
- * @bug 4635230 6283345 6303830 6824440 6867348
+ * @bug 4635230 6283345 6303830 6824440 6867348 7094155
  * @summary Basic unit tests for generating XML Signatures with JSR 105
  * @compile -XDignore.symbol.file KeySelectors.java SignatureValidator.java
  *     X509KeySelector.java GenerationTests.java
@@ -134,6 +134,7 @@
         test_create_signature_enveloping_sha512_rsa_sha384();
         test_create_signature_enveloping_sha512_rsa_sha512();
         test_create_signature_reference_dependency();
+        test_create_signature_with_attr_in_no_namespace();
     }
 
     private static void setup() throws Exception {
@@ -443,6 +444,52 @@
 
         sig.sign(dsc);
 
+        // dumpDocument(doc, new PrintWriter(System.out));
+
+        DOMValidateContext dvc = new DOMValidateContext
+            (kvks, doc.getDocumentElement());
+        XMLSignature sig2 = fac.unmarshalXMLSignature(dvc);
+
+        if (sig.equals(sig2) == false) {
+            throw new Exception
+                ("Unmarshalled signature is not equal to generated signature");
+        }
+        if (sig2.validate(dvc) == false) {
+            throw new Exception("Validation of generated signature failed");
+        }
+
+        System.out.println();
+    }
+
+    static void test_create_signature_with_attr_in_no_namespace()
+        throws Exception
+    {
+        System.out.println
+            ("* Generating signature-with-attr-in-no-namespace.xml");
+
+        // create references
+        List<Reference> refs = Collections.singletonList
+            (fac.newReference("#unknown", sha1));
+
+        // create SignedInfo
+        SignedInfo si = fac.newSignedInfo(withoutComments, rsaSha1, refs);
+
+        // create object-1
+        Document doc = db.newDocument();
+        Element nc = doc.createElementNS(null, "NonCommentandus");
+        // add attribute with no namespace
+        nc.setAttribute("Id", "unknown");
+        XMLObject obj = fac.newXMLObject(Collections.singletonList
+            (new DOMStructure(nc)), "object-1", null, null);
+
+        // create XMLSignature
+        XMLSignature sig = fac.newXMLSignature(si, rsa,
+                                               Collections.singletonList(obj),
+                                               "signature", null);
+        DOMSignContext dsc = new DOMSignContext(getPrivateKey("RSA"), doc);
+
+        sig.sign(dsc);
+
 //      dumpDocument(doc, new PrintWriter(System.out));
 
         DOMValidateContext dvc = new DOMValidateContext