Search in sources :

Example 1 with SAMLMessageContext

use of org.springframework.security.saml.context.SAMLMessageContext in project pentaho-engineering-samples by pentaho.

the class PentahoSamlLogoutFilter method idpContainsGlobalLogoutEndpoint.

private boolean idpContainsGlobalLogoutEndpoint(HttpServletRequest request, HttpServletResponse response) {
    try {
        SAMLMessageContext ctx = contextProvider.getLocalAndPeerEntity(request, response);
        String binding = SAMLUtil.getLogoutBinding((IDPSSODescriptor) ctx.getPeerEntityRoleMetadata(), (SPSSODescriptor) ctx.getLocalEntityRoleMetadata());
        return (binding != null && !binding.isEmpty());
    } catch (MetadataProviderException e) {
        logger.error(e.getMessage(), e);
    }
    return false;
}
Also used : SAMLMessageContext(org.springframework.security.saml.context.SAMLMessageContext) MetadataProviderException(org.opensaml.saml2.metadata.provider.MetadataProviderException)

Example 2 with SAMLMessageContext

use of org.springframework.security.saml.context.SAMLMessageContext 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

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