Search in sources :

Example 11 with InboundSecurityContextImpl

use of org.apache.xml.security.stax.impl.InboundSecurityContextImpl 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 12 with InboundSecurityContextImpl

use of org.apache.xml.security.stax.impl.InboundSecurityContextImpl 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 13 with InboundSecurityContextImpl

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

Example 14 with InboundSecurityContextImpl

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

the class SecurityTokenFactoryImplTest method testKeyNameTokenWithSignatureVerificationKeySet.

@Test
public void testKeyNameTokenWithSignatureVerificationKeySet() throws Exception {
    SecurityTokenFactory factory = new SecurityTokenFactoryImpl();
    SecurityTokenConstants.KeyUsage keyUsage = SecurityTokenConstants.KeyUsage_Signature_Verification;
    xmlSecurityProperties.addKeyNameMapping("mykey", loadPublicKey("dsa.key", "DSA"));
    xmlSecurityProperties.setSignatureVerificationKey(loadPublicKey("rsa.key", "RSA"));
    InboundSecurityContext inboundSecurityContext = new InboundSecurityContextImpl();
    InboundSecurityToken token = factory.getSecurityToken(keyInfoType, keyUsage, xmlSecurityProperties, inboundSecurityContext);
    assertEquals(KeyIdentifier_KeyName, token.getKeyIdentifier());
    assertNotNull(token.getPublicKey());
    assertEquals("RSA", token.getPublicKey().getAlgorithm());
}
Also used : InboundSecurityContextImpl(org.apache.xml.security.stax.impl.InboundSecurityContextImpl) SecurityTokenFactory(org.apache.xml.security.stax.securityToken.SecurityTokenFactory) SecurityTokenConstants(org.apache.xml.security.stax.securityToken.SecurityTokenConstants) InboundSecurityToken(org.apache.xml.security.stax.securityToken.InboundSecurityToken) InboundSecurityContext(org.apache.xml.security.stax.ext.InboundSecurityContext) Test(org.junit.Test)

Aggregations

InboundSecurityContextImpl (org.apache.xml.security.stax.impl.InboundSecurityContextImpl)14 Test (org.junit.Test)12 InputProcessorChainImpl (org.apache.xml.security.stax.impl.InputProcessorChainImpl)10 XMLSecurityStreamReader (org.apache.xml.security.stax.impl.XMLSecurityStreamReader)5 InboundSecurityContext (org.apache.xml.security.stax.ext.InboundSecurityContext)3 SecurityTokenConstants (org.apache.xml.security.stax.securityToken.SecurityTokenConstants)3 SecurityTokenFactory (org.apache.xml.security.stax.securityToken.SecurityTokenFactory)3 DocumentContextImpl (org.apache.xml.security.stax.impl.DocumentContextImpl)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 Key (java.security.Key)1 KeyPair (java.security.KeyPair)1 KeyPairGenerator (java.security.KeyPairGenerator)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 KeyInfoType (org.apache.xml.security.binding.xmldsig.KeyInfoType)1 ObjectFactory (org.apache.xml.security.binding.xmldsig.ObjectFactory)1