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);
}
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());
}
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);
}
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());
}
Aggregations