use of org.opensaml.saml2.core.impl.NameIDImpl 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);
}
}
Aggregations