use of com.walmartlabs.concord.server.security.UserPrincipal in project concord by walmartlabs.
the class OidcRealm method doGetAuthenticationInfo.
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
OidcToken t = (OidcToken) token;
OidcProfile profile = t.getProfile();
// TODO replace getOrCreate+update with a single method?
String username = profile.getEmail().toLowerCase();
UserEntry u = userManager.getOrCreate(username, null, UserType.LOCAL).orElseThrow(() -> new ConcordApplicationException("User not found: " + profile.getEmail()));
userManager.update(u.getId(), profile.getDisplayName(), profile.getEmail(), null, false, null);
UserPrincipal userPrincipal = new UserPrincipal(REALM_NAME, u);
return new SimpleAccount(Arrays.asList(userPrincipal, t), t, getName());
}
use of com.walmartlabs.concord.server.security.UserPrincipal in project concord by walmartlabs.
the class SsoRealm method doGetAuthenticationInfo.
@Override
@WithTimer
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
SsoToken t = (SsoToken) token;
if (t.getUsername() == null) {
return null;
}
UserEntry u = userManager.get(t.getUsername(), t.getDomain(), UserType.LDAP).orElse(null);
if (u == null) {
u = userManager.create(t.getUsername(), t.getDomain(), t.getDisplayName(), t.getMail(), UserType.SSO, null);
}
// we consider the account active if the authentication was successful
userManager.enable(u.getId());
auditLog.add(AuditObject.SYSTEM, AuditAction.ACCESS).userId(u.getId()).field("username", u.getName()).field("userDomain", u.getDomain()).field("realm", REALM_NAME).log();
UserPrincipal userPrincipal = new UserPrincipal(REALM_NAME, u);
LdapPrincipal ldapPrincipal = new LdapPrincipal(t.getUsername(), t.getDomain(), t.getNameInNamespace(), t.getUserPrincipalName(), t.getDisplayName(), t.getMail(), t.getGroups(), Collections.singletonMap("mail", t.getMail()));
return new SimpleAccount(Arrays.asList(userPrincipal, t, ldapPrincipal), t.getCredentials(), getName());
}
Aggregations