Search in sources :

Example 1 with Canonicalizer20010315_ExclWithCommentsTransformer

use of org.apache.xml.security.stax.impl.transformer.canonicalizer.Canonicalizer20010315_ExclWithCommentsTransformer in project santuario-java by apache.

the class Canonicalizer20010315ExclusiveTest method test24excl.

@org.junit.Test
public void test24excl() throws Exception {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    Canonicalizer20010315_ExclWithCommentsTransformer c = new Canonicalizer20010315_ExclWithCommentsTransformer();
    c.setOutputStream(baos);
    canonicalize(c, this.getClass().getClassLoader().getResourceAsStream("org/apache/xml/security/c14n/inExcl/example2_4.xml"), new QName("http://example.net", "elem2"));
    byte[] reference = getBytesFromResource(this.getClass().getClassLoader().getResource("org/apache/xml/security/c14n/inExcl/example2_4_c14nized.xml"));
    boolean equals = java.security.MessageDigest.isEqual(reference, baos.toByteArray());
    if (!equals) {
        System.out.println("Expected:\n" + new String(reference, java.nio.charset.StandardCharsets.UTF_8));
        System.out.println("");
        System.out.println("Got:\n" + new String(baos.toByteArray(), java.nio.charset.StandardCharsets.UTF_8));
    }
    assertTrue(equals);
}
Also used : QName(javax.xml.namespace.QName) Canonicalizer20010315_ExclWithCommentsTransformer(org.apache.xml.security.stax.impl.transformer.canonicalizer.Canonicalizer20010315_ExclWithCommentsTransformer)

Example 2 with Canonicalizer20010315_ExclWithCommentsTransformer

use of org.apache.xml.security.stax.impl.transformer.canonicalizer.Canonicalizer20010315_ExclWithCommentsTransformer in project santuario-java by apache.

the class Canonicalizer20010315ExclusiveTest method test222excl.

@org.junit.Test
public void test222excl() throws Exception {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    Canonicalizer20010315_ExclWithCommentsTransformer c = new Canonicalizer20010315_ExclWithCommentsTransformer();
    c.setOutputStream(baos);
    canonicalize(c, this.getClass().getClassLoader().getResourceAsStream("org/apache/xml/security/c14n/inExcl/example2_2_2.xml"), new QName("http://example.net", "elem2"));
    byte[] reference = getBytesFromResource(this.getClass().getClassLoader().getResource("org/apache/xml/security/c14n/inExcl/example2_2_c14nized_exclusive.xml"));
    boolean equals = java.security.MessageDigest.isEqual(reference, baos.toByteArray());
    if (!equals) {
        System.out.println("Expected:\n" + new String(reference, java.nio.charset.StandardCharsets.UTF_8));
        System.out.println("");
        System.out.println("Got:\n" + new String(baos.toByteArray(), java.nio.charset.StandardCharsets.UTF_8));
    }
    assertTrue(equals);
}
Also used : QName(javax.xml.namespace.QName) Canonicalizer20010315_ExclWithCommentsTransformer(org.apache.xml.security.stax.impl.transformer.canonicalizer.Canonicalizer20010315_ExclWithCommentsTransformer)

Example 3 with Canonicalizer20010315_ExclWithCommentsTransformer

use of org.apache.xml.security.stax.impl.transformer.canonicalizer.Canonicalizer20010315_ExclWithCommentsTransformer in project santuario-java by apache.

the class Canonicalizer20010315ExclusiveTest method testComplexDocexcl.

@org.junit.Test
public void testComplexDocexcl() throws Exception {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    Canonicalizer20010315_ExclWithCommentsTransformer c = new Canonicalizer20010315_ExclWithCommentsTransformer();
    c.setOutputStream(baos);
    canonicalize(c, this.getClass().getClassLoader().getResourceAsStream("org/apache/xml/security/c14n/inExcl/plain-soap-1.1.xml"), new QName("http://schemas.xmlsoap.org/soap/envelope/", "Body", "env"));
    byte[] reference = getBytesFromResource(this.getClass().getClassLoader().getResource("org/apache/xml/security/c14n/inExcl/plain-soap-c14nized.xml"));
    boolean equals = java.security.MessageDigest.isEqual(reference, baos.toByteArray());
    if (!equals) {
        System.out.println("Expected:\n" + new String(reference, java.nio.charset.StandardCharsets.UTF_8));
        System.out.println("");
        System.out.println("Got:\n" + new String(baos.toByteArray(), java.nio.charset.StandardCharsets.UTF_8));
    }
    assertTrue(equals);
}
Also used : QName(javax.xml.namespace.QName) Canonicalizer20010315_ExclWithCommentsTransformer(org.apache.xml.security.stax.impl.transformer.canonicalizer.Canonicalizer20010315_ExclWithCommentsTransformer)

Example 4 with Canonicalizer20010315_ExclWithCommentsTransformer

use of org.apache.xml.security.stax.impl.transformer.canonicalizer.Canonicalizer20010315_ExclWithCommentsTransformer in project santuario-java by apache.

the class Canonicalizer20010315ExclusiveTest method test24Aexcl.

/**
 * Method test24Aexcl - a testcase for SANTUARIO-263
 * "Canonicalizer can't handle dynamical created DOM correctly"
 * https://issues.apache.org/jira/browse/SANTUARIO-263
 */
