Search in sources :

Example 1 with SecurityTokenFactory

use of org.apache.xml.security.stax.securityToken.SecurityTokenFactory in project santuario-java by apache.

the class SecurityTokenFactoryImplTest method testKeyNameTokenWithoutKeyInMap.

@Test
public void testKeyNameTokenWithoutKeyInMap() throws Exception {
    expectedException.expect(XMLSecurityException.class);
    expectedException.expectMessage("No key configured for KeyName: mykey");
    SecurityTokenFactory factory = new SecurityTokenFactoryImpl();
    SecurityTokenConstants.KeyUsage keyUsage = SecurityTokenConstants.KeyUsage_Signature_Verification;
    InboundSecurityContext inboundSecurityContext = new InboundSecurityContextImpl();
    factory.getSecurityToken(keyInfoType, keyUsage, xmlSecurityProperties, inboundSecurityContext);
}
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) InboundSecurityContext(org.apache.xml.security.stax.ext.InboundSecurityContext) Test(org.junit.Test)

Example 2 with SecurityTokenFactory

use of org.apache.xml.security.stax.securityToken.SecurityTokenFactory in project santuario-java by apache.

the class SecurityTokenFactoryImplTest method testKeyNameToken.

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

Example 3 with SecurityTokenFactory

use of org.apache.xml.security.stax.securityToken.SecurityTokenFactory in project santuario-java by apache.

the class SecurityTokenFactoryImplTest method testKeyNameTokenWithWrongKeyInMap.

@Test
public void testKeyNameTokenWithWrongKeyInMap() throws Exception {
    expectedException.expect(XMLSecurityException.class);
    expectedException.expectMessage("Key of type DSAPrivateKey not supported for a KeyName lookup");
    SecurityTokenFactory factory = new SecurityTokenFactoryImpl();
    SecurityTokenConstants.KeyUsage keyUsage = SecurityTokenConstants.KeyUsage_Signature_Verification;
    KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DSA", "SUN");
    KeyPair keyPair = keyGen.generateKeyPair();
    Key privateKey = keyPair.getPrivate();
    xmlSecurityProperties.addKeyNameMapping("mykey", privateKey);
    InboundSecurityContext inboundSecurityContext = new InboundSecurityContextImpl();
    factory.getSecurityToken(keyInfoType, keyUsage, xmlSecurityProperties, inboundSecurityContext);
}
Also used : KeyPair(java.security.KeyPair) InboundSecurityContextImpl(org.apache.xml.security.stax.impl.InboundSecurityContextImpl) SecurityTokenFactory(org.apache.xml.security.stax.securityToken.SecurityTokenFactory) SecurityTokenConstants(org.apache.xml.security.stax.securityToken.SecurityTokenConstants) KeyPairGenerator(java.security.KeyPairGenerator) InboundSecurityContext(org.apache.xml.security.stax.ext.InboundSecurityContext) Key(java.security.Key) KeyLoader.loadPublicKey(org.apache.xml.security.test.stax.utils.KeyLoader.loadPublicKey) Test(org.junit.Test)

Example 4 with SecurityTokenFactory

use of org.apache.xml.security.stax.securityToken.SecurityTokenFactory 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

SecurityTokenConstants (org.apache.xml.security.stax.securityToken.SecurityTokenConstants)4 SecurityTokenFactory (org.apache.xml.security.stax.securityToken.SecurityTokenFactory)4 Test (org.junit.Test)4 InboundSecurityContext (org.apache.xml.security.stax.ext.InboundSecurityContext)3 InboundSecurityContextImpl (org.apache.xml.security.stax.impl.InboundSecurityContextImpl)3 InboundSecurityToken (org.apache.xml.security.stax.securityToken.InboundSecurityToken)2 Key (java.security.Key)1 KeyPair (java.security.KeyPair)1 KeyPairGenerator (java.security.KeyPairGenerator)1 KeyLoader.loadPublicKey (org.apache.xml.security.test.stax.utils.KeyLoader.loadPublicKey)1