Search in sources :

Example 26 with XMLSecEvent

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

the class TransformCanonicalizerTest method testXMLSecEventToOutputStreamStreamAPI.

@Test
public void testXMLSecEventToOutputStreamStreamAPI() throws Exception {
    Canonicalizer20010315_OmitCommentsTransformer canonicalizerTransformer = new Canonicalizer20010315_OmitCommentsTransformer();
    final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    canonicalizerTransformer.setOutputStream(byteArrayOutputStream);
    XMLEventReader xmlSecEventReader = xmlInputFactory.createXMLEventReader(this.getClass().getClassLoader().getResourceAsStream("ie/baltimore/merlin-examples/merlin-xmlenc-five/plaintext-base64.xml"));
    while (xmlSecEventReader.hasNext()) {
        XMLSecEvent xmlSecEvent = (XMLSecEvent) xmlSecEventReader.nextEvent();
        canonicalizerTransformer.transform(xmlSecEvent);
    }
    canonicalizerTransformer.doFinal();
    Assert.assertEquals(554, byteArrayOutputStream.size());
}
Also used : Canonicalizer20010315_OmitCommentsTransformer(org.apache.xml.security.stax.impl.transformer.canonicalizer.Canonicalizer20010315_OmitCommentsTransformer) XMLEventReader(javax.xml.stream.XMLEventReader) ByteArrayOutputStream(java.io.ByteArrayOutputStream) XMLSecEvent(org.apache.xml.security.stax.ext.stax.XMLSecEvent) Test(org.junit.Test)

Example 27 with XMLSecEvent

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

the class TransformEnvelopedSignatureTest method testXMLSecEventToXMLSecEventAPI.

@Test
public void testXMLSecEventToXMLSecEventAPI() throws Exception {
    TransformEnvelopedSignature transformEnvelopedSignature = new TransformEnvelopedSignature();
    final List<XMLSecEvent> xmlSecEvents = new ArrayList<>();
    Transformer transformer = new Transformer() {

        @Override
        public void setOutputStream(OutputStream outputStream) throws XMLSecurityException {
        }

        @Override
        public void setTransformer(Transformer transformer) throws XMLSecurityException {
        }

        @Override
        public void setProperties(Map<String, Object> properties) throws XMLSecurityException {
        }

        @Override
        public XMLSecurityConstants.TransformMethod getPreferredTransformMethod(XMLSecurityConstants.TransformMethod forInput) {
            return XMLSecurityConstants.TransformMethod.XMLSecEvent;
        }

        @Override
        public void transform(XMLSecEvent xmlSecEvent) throws XMLStreamException {
            xmlSecEvents.add(xmlSecEvent);
        }

        @Override
        public void transform(InputStream inputStream) throws XMLStreamException {
            Assert.fail("unexpected call to transform(InputStream");
        }

        @Override
        public void doFinal() throws XMLStreamException {
        }
    };
    transformEnvelopedSignature.setTransformer(transformer);
    XMLEventReader xmlSecEventReader = xmlInputFactory.createXMLEventReader(this.getClass().getClassLoader().getResourceAsStream("com/phaos/phaos-xmldsig-three/signature-rsa-enveloped.xml"));
    while (xmlSecEventReader.hasNext()) {
        XMLSecEvent xmlSecEvent = (XMLSecEvent) xmlSecEventReader.nextEvent();
        transformEnvelopedSignature.transform(xmlSecEvent);
    }
    transformEnvelopedSignature.doFinal();
    Assert.assertEquals(19, xmlSecEvents.size());
}
Also used : XMLSecurityConstants(org.apache.xml.security.stax.ext.XMLSecurityConstants) Transformer(org.apache.xml.security.stax.ext.Transformer) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ArrayList(java.util.ArrayList) TransformEnvelopedSignature(org.apache.xml.security.stax.impl.transformer.TransformEnvelopedSignature) XMLEventReader(javax.xml.stream.XMLEventReader) Map(java.util.Map) XMLSecEvent(org.apache.xml.security.stax.ext.stax.XMLSecEvent) Test(org.junit.Test)

Example 28 with XMLSecEvent

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

the class TransformIdentityTest method testInputStreamToXMLSecEventAPI.

