List of usage examples for org.w3c.dom Document getElementsByTagNameNS
public NodeList getElementsByTagNameNS(String namespaceURI, String localName);
NodeList
of all the Elements
with a given local name and namespace URI in document order. From source file:org.apache.servicemix.jbi.deployer.utils.ManagementSupport.java
private static Element getElement(Document doc, String name) { NodeList l = doc.getElementsByTagNameNS(HTTP_JAVA_SUN_COM_XML_NS_JBI_MANAGEMENT_MESSAGE, name); return (Element) l.item(0); }
From source file:org.apache.xml.security.samples.encryption.Decrypter.java
public static void main(String unused[]) throws Exception { Document document = loadEncryptionDocument(); Element encryptedDataElement = (Element) document.getElementsByTagNameNS( EncryptionConstants.EncryptionSpecNS, EncryptionConstants._TAG_ENCRYPTEDDATA).item(0); /*//from www . ja v a2s . c o m * Load the key to be used for decrypting the xml data * encryption key. */ Key kek = loadKeyEncryptionKey(); String providerName = "BC"; XMLCipher xmlCipher = XMLCipher.getInstance(); /* * The key to be used for decrypting xml data would be obtained * from the keyinfo of the EncrypteData using the kek. */ xmlCipher.init(XMLCipher.DECRYPT_MODE, null); xmlCipher.setKEK(kek); /* * The following doFinal call replaces the encrypted data with * decrypted contents in the document. */ xmlCipher.doFinal(document, encryptedDataElement); outputDocToFile(document, "decryptedInfo.xml"); }
From source file:org.apache.xml.security.test.c14n.implementations.Canonicalizer20010315ExclusiveTest.java
/** * Method testA/* www . java2 s . co m*/ * * @throws CanonicalizationException * @throws FileNotFoundException * @throws IOException * @throws InvalidCanonicalizerException * @throws ParserConfigurationException * @throws SAXException * @throws TransformerException * @throws XMLSecurityException * @throws XMLSignatureException * @throws org.apache.xml.security.keys.keyresolver.KeyResolverException */ public void testA() throws IOException, FileNotFoundException, SAXException, ParserConfigurationException, CanonicalizationException, InvalidCanonicalizerException, TransformerException, XMLSignatureException, XMLSecurityException, org.apache.xml.security.keys.keyresolver.KeyResolverException { File fileIn = new File( getAbsolutePath("data/ie/baltimore/merlin-examples/ec-merlin-iaikTests-two/signature.xml")); // File fileIn = new File("signature.xml"); assertTrue("file exists", fileIn.exists()); Document doc = this.db.parse(fileIn); Element signatureElement = (Element) doc .getElementsByTagNameNS(Constants.SignatureSpecNS, Constants._TAG_SIGNATURE).item(0); XMLSignature xmlSignature = new XMLSignature(signatureElement, fileIn.toURL().toString()); boolean verify = xmlSignature.checkSignatureValue(xmlSignature.getKeyInfo().getPublicKey()); int length = xmlSignature.getSignedInfo().getLength(); int numberOfPositiveReferences = 0; for (int i = 0; i < length; i++) { boolean singleResult = xmlSignature.getSignedInfo().getVerificationResult(i); if (singleResult) { numberOfPositiveReferences++; } } assertTrue("Verification failed; only " + numberOfPositiveReferences + "/" + length + " matched", verify); }
From source file:org.apache.xml.security.test.c14n.implementations.Canonicalizer20010315ExclusiveTest.java
/** * Method test221/*from w ww.j av a 2 s. co m*/ * * @throws CanonicalizationException * @throws FileNotFoundException * @throws IOException * @throws InvalidCanonicalizerException * @throws ParserConfigurationException * @throws SAXException * @throws TransformerException * @throws XMLSecurityException * @throws XMLSignatureException */ public void test221() throws IOException, FileNotFoundException, SAXException, ParserConfigurationException, CanonicalizationException, InvalidCanonicalizerException, TransformerException, XMLSignatureException, XMLSecurityException { Document doc = this.db.parse(getAbsolutePath("data/org/apache/xml/security/c14n/inExcl/example2_2_1.xml")); Node root = doc.getElementsByTagNameNS("http://example.net", "elem2").item(0); Canonicalizer20010315 c = new Canonicalizer20010315WithComments(); byte[] reference = JavaUtils.getBytesFromFile( getAbsolutePath("data/org/apache/xml/security/c14n/inExcl/example2_2_1_c14nized.xml")); byte[] result = c.engineCanonicalizeSubTree(root); boolean equals = java.security.MessageDigest.isEqual(reference, result); /* if (!equals) { JavaUtils.writeBytesToFilename("data/org/apache/xml/security/c14n/inExcl/example2_2_1_c14nized.apache.xml", result); } */ assertTrue(equals); }
From source file:org.apache.xml.security.test.c14n.implementations.Canonicalizer20010315ExclusiveTest.java
/** * Method test222//from ww w .j a v a 2 s .co m * * @throws CanonicalizationException * @throws FileNotFoundException * @throws IOException * @throws InvalidCanonicalizerException * @throws ParserConfigurationException * @throws SAXException * @throws TransformerException * @throws XMLSecurityException * @throws XMLSignatureException */ public void test222() throws IOException, FileNotFoundException, SAXException, ParserConfigurationException, CanonicalizationException, InvalidCanonicalizerException, TransformerException, XMLSignatureException, XMLSecurityException { Document doc = this.db.parse(getAbsolutePath("data/org/apache/xml/security/c14n/inExcl/example2_2_2.xml")); Node root = doc.getElementsByTagNameNS("http://example.net", "elem2").item(0); Canonicalizer20010315 c = new Canonicalizer20010315WithComments(); byte[] reference = JavaUtils.getBytesFromFile( getAbsolutePath("data/org/apache/xml/security/c14n/inExcl/example2_2_2_c14nized.xml")); byte[] result = c.engineCanonicalizeSubTree(root); boolean equals = java.security.MessageDigest.isEqual(reference, result); assertTrue(equals); }
From source file:org.apache.xml.security.test.c14n.implementations.Canonicalizer20010315ExclusiveTest.java
/** * Method test221excl/*from w ww .jav a 2 s . com*/ * * @throws CanonicalizationException * @throws FileNotFoundException * @throws IOException * @throws InvalidCanonicalizerException * @throws ParserConfigurationException * @throws SAXException * @throws TransformerException * @throws XMLSecurityException * @throws XMLSignatureException */ public void test221excl() throws IOException, FileNotFoundException, SAXException, ParserConfigurationException, CanonicalizationException, InvalidCanonicalizerException, TransformerException, XMLSignatureException, XMLSecurityException { Document doc = this.db.parse(getAbsolutePath("data/org/apache/xml/security/c14n/inExcl/example2_2_1.xml")); Node root = doc.getElementsByTagNameNS("http://example.net", "elem2").item(0); Canonicalizer20010315Excl c = new Canonicalizer20010315ExclWithComments(); byte[] reference = JavaUtils.getBytesFromFile( getAbsolutePath("data/org/apache/xml/security/c14n/inExcl/example2_2_c14nized_exclusive.xml")); byte[] result = c.engineCanonicalizeSubTree(root); boolean equals = java.security.MessageDigest.isEqual(reference, result); assertTrue(equals); }
From source file:org.apache.xml.security.test.c14n.implementations.Canonicalizer20010315ExclusiveTest.java
/** * Method test222excl//from w ww . j a v a2 s. co m * * @throws CanonicalizationException * @throws FileNotFoundException * @throws IOException * @throws InvalidCanonicalizerException * @throws ParserConfigurationException * @throws SAXException * @throws TransformerException * @throws XMLSecurityException * @throws XMLSignatureException */ public void test222excl() throws IOException, FileNotFoundException, SAXException, ParserConfigurationException, CanonicalizationException, InvalidCanonicalizerException, TransformerException, XMLSignatureException, XMLSecurityException { Document doc = this.db.parse(getAbsolutePath("data/org/apache/xml/security/c14n/inExcl/example2_2_2.xml")); Node root = doc.getElementsByTagNameNS("http://example.net", "elem2").item(0); Canonicalizer20010315Excl c = new Canonicalizer20010315ExclWithComments(); byte[] reference = JavaUtils.getBytesFromFile( getAbsolutePath("data/org/apache/xml/security/c14n/inExcl/example2_2_c14nized_exclusive.xml")); byte[] result = c.engineCanonicalizeSubTree(root); boolean equals = java.security.MessageDigest.isEqual(reference, result); assertTrue(equals); }
From source file:org.apache.xml.security.test.c14n.implementations.Canonicalizer20010315ExclusiveTest.java
/** * Method test24excl - a testcase for SANTUARIO-263 * "Canonicalizer can't handle dynamical created DOM correctly" * https://issues.apache.org/jira/browse/SANTUARIO-263 * * @throws CanonicalizationException/*from w w w . j a va2 s.com*/ * @throws FileNotFoundException * @throws IOException * @throws InvalidCanonicalizerException * @throws ParserConfigurationException * @throws SAXException * @throws TransformerException * @throws XMLSecurityException * @throws XMLSignatureException */ public void test24excl() throws IOException, FileNotFoundException, SAXException, ParserConfigurationException, CanonicalizationException, InvalidCanonicalizerException, TransformerException, XMLSignatureException, XMLSecurityException { Document doc = this.db.parse(getAbsolutePath("data/org/apache/xml/security/c14n/inExcl/example2_4.xml")); Node root = doc.getElementsByTagNameNS("http://example.net", "elem2").item(0); Canonicalizer20010315Excl c = new Canonicalizer20010315ExclWithComments(); byte[] reference = JavaUtils.getBytesFromFile( getAbsolutePath("data/org/apache/xml/security/c14n/inExcl/example2_4_c14nized.xml")); byte[] result = c.engineCanonicalizeSubTree(root); boolean equals = java.security.MessageDigest.isEqual(reference, result); assertTrue(equals); }
From source file:org.apache.xml.security.test.c14n.implementations.Canonicalizer20010315ExclusiveTest.java
/** * Method test24Aexcl - a testcase for SANTUARIO-263 * "Canonicalizer can't handle dynamical created DOM correctly" * https://issues.apache.org/jira/browse/SANTUARIO-263 * * @throws CanonicalizationException// w ww. j a v a 2 s .c o m * @throws FileNotFoundException * @throws IOException * @throws InvalidCanonicalizerException * @throws ParserConfigurationException * @throws SAXException * @throws TransformerException * @throws XMLSecurityException * @throws XMLSignatureException */ public void test24Aexcl() throws IOException, FileNotFoundException, SAXException, ParserConfigurationException, CanonicalizationException, InvalidCanonicalizerException, TransformerException, XMLSignatureException, XMLSecurityException { Document doc = dbf.newDocumentBuilder().newDocument(); Element local = doc.createElementNS("foo:bar", "dsig:local"); Element test = doc.createElementNS("http://example.net", "etsi:test"); Element elem2 = doc.createElementNS("http://example.net", "etsi:elem2"); Element stuff = doc.createElementNS("foo:bar", "dsig:stuff"); elem2.appendChild(stuff); test.appendChild(elem2); local.appendChild(test); doc.appendChild(local); Node root = doc.getElementsByTagNameNS("http://example.net", "elem2").item(0); Canonicalizer20010315Excl c = new Canonicalizer20010315ExclWithComments(); byte[] reference = JavaUtils.getBytesFromFile( getAbsolutePath("data/org/apache/xml/security/c14n/inExcl/example2_4_c14nized.xml")); byte[] result = c.engineCanonicalizeSubTree(root); boolean equals = java.security.MessageDigest.isEqual(reference, result); assertTrue(equals); }
From source file:org.apache.xml.security.test.c14n.implementations.ExclusiveC14NInterop.java
/** * Method t//from w ww . j av a 2s . c om * * @param directory * @param file * * @throws Exception */ public String t(String directory, String file) throws Exception { String basedir = System.getProperty("basedir"); if (basedir != null && !"".equals(basedir)) { directory = basedir + "/" + directory; } File f = new File(directory + "/" + file); javax.xml.parsers.DocumentBuilderFactory dbf = javax.xml.parsers.DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); javax.xml.parsers.DocumentBuilder db = dbf.newDocumentBuilder(); org.w3c.dom.Document doc = db.parse(f); Element sigElement = (Element) doc .getElementsByTagNameNS(Constants.SignatureSpecNS, Constants._TAG_SIGNATURE).item(0); XMLSignature signature = new XMLSignature(sigElement, f.toURL().toString()); boolean verify = signature.checkSignatureValue(signature.getKeyInfo().getPublicKey()); log.debug(" signature.checkSignatureValue finished: " + verify); int failures = 0; // if (!verify) { if (true) { StringBuffer sb = new StringBuffer(); for (int i = 0; i < signature.getSignedInfo().getLength(); i++) { boolean refVerify = signature.getSignedInfo().getVerificationResult(i); JavaUtils.writeBytesToFilename(directory + "/c14n-" + i + ".apache.html", signature.getSignedInfo().item(i).getHTMLRepresentation().getBytes()); if (refVerify) { log.debug("Reference " + i + " was OK"); } else { failures++; sb.append(i + " "); JavaUtils.writeBytesToFilename(directory + "/c14n-" + i + ".apache.txt", signature.getSignedInfo().item(i).getContentsAfterTransformation().getBytes()); JavaUtils.writeBytesToFilename(directory + "/c14n-" + i + ".apache.html", signature.getSignedInfo().item(i).getHTMLRepresentation().getBytes()); Reference reference = signature.getSignedInfo().item(i); int length = reference.getTransforms().getLength(); String algo = reference.getTransforms().item(length - 1).getURI(); log.debug("Reference " + i + " failed: " + algo); } } String r = sb.toString().trim(); if (r.length() == 0) { return null; } else { return r; } } else { return null; } }