Search in sources :

Example 1 with DefaultTokenSecurityEvent

use of org.apache.xml.security.stax.securityEvent.DefaultTokenSecurityEvent in project santuario-java by apache.

the class BaltimoreTest method checkSignatureToken.

private void checkSignatureToken(TestSecurityEventListener securityEventListener, Key key, SecurityTokenConstants.KeyIdentifier keyIdentifier) throws XMLSecurityException {
    if (SecurityTokenConstants.KeyIdentifier_KeyValue.equals(keyIdentifier)) {
    // NOPMD
    } 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);
        if (key instanceof SecretKey) {
            Key processedKey = tokenEvent.getSecurityToken().getSecretKey().values().iterator().next();
            assertEquals(processedKey, key);
        } else {
            Key processedKey = tokenEvent.getSecurityToken().getPublicKey();
            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_X509SubjectName.equals(keyIdentifier)) {
            Key processedKey = x509SecurityToken.getPublicKey();
            assertEquals(processedKey, key);
            assertNotNull(((X509SubjectNameSecurityToken) x509SecurityToken).getSubjectName());
        } else if (SecurityTokenConstants.KeyIdentifier_IssuerSerial.equals(keyIdentifier)) {
            Key processedKey = x509SecurityToken.getPublicKey();
            assertEquals(processedKey, key);
            assertNotNull(((X509IssuerSerialSecurityToken) x509SecurityToken).getIssuerName());
            assertNotNull(((X509IssuerSerialSecurityToken) x509SecurityToken).getSerialNumber());
        }
    }
}
Also used : SecretKey(javax.crypto.SecretKey) DefaultTokenSecurityEvent(org.apache.xml.security.stax.securityEvent.DefaultTokenSecurityEvent) X509SecurityToken(org.apache.xml.security.stax.impl.securityToken.X509SecurityToken) KeyNameTokenSecurityEvent(org.apache.xml.security.stax.securityEvent.KeyNameTokenSecurityEvent) X509TokenSecurityEvent(org.apache.xml.security.stax.securityEvent.X509TokenSecurityEvent) X509IssuerSerialSecurityToken(org.apache.xml.security.stax.impl.securityToken.X509IssuerSerialSecurityToken) Key(java.security.Key) SecretKey(javax.crypto.SecretKey) PublicKey(java.security.PublicKey)

Example 2 with DefaultTokenSecurityEvent

use of org.apache.xml.security.stax.securityEvent.DefaultTokenSecurityEvent in project santuario-java by apache.

the class IAIKTest method checkSignatureToken.

private void checkSignatureToken(TestSecurityEventListener securityEventListener, Key key, SecurityTokenConstants.KeyIdentifier keyIdentifier) throws XMLSecurityException {
    if (SecurityTokenConstants.KeyIdentifier_KeyValue.equals(keyIdentifier)) {
    // NOPMD
    } 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_X509SubjectName.equals(keyIdentifier)) {
            Key processedKey = x509SecurityToken.getPublicKey();
            assertEquals(processedKey, key);
            assertNotNull(((X509SubjectNameSecurityToken) x509SecurityToken).getSubjectName());
        } else if (SecurityTokenConstants.KeyIdentifier_IssuerSerial.equals(keyIdentifier)) {
            Key processedKey = x509SecurityToken.getPublicKey();
            assertEquals(processedKey, key);
            assertNotNull(((X509IssuerSerialSecurityToken) x509SecurityToken).getIssuerName());
            assertNotNull(((X509IssuerSerialSecurityToken) x509SecurityToken).getSerialNumber());
        }
    }
}
Also used : DefaultTokenSecurityEvent(org.apache.xml.security.stax.securityEvent.DefaultTokenSecurityEvent) X509SecurityToken(org.apache.xml.security.stax.impl.securityToken.X509SecurityToken) KeyNameTokenSecurityEvent(org.apache.xml.security.stax.securityEvent.KeyNameTokenSecurityEvent) X509TokenSecurityEvent(org.apache.xml.security.stax.securityEvent.X509TokenSecurityEvent) X509IssuerSerialSecurityToken(org.apache.xml.security.stax.impl.securityToken.X509IssuerSerialSecurityToken) PublicKey(java.security.PublicKey) Key(java.security.Key) SecretKey(javax.crypto.SecretKey)

Example 3 with DefaultTokenSecurityEvent

use of org.apache.xml.security.stax.securityEvent.DefaultTokenSecurityEvent in project santuario-java by apache.

the class DecryptionTest method checkEncryptionToken.

protected void checkEncryptionToken(TestSecurityEventListener securityEventListener, X509Certificate cert, Key key, SecurityTokenConstants.KeyIdentifier keyIdentifier, String algorithm) throws XMLSecurityException {
    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_EncryptedKey.equals(keyIdentifier)) {
        EncryptedKeyTokenSecurityEvent tokenEvent = (EncryptedKeyTokenSecurityEvent) securityEventListener.getSecurityEvent(SecurityEventConstants.EncryptedKeyToken);
        assertNotNull(tokenEvent);
        Key processedKey = tokenEvent.getSecurityToken().getSecretKey().values().iterator().next();
        assertEquals(processedKey, key);
    }
}
Also used : DefaultTokenSecurityEvent(org.apache.xml.security.stax.securityEvent.DefaultTokenSecurityEvent) EncryptedKeyTokenSecurityEvent(org.apache.xml.security.stax.securityEvent.EncryptedKeyTokenSecurityEvent) Key(java.security.Key) PrivateKey(java.security.PrivateKey) SecretKey(javax.crypto.SecretKey) PublicKey(java.security.PublicKey) EncryptedKey(org.apache.xml.security.encryption.EncryptedKey)

Aggregations

Key (java.security.Key)3 PublicKey (java.security.PublicKey)3 SecretKey (javax.crypto.SecretKey)3 DefaultTokenSecurityEvent (org.apache.xml.security.stax.securityEvent.DefaultTokenSecurityEvent)3 X509IssuerSerialSecurityToken (org.apache.xml.security.stax.impl.securityToken.X509IssuerSerialSecurityToken)2 X509SecurityToken (org.apache.xml.security.stax.impl.securityToken.X509SecurityToken)2 KeyNameTokenSecurityEvent (org.apache.xml.security.stax.securityEvent.KeyNameTokenSecurityEvent)2 X509TokenSecurityEvent (org.apache.xml.security.stax.securityEvent.X509TokenSecurityEvent)2 PrivateKey (java.security.PrivateKey)1 EncryptedKey (org.apache.xml.security.encryption.EncryptedKey)1 EncryptedKeyTokenSecurityEvent (org.apache.xml.security.stax.securityEvent.EncryptedKeyTokenSecurityEvent)1