@Test
public void testInputStreamToXMLSecEventAPI() throws Exception {
    TransformIdentity transformIdentity = new TransformIdentity();
    final List<XMLSecEvent> xmlSecEvents = new ArrayList<>();
    Transformer transformer = new Transformer() {

        @Override
        public void setOutputStream(OutputStream outputStream) throws XMLSecurityException {
        }

        @Override
        public void setTransformer(Transformer transformer) throws XMLSecurityException {
        }

        @Override
        public void setProperties(Map<String, Object> properties) throws XMLSecurityException {
        }

        @Override
        public XMLSecurityConstants.TransformMethod getPreferredTransformMethod(XMLSecurityConstants.TransformMethod forInput) {
            return XMLSecurityConstants.TransformMethod.XMLSecEvent;
        }

        @Override
        public void transform(XMLSecEvent xmlSecEvent) throws XMLStreamException {
            xmlSecEvents.add(xmlSecEvent);
        }

        @Override
        public void transform(InputStream inputStream) throws XMLStreamException {
            Assert.fail("unexpected call to transform(InputStream");
        }

        @Override
        public void doFinal() throws XMLStreamException {
        }
    };
    transformIdentity.setTransformer(transformer);
    transformIdentity.transform(new UnixInputStream(this.getClass().getClassLoader().getResourceAsStream("ie/baltimore/merlin-examples/merlin-xmlenc-five/plaintext-base64.xml")));
    transformIdentity.doFinal();
    Assert.assertEquals(25, xmlSecEvents.size());
}
Also used : XMLSecurityConstants(org.apache.xml.security.stax.ext.XMLSecurityConstants) TransformIdentity(org.apache.xml.security.stax.impl.transformer.TransformIdentity) Transformer(org.apache.xml.security.stax.ext.Transformer) UnixInputStream(org.apache.xml.security.test.stax.utils.UnixInputStream) UnixInputStream(org.apache.xml.security.test.stax.utils.UnixInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ArrayList(java.util.ArrayList) Map(java.util.Map) XMLSecEvent(org.apache.xml.security.stax.ext.stax.XMLSecEvent) Test(org.junit.Test)

Example 29 with XMLSecEvent

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

the class TransformIdentityTest method testInputStreamToInputStreamAPI.

@Test
public void testInputStreamToInputStreamAPI() throws Exception {
    TransformIdentity transformIdentity = new TransformIdentity();
    final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    Transformer transformer = new Transformer() {

        @Override
        public void setOutputStream(OutputStream outputStream) throws XMLSecurityException {
        }

        @Override
        public void setTransformer(Transformer transformer) throws XMLSecurityException {
        }

        @Override
        public void setProperties(Map<String, Object> properties) throws XMLSecurityException {
        }

        @Override
        public XMLSecurityConstants.TransformMethod getPreferredTransformMethod(XMLSecurityConstants.TransformMethod forInput) {
            return XMLSecurityConstants.TransformMethod.InputStream;
        }

        @Override
        public void transform(XMLSecEvent xmlSecEvent) throws XMLStreamException {
            Assert.fail("unexpected call to transform(XMLSecEvent");
        }

        @Override
        public void transform(InputStream inputStream) throws XMLStreamException {
            try {
                XMLSecurityUtils.copy(inputStream, byteArrayOutputStream);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        @Override
        public void doFinal() throws XMLStreamException {
        }
    };
    transformIdentity.setTransformer(transformer);
    transformIdentity.transform(this.getClass().getClassLoader().getResourceAsStream("ie/baltimore/merlin-examples/merlin-xmlenc-five/base64.xml"));
    transformIdentity.doFinal();
    Assert.assertEquals(831, byteArrayOutputStream.size());
}
Also used : XMLSecurityConstants(org.apache.xml.security.stax.ext.XMLSecurityConstants) TransformIdentity(org.apache.xml.security.stax.impl.transformer.TransformIdentity) Transformer(org.apache.xml.security.stax.ext.Transformer) UnixInputStream(org.apache.xml.security.test.stax.utils.UnixInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) Map(java.util.Map) XMLSecEvent(org.apache.xml.security.stax.ext.stax.XMLSecEvent) Test(org.junit.Test)

Example 30 with XMLSecEvent

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

the class Canonicalizer20010315ExclusiveTest method canonicalize.

private void canonicalize(Canonicalizer20010315_Excl c, XMLEventReader xmlEventReader, QName elementName) throws XMLStreamException {
    XMLSecEvent xmlSecEvent = null;
    while (xmlEventReader.hasNext()) {
        xmlSecEvent = (XMLSecEvent) xmlEventReader.nextEvent();
        if (xmlSecEvent.isStartElement() && xmlSecEvent.asStartElement().getName().equals(elementName)) {
            break;
        }
    }
    while (xmlEventReader.hasNext()) {
        c.transform(xmlSecEvent);
        if (xmlSecEvent.isEndElement() && xmlSecEvent.asEndElement().getName().equals(elementName)) {
            break;
        }
        xmlSecEvent = (XMLSecEvent) xmlEventReader.nextEvent();
    }
}
Also used : XMLSecEvent(org.apache.xml.security.stax.ext.stax.XMLSecEvent)

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