Search in sources :

Example 31 with XMLSecEvent

use of org.apache.xml.security.stax.ext.stax.XMLSecEvent 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)

Example 32 with XMLSecEvent

use of org.apache.xml.security.stax.ext.stax.XMLSecEvent in project santuario-java by apache.

the class Canonicalizer20010315Test method test222.

@Test
public void test222() throws Exception {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    Canonicalizer20010315_WithCommentsTransformer c = new Canonicalizer20010315_WithCommentsTransformer();
    c.setOutputStream(baos);
    XMLEventReader xmlSecEventReader = xmlInputFactory.createXMLEventReader(this.getClass().getClassLoader().getResourceAsStream("org/apache/xml/security/c14n/inExcl/example2_2_2.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_2_c14nized.xml"));
    boolean equals = java.security.MessageDigest.isEqual(reference, baos.toByteArray());
    if (!equals) {
        System.out.println("Expected:\n" + new String(reference, StandardCharsets.UTF_8));
        System.out.println("");
        System.out.println("Got:\n" + new String(baos.toByteArray(), StandardCharsets.UTF_8));
    }
    assertTrue(equals);
}
Also used : QName(javax.xml.namespace.QName) Canonicalizer20010315_WithCommentsTransformer(org.apache.xml.security.stax.impl.transformer.canonicalizer.Canonicalizer20010315_WithCommentsTransformer) XMLEventReader(javax.xml.stream.XMLEventReader) ByteArrayOutputStream(java.io.ByteArrayOutputStream) XMLSecEvent(org.apache.xml.security.stax.ext.stax.XMLSecEvent) Test(org.junit.Test)

Example 33 with XMLSecEvent

use of org.apache.xml.security.stax.ext.stax.XMLSecEvent in project santuario-java by apache.

the class Canonicalizer20010315Test method testDefault_ns_redefinition.

@Test
public void testDefault_ns_redefinition() throws Exception {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    Canonicalizer20010315_WithCommentsTransformer c = new Canonicalizer20010315_WithCommentsTransformer();
    c.setOutputStream(baos);
    XMLEventReader xmlSecEventReader = xmlInputFactory.createXMLEventReader(this.getClass().getClassLoader().getResourceAsStream("org/apache/xml/security/c14n/in/default_ns_redefinition_input.xml"));
    XMLSecEvent xmlSecEvent = null;
    while (xmlSecEventReader.hasNext()) {
        xmlSecEvent = (XMLSecEvent) xmlSecEventReader.nextEvent();
        if (xmlSecEvent.isStartElement() && xmlSecEvent.asStartElement().getName().equals(new QName("http://www.w3.org/2000/09/xmldsig#", "Object"))) {
            break;
        }
    }
    while (xmlSecEventReader.hasNext()) {
        c.transform(xmlSecEvent);
        if (xmlSecEvent.isEndElement() && xmlSecEvent.asEndElement().getName().equals(new QName("http://www.w3.org/2000/09/xmldsig#", "Object"))) {
            break;
        }
        xmlSecEvent = (XMLSecEvent) xmlSecEventReader.nextEvent();
    }
    byte[] reference = getBytesFromResource(this.getClass().getClassLoader().getResource("org/apache/xml/security/c14n/in/default_ns_redefinition_c14n.xml"), true);
    boolean equals = java.security.MessageDigest.isEqual(reference, baos.toByteArray());
    if (!equals) {
        System.out.println("Expected:\n" + new String(reference, StandardCharsets.UTF_8));
        System.out.println("");
        System.out.println("Got:\n" + new String(baos.toByteArray(), StandardCharsets.UTF_8));
    }
    assertTrue(equals);
}
Also used : QName(javax.xml.namespace.QName) Canonicalizer20010315_WithCommentsTransformer(org.apache.xml.security.stax.impl.transformer.canonicalizer.Canonicalizer20010315_WithCommentsTransformer) XMLEventReader(javax.xml.stream.XMLEventReader) ByteArrayOutputStream(java.io.ByteArrayOutputStream) XMLSecEvent(org.apache.xml.security.stax.ext.stax.XMLSecEvent) Test(org.junit.Test)

Example 34 with XMLSecEvent

use of org.apache.xml.security.stax.ext.stax.XMLSecEvent in project santuario-java by apache.

the class Canonicalizer20010315Test method test221.

