use of com.enonic.app.auth0.impl.user.Auth0User in project app-auth0-idprovider by enonic.
the class Auth0LoginService method updateProfile.
private void updateProfile(final Auth0User auth0User, final PrincipalKey principalKey) {
final UpdateUserParams updateUserParams = UpdateUserParams.create().userKey(principalKey).editor(editableUser -> this.updateProfile(editableUser.profile, auth0User)).build();
runAs(() -> securityService.updateUser(updateUserParams), RoleKeys.ADMIN);
}
use of com.enonic.app.auth0.impl.user.Auth0User in project app-auth0-idprovider by enonic.
the class Auth0LoginService method login.
public void login(final HttpServletRequest request, final Auth0User auth0User, final IdProviderKey idProviderKey) {
// Retrieves the user by key
final String userId = auth0User.getUserId().replace('|', '-');
final PrincipalKey principalKey = PrincipalKey.ofUser(idProviderKey, userId);
User user = runAs(() -> securityService.getUser(principalKey), RoleKeys.AUTHENTICATED).orElse(null);
// If the user does not exist with this id
if (user == null && auth0User.getEmail() != null) {
// Retrieves the user by email
final ConstraintExpr constraintExpr = QueryParser.parseCostraintExpression("userstorekey = '" + idProviderKey + "' AND email = '" + auth0User.getEmail() + "'");
final QueryExpr queryExpr = QueryExpr.from(constraintExpr);
final UserQuery userQuery = UserQuery.create().size(1).queryExpr(queryExpr).build();
user = (User) runAs(() -> securityService.query(userQuery), RoleKeys.AUTHENTICATED).getUsers().first();
}
// If the user does not exist
if (user == null) {
// Creates the user
user = createUser(auth0User, principalKey);
}
// Updates the profile
updateProfile(auth0User, user.getKey());
// Authenticates the user
authenticate(request, user.getKey());
}
use of com.enonic.app.auth0.impl.user.Auth0User in project app-auth0-idprovider by enonic.
the class Auth0LoginService method createUser.
private User createUser(final Auth0User auth0User, final PrincipalKey principalKey) {
final String email = auth0User.getEmail();
final String name = auth0User.getName();
final PrincipalKeys defaultPrincipals = configurationService.getDefaultPrincipals(principalKey.getIdProviderKey());
final CreateUserParams createUserParams = CreateUserParams.create().login(principalKey.getId()).displayName(name).email(email).userKey(principalKey).build();
return runAs(() -> {
final User user = securityService.createUser(createUserParams);
for (PrincipalKey defaultPrincipal : defaultPrincipals) {
securityService.addRelationship(PrincipalRelationship.from(defaultPrincipal).to(principalKey));
}
return user;
}, RoleKeys.ADMIN);
}
Aggregations