Search in sources :

Example 1 with SAMLAuthenticationToken

use of org.springframework.security.saml.SAMLAuthenticationToken in project hub-alert by blackducksoftware.

the class AuthenticationEventManager method sendAuthenticationEvent.

public void sendAuthenticationEvent(Authentication authentication, AuthenticationType authenticationType) {
    String username;
    String emailAddress = null;
    try {
        Object authPrincipal = authentication.getPrincipal();
        if (authentication instanceof SAMLAuthenticationToken) {
            SAMLAuthenticationToken samlAuthenticationToken = (SAMLAuthenticationToken) authentication;
            SAMLMessageContext credentials = samlAuthenticationToken.getCredentials();
            NameIDImpl subjectNameIdentifier = (NameIDImpl) credentials.getSubjectNameIdentifier();
            username = subjectNameIdentifier.getValue();
            emailAddress = username;
        } else if (authPrincipal instanceof InetOrgPerson) {
            username = authentication.getName();
            emailAddress = ((InetOrgPerson) authPrincipal).getMail();
        } else {
            username = authentication.getName();
        }
        sendAuthenticationEvent(username, emailAddress, authenticationType, authentication.getAuthorities());
    } catch (Exception e) {
        logger.warn("Unable to send authentication event");
        logger.debug("Authentication event failure", e);
    }
}
Also used : NameIDImpl(org.opensaml.saml2.core.impl.NameIDImpl) SAMLMessageContext(org.springframework.security.saml.context.SAMLMessageContext) InetOrgPerson(org.springframework.security.ldap.userdetails.InetOrgPerson) SAMLAuthenticationToken(org.springframework.security.saml.SAMLAuthenticationToken) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException)

Aggregations

AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)1 NameIDImpl (org.opensaml.saml2.core.impl.NameIDImpl)1 InetOrgPerson (org.springframework.security.ldap.userdetails.InetOrgPerson)1 SAMLAuthenticationToken (org.springframework.security.saml.SAMLAuthenticationToken)1 SAMLMessageContext (org.springframework.security.saml.context.SAMLMessageContext)1