@Test
public void test221() throws Exception {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    Canonicalizer20010315_WithCommentsTransformer c = new Canonicalizer20010315_WithCommentsTransformer();
    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_1_c14nized.xml"));
    boolean equals = java.security.MessageDigest.isEqual(reference, baos.toByteArray());
    if (!equals) {
        System.out.println("Expected:\n" + new String(reference, StandardCharsets.UTF_8));
        System.out.println("");
        System.out.println("Got:\n" + new String(baos.toByteArray(), StandardCharsets.UTF_8));
    }
    assertTrue(equals);
}
Also used : QName(javax.xml.namespace.QName) Canonicalizer20010315_WithCommentsTransformer(org.apache.xml.security.stax.impl.transformer.canonicalizer.Canonicalizer20010315_WithCommentsTransformer) XMLEventReader(javax.xml.stream.XMLEventReader) ByteArrayOutputStream(java.io.ByteArrayOutputStream) XMLSecEvent(org.apache.xml.security.stax.ext.stax.XMLSecEvent) Test(org.junit.Test)

Example 35 with XMLSecEvent

use of org.apache.xml.security.stax.ext.stax.XMLSecEvent in project santuario-java by apache.

the class Santuario191Test method testSantuario191.

@Test
public void testSantuario191() throws Exception {
    // 
    // Parse the Data
    // 
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    Canonicalizer11_OmitCommentsTransformer c = new Canonicalizer11_OmitCommentsTransformer();
    c.setOutputStream(baos);
    XMLEventReader xmlSecEventReader = xmlInputFactory.createXMLEventReader(new StringReader(INPUT_DATA));
    XMLSecEvent xmlSecEvent = null;
    while (xmlSecEventReader.hasNext()) {
        xmlSecEvent = (XMLSecEvent) xmlSecEventReader.nextEvent();
        if (xmlSecEvent.isStartElement() && xmlSecEvent.asStartElement().getName().equals(new QName(null, "data"))) {
            break;
        }
    }
    while (xmlSecEventReader.hasNext()) {
        c.transform(xmlSecEvent);
        if (xmlSecEvent.isEndElement() && xmlSecEvent.asEndElement().getName().equals(new QName(null, "data"))) {
            break;
        }
        xmlSecEvent = (XMLSecEvent) xmlSecEventReader.nextEvent();
    }
    assertEquals(new String(baos.toByteArray(), java.nio.charset.StandardCharsets.UTF_8), EXPECTED_RESULT);
}
Also used : QName(javax.xml.namespace.QName) Canonicalizer11_OmitCommentsTransformer(org.apache.xml.security.stax.impl.transformer.canonicalizer.Canonicalizer11_OmitCommentsTransformer) StringReader(java.io.StringReader) XMLEventReader(javax.xml.stream.XMLEventReader) ByteArrayOutputStream(java.io.ByteArrayOutputStream) XMLSecEvent(org.apache.xml.security.stax.ext.stax.XMLSecEvent) Test(org.junit.Test)

Aggregations

XMLSecEvent (org.apache.xml.security.stax.ext.stax.XMLSecEvent)46 ByteArrayOutputStream (java.io.ByteArrayOutputStream)25 Test (org.junit.Test)25 XMLEventReader (javax.xml.stream.XMLEventReader)22 XMLSecurityConstants (org.apache.xml.security.stax.ext.XMLSecurityConstants)16 InputStream (java.io.InputStream)15 OutputStream (java.io.OutputStream)14 Map (java.util.Map)14 QName (javax.xml.namespace.QName)14 Transformer (org.apache.xml.security.stax.ext.Transformer)14 IOException (java.io.IOException)10 XMLSecurityException (org.apache.xml.security.exceptions.XMLSecurityException)9 XMLStreamException (javax.xml.stream.XMLStreamException)6 Canonicalizer20010315_OmitCommentsTransformer (org.apache.xml.security.stax.impl.transformer.canonicalizer.Canonicalizer20010315_OmitCommentsTransformer)6 ArrayList (java.util.ArrayList)5 TransformBase64Decode (org.apache.xml.security.stax.impl.transformer.TransformBase64Decode)5 TransformIdentity (org.apache.xml.security.stax.impl.transformer.TransformIdentity)5 XMLStreamReader (javax.xml.stream.XMLStreamReader)4 Canonicalizer20010315_WithCommentsTransformer (org.apache.xml.security.stax.impl.transformer.canonicalizer.Canonicalizer20010315_WithCommentsTransformer)4 UnixInputStream (org.apache.xml.security.test.stax.utils.UnixInputStream)4