Search in sources :

Example 1 with X509SubjectNameSecurityToken

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

the class AbstractSignatureVerificationTest method checkSignatureToken.

protected void checkSignatureToken(TestSecurityEventListener securityEventListener, X509Certificate cert, Key key, SecurityTokenConstants.KeyIdentifier keyIdentifier) throws XMLSecurityException {
    if (SecurityTokenConstants.KeyIdentifier_KeyValue.equals(keyIdentifier)) {
        KeyValueTokenSecurityEvent tokenEvent = (KeyValueTokenSecurityEvent) securityEventListener.getSecurityEvent(SecurityEventConstants.KeyValueToken);
        assertNotNull(tokenEvent);
    } else if (SecurityTokenConstants.KeyIdentifier_NoKeyInfo.equals(keyIdentifier)) {
        DefaultTokenSecurityEvent tokenEvent = (DefaultTokenSecurityEvent) securityEventListener.getSecurityEvent(SecurityEventConstants.DefaultToken);
        assertNotNull(tokenEvent);
        Key processedKey = tokenEvent.getSecurityToken().getSecretKey().values().iterator().next();
        assertEquals(processedKey, key);
    } else if (SecurityTokenConstants.KeyIdentifier_KeyName.equals(keyIdentifier)) {
        KeyNameTokenSecurityEvent tokenEvent = (KeyNameTokenSecurityEvent) securityEventListener.getSecurityEvent(SecurityEventConstants.KeyNameToken);
        assertNotNull(tokenEvent);
        Key processedKey = tokenEvent.getSecurityToken().getSecretKey().values().iterator().next();
        assertEquals(processedKey, key);
        assertNotNull(((KeyNameSecurityToken) tokenEvent.getSecurityToken()).getKeyName());
    } else {
        X509TokenSecurityEvent tokenEvent = (X509TokenSecurityEvent) securityEventListener.getSecurityEvent(SecurityEventConstants.X509Token);
        assertNotNull(tokenEvent);
        X509SecurityToken x509SecurityToken = (X509SecurityToken) tokenEvent.getSecurityToken();
        assertNotNull(x509SecurityToken);
        if (SecurityTokenConstants.KeyIdentifier_X509KeyIdentifier.equals(keyIdentifier)) {
            assertEquals(cert, x509SecurityToken.getX509Certificates()[0]);
        } else if (SecurityTokenConstants.KeyIdentifier_X509SubjectName.equals(keyIdentifier)) {
            Key processedKey = x509SecurityToken.getPublicKey();
            assertEquals(processedKey, cert.getPublicKey());
            assertNotNull(((X509SubjectNameSecurityToken) x509SecurityToken).getSubjectName());
        } else if (SecurityTokenConstants.KeyIdentifier_IssuerSerial.equals(keyIdentifier)) {
            Key processedKey = x509SecurityToken.getPublicKey();
            assertEquals(processedKey, cert.getPublicKey());
            assertNotNull(((X509IssuerSerialSecurityToken) x509SecurityToken).getIssuerName());
            assertNotNull(((X509IssuerSerialSecurityToken) x509SecurityToken).getSerialNumber());
        }
    }
}
Also used : X509SubjectNameSecurityToken(org.apache.xml.security.stax.impl.securityToken.X509SubjectNameSecurityToken) X509SecurityToken(org.apache.xml.security.stax.impl.securityToken.X509SecurityToken) Key(java.security.Key)

Aggregations

Key (java.security.Key)1 X509SecurityToken (org.apache.xml.security.stax.impl.securityToken.X509SecurityToken)1 X509SubjectNameSecurityToken (org.apache.xml.security.stax.impl.securityToken.X509SubjectNameSecurityToken)1