Search in sources :

Example 6 with InputProcessorChainImpl

use of org.apache.xml.security.stax.impl.InputProcessorChainImpl in project santuario-java by apache.

the class InputProcessorChainTest method testAddProcessorPhase1.

@Test
public void testAddProcessorPhase1() {
    InputProcessorChainImpl inputProcessorChain = new InputProcessorChainImpl(new InboundSecurityContextImpl());
    AbstractInputProcessor inputProcessor1 = new AbstractInputProcessor() {
    };
    inputProcessorChain.addProcessor(inputProcessor1);
    AbstractInputProcessor inputProcessor2 = new AbstractInputProcessor() {
    };
    inputProcessorChain.addProcessor(inputProcessor2);
    AbstractInputProcessor inputProcessor3 = new AbstractInputProcessor() {
    };
    inputProcessorChain.addProcessor(inputProcessor3);
    Assert.assertEquals(inputProcessorChain.getProcessors().get(0), inputProcessor3);
    Assert.assertEquals(inputProcessorChain.getProcessors().get(1), inputProcessor2);
    Assert.assertEquals(inputProcessorChain.getProcessors().get(2), inputProcessor1);
}
Also used : InputProcessorChainImpl(org.apache.xml.security.stax.impl.InputProcessorChainImpl) InboundSecurityContextImpl(org.apache.xml.security.stax.impl.InboundSecurityContextImpl) Test(org.junit.Test)

Example 7 with InputProcessorChainImpl

use of org.apache.xml.security.stax.impl.InputProcessorChainImpl in project santuario-java by apache.

the class InputProcessorChainTest method testAddProcessorBeforeAndAfter1.

@Test
public void testAddProcessorBeforeAndAfter1() {
    InputProcessorChainImpl inputProcessorChain = new InputProcessorChainImpl(new InboundSecurityContextImpl());
    AbstractInputProcessor inputProcessor1 = new AbstractInputProcessor() {
    };
    inputProcessorChain.addProcessor(inputProcessor1);
    AbstractInputProcessor inputProcessor2 = new AbstractInputProcessor() {
    };
    inputProcessorChain.addProcessor(inputProcessor2);
    AbstractInputProcessor inputProcessor3 = new AbstractInputProcessor() {
    };
    inputProcessorChain.addProcessor(inputProcessor3);
    AbstractInputProcessor inputProcessor4 = new AbstractInputProcessor() {
    };
    inputProcessorChain.addProcessor(inputProcessor4);
    AbstractInputProcessor inputProcessor5 = new AbstractInputProcessor() {
    };
    inputProcessor5.addBeforeProcessor("");
    inputProcessor5.addAfterProcessor(inputProcessor3.getClass().getName());
    inputProcessorChain.addProcessor(inputProcessor5);
    AbstractInputProcessor inputProcessor6 = new AbstractInputProcessor() {
    };
    inputProcessor6.addBeforeProcessor(inputProcessor5.getClass().getName());
    inputProcessor6.addAfterProcessor("");
    inputProcessorChain.addProcessor(inputProcessor6);
    Assert.assertEquals(inputProcessorChain.getProcessors().get(0), inputProcessor4);
    Assert.assertEquals(inputProcessorChain.getProcessors().get(1), inputProcessor5);
    Assert.assertEquals(inputProcessorChain.getProcessors().get(2), inputProcessor6);
    Assert.assertEquals(inputProcessorChain.getProcessors().get(3), inputProcessor3);
    Assert.assertEquals(inputProcessorChain.getProcessors().get(4), inputProcessor2);
    Assert.assertEquals(inputProcessorChain.getProcessors().get(5), inputProcessor1);
}
Also used : InputProcessorChainImpl(org.apache.xml.security.stax.impl.InputProcessorChainImpl) InboundSecurityContextImpl(org.apache.xml.security.stax.impl.InboundSecurityContextImpl) Test(org.junit.Test)

Example 8 with InputProcessorChainImpl

use of org.apache.xml.security.stax.impl.InputProcessorChainImpl in project santuario-java by apache.

the class XMLSecurityStreamReaderTest method testIdentityTransformSource.