@org.junit.Test
public void test24Aexcl() throws Exception {
    Document doc = XMLUtils.createDocumentBuilder(false).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);
    TransformerFactory tf = TransformerFactory.newInstance();
    Transformer t = tf.newTransformer();
    StringWriter stringWriter = new StringWriter();
    StreamResult streamResult = new StreamResult(stringWriter);
    t.transform(new DOMSource(doc), streamResult);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    List<String> inclusiveNamespaces = new ArrayList<>();
    Canonicalizer20010315_ExclWithCommentsTransformer c = new Canonicalizer20010315_ExclWithCommentsTransformer();
    Map<String, Object> transformerProperties = new HashMap<>();
    transformerProperties.put(Canonicalizer20010315_Excl.INCLUSIVE_NAMESPACES_PREFIX_LIST, inclusiveNamespaces);
    c.setProperties(transformerProperties);
    c.setOutputStream(baos);
    canonicalize(c, new StringReader(stringWriter.toString()), new QName("http://example.net", "elem2"));
    byte[] reference = getBytesFromResource(this.getClass().getClassLoader().getResource("org/apache/xml/security/c14n/inExcl/example2_4_c14nized.xml"));
    boolean equals = java.security.MessageDigest.isEqual(reference, baos.toByteArray());
    assertTrue(equals);
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) TransformerFactory(javax.xml.transform.TransformerFactory) Transformer(javax.xml.transform.Transformer) Canonicalizer20010315_ExclWithCommentsTransformer(org.apache.xml.security.stax.impl.transformer.canonicalizer.Canonicalizer20010315_ExclWithCommentsTransformer) Canonicalizer20010315_ExclOmitCommentsTransformer(org.apache.xml.security.stax.impl.transformer.canonicalizer.Canonicalizer20010315_ExclOmitCommentsTransformer) StreamResult(javax.xml.transform.stream.StreamResult) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) Document(org.w3c.dom.Document) Canonicalizer20010315_ExclWithCommentsTransformer(org.apache.xml.security.stax.impl.transformer.canonicalizer.Canonicalizer20010315_ExclWithCommentsTransformer)

Example 5 with Canonicalizer20010315_ExclWithCommentsTransformer

use of org.apache.xml.security.stax.impl.transformer.canonicalizer.Canonicalizer20010315_ExclWithCommentsTransformer in project santuario-java by apache.

the class Canonicalizer20010315ExclusiveTest method test221excl.

@org.junit.Test
public void test221excl() throws Exception {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    Canonicalizer20010315_ExclWithCommentsTransformer c = new Canonicalizer20010315_ExclWithCommentsTransformer();
    c.setOutputStream(baos);
    XMLEventReader xmlSecEventReader = xmlInputFactory.createXMLEventReader(this.getClass().getClassLoader().getResourceAsStream("org/apache/xml/security/c14n/inExcl/example2_2_1.xml"));
    XMLSecEvent xmlSecEvent = null;
    while (xmlSecEventReader.hasNext()) {
        xmlSecEvent = (XMLSecEvent) xmlSecEventReader.nextEvent();
        if (xmlSecEvent.isStartElement() && xmlSecEvent.asStartElement().getName().equals(new QName("http://example.net", "elem2"))) {
            break;
        }
    }
    while (xmlSecEventReader.hasNext()) {
        c.transform(xmlSecEvent);
        if (xmlSecEvent.isEndElement() && xmlSecEvent.asEndElement().getName().equals(new QName("http://example.net", "elem2"))) {
            break;
        }
        xmlSecEvent = (XMLSecEvent) xmlSecEventReader.nextEvent();
    }
    byte[] reference = getBytesFromResource(this.getClass().getClassLoader().getResource("org/apache/xml/security/c14n/inExcl/example2_2_c14nized_exclusive.xml"));
    boolean equals = java.security.MessageDigest.isEqual(reference, baos.toByteArray());
    if (!equals) {
        System.out.println("Expected:\n" + new String(reference, java.nio.charset.StandardCharsets.UTF_8));
        System.out.println("");
        System.out.println("Got:\n" + new String(baos.toByteArray(), java.nio.charset.StandardCharsets.UTF_8));
    }
    assertTrue(equals);
}
Also used : QName(javax.xml.namespace.QName) XMLEventReader(javax.xml.stream.XMLEventReader) Canonicalizer20010315_ExclWithCommentsTransformer(org.apache.xml.security.stax.impl.transformer.canonicalizer.Canonicalizer20010315_ExclWithCommentsTransformer) XMLSecEvent(org.apache.xml.security.stax.ext.stax.XMLSecEvent)

Aggregations

QName (javax.xml.namespace.QName)5 Canonicalizer20010315_ExclWithCommentsTransformer (org.apache.xml.security.stax.impl.transformer.canonicalizer.Canonicalizer20010315_ExclWithCommentsTransformer)5 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 XMLEventReader (javax.xml.stream.XMLEventReader)1 Transformer (javax.xml.transform.Transformer)1 TransformerFactory (javax.xml.transform.TransformerFactory)1 DOMSource (javax.xml.transform.dom.DOMSource)1 StreamResult (javax.xml.transform.stream.StreamResult)1 XMLSecEvent (org.apache.xml.security.stax.ext.stax.XMLSecEvent)1 Canonicalizer20010315_ExclOmitCommentsTransformer (org.apache.xml.security.stax.impl.transformer.canonicalizer.Canonicalizer20010315_ExclOmitCommentsTransformer)1 Document (org.w3c.dom.Document)1 Element (org.w3c.dom.Element)1