@Test
public void testIdentityTransformSource() throws Exception {
    XMLSecurityProperties securityProperties = new XMLSecurityProperties();
    InboundSecurityContextImpl securityContext = new InboundSecurityContextImpl();
    InputProcessorChainImpl inputProcessorChain = new InputProcessorChainImpl(securityContext);
    inputProcessorChain.addProcessor(new EventReaderProcessor());
    XMLSecurityStreamReader xmlSecurityStreamReader = new XMLSecurityStreamReader(inputProcessorChain, securityProperties);
    // use the sun internal TransformerFactory since the current xalan version don't know how to handle StaxSources:
    TransformerFactory transformerFactory = TransformerFactory.newInstance("com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl", this.getClass().getClassLoader());
    javax.xml.transform.Transformer transformer = transformerFactory.newTransformer();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    transformer.transform(new StAXSource(xmlSecurityStreamReader), new StreamResult(baos));
    XMLAssert.assertXMLEqual(readTestFile(), baos.toString(StandardCharsets.UTF_8.name()));
}
Also used : InputProcessorChainImpl(org.apache.xml.security.stax.impl.InputProcessorChainImpl) TransformerFactory(javax.xml.transform.TransformerFactory) XMLSecurityStreamReader(org.apache.xml.security.stax.impl.XMLSecurityStreamReader) StreamResult(javax.xml.transform.stream.StreamResult) InboundSecurityContextImpl(org.apache.xml.security.stax.impl.InboundSecurityContextImpl) ByteArrayOutputStream(java.io.ByteArrayOutputStream) StAXSource(javax.xml.transform.stax.StAXSource) Test(org.junit.Test)

Example 9 with InputProcessorChainImpl

use of org.apache.xml.security.stax.impl.InputProcessorChainImpl in project santuario-java by apache.

the class XMLSecurityStreamReaderTest method testPassThroughDocumentEvents.

@Test
public void testPassThroughDocumentEvents() throws Exception {
    XMLSecurityProperties securityProperties = new XMLSecurityProperties();
    securityProperties.setSkipDocumentEvents(false);
    InboundSecurityContextImpl securityContext = new InboundSecurityContextImpl();
    InputProcessorChainImpl inputProcessorChain = new InputProcessorChainImpl(securityContext);
    inputProcessorChain.addProcessor(new EventReaderProcessor());
    XMLSecurityStreamReader xmlSecurityStreamReader = new XMLSecurityStreamReader(inputProcessorChain, securityProperties);
    int event = xmlSecurityStreamReader.next();
    Assert.assertEquals(XMLStreamConstants.START_DOCUMENT, event);
}
Also used : InputProcessorChainImpl(org.apache.xml.security.stax.impl.InputProcessorChainImpl) XMLSecurityStreamReader(org.apache.xml.security.stax.impl.XMLSecurityStreamReader) InboundSecurityContextImpl(org.apache.xml.security.stax.impl.InboundSecurityContextImpl) Test(org.junit.Test)

Example 10 with InputProcessorChainImpl

use of org.apache.xml.security.stax.impl.InputProcessorChainImpl in project santuario-java by apache.

the class XMLSecurityStreamReaderTest method testSkipThroughDocumentEvents.

@Test
public void testSkipThroughDocumentEvents() throws Exception {
    XMLSecurityProperties securityProperties = new XMLSecurityProperties();
    securityProperties.setSkipDocumentEvents(true);
    InboundSecurityContextImpl securityContext = new InboundSecurityContextImpl();
    InputProcessorChainImpl inputProcessorChain = new InputProcessorChainImpl(securityContext);
    inputProcessorChain.addProcessor(new EventReaderProcessor());
    XMLSecurityStreamReader xmlSecurityStreamReader = new XMLSecurityStreamReader(inputProcessorChain, securityProperties);
    int event = xmlSecurityStreamReader.next();
    Assert.assertEquals(XMLStreamConstants.START_ELEMENT, event);
}
Also used : InputProcessorChainImpl(org.apache.xml.security.stax.impl.InputProcessorChainImpl) XMLSecurityStreamReader(org.apache.xml.security.stax.impl.XMLSecurityStreamReader) InboundSecurityContextImpl(org.apache.xml.security.stax.impl.InboundSecurityContextImpl) Test(org.junit.Test)

Aggregations

InboundSecurityContextImpl (org.apache.xml.security.stax.impl.InboundSecurityContextImpl)10 InputProcessorChainImpl (org.apache.xml.security.stax.impl.InputProcessorChainImpl)10 Test (org.junit.Test)9 XMLSecurityStreamReader (org.apache.xml.security.stax.impl.XMLSecurityStreamReader)5 DocumentContextImpl (org.apache.xml.security.stax.impl.DocumentContextImpl)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 Location (javax.xml.stream.Location)1 XMLInputFactory (javax.xml.stream.XMLInputFactory)1 XMLStreamReader (javax.xml.stream.XMLStreamReader)1 TransformerFactory (javax.xml.transform.TransformerFactory)1 StAXSource (javax.xml.transform.stax.StAXSource)1 StreamResult (javax.xml.transform.stream.StreamResult)1 LogInputProcessor (org.apache.xml.security.stax.impl.processor.input.LogInputProcessor)1 XMLEventReaderInputProcessor (org.apache.xml.security.stax.impl.processor.input.XMLEventReaderInputProcessor)1 XMLSecurityInputProcessor (org.apache.xml.security.stax.impl.processor.input.XMLSecurityInputProcessor)1