Пример #1
0
  public void merge(final User otherUser) {
    for (final LinkedAccount acc : otherUser.linkedAccounts) {
      this.linkedAccounts.add(LinkedAccount.create(acc));
    }
    // do all other merging stuff here - like resources, etc.

    // deactivate the merged user that got added to this one
    otherUser.active = false;
    MorphiaObject.datastore.save(otherUser);
    MorphiaObject.datastore.save(this);
  }
Пример #2
0
 public void changePassword(final UsernamePasswordAuthUser authUser, final boolean create) {
   LinkedAccount a = this.getAccountByProvider(authUser.getProvider());
   if (a == null) {
     if (create) {
       a = LinkedAccount.create(authUser);
     } else {
       throw new RuntimeException("Account not enabled for password usage");
     }
   }
   a.providerUserId = authUser.getHashedPassword();
   this.linkedAccounts.add(a);
   MorphiaObject.datastore.save(this);
 }
Пример #3
0
  public static User create(final AuthUser authUser) {
    final User user = new User();
    user.roles =
        Collections.singletonList(SecurityRole.findByRoleName(controllers.Application.USER_ROLE));
    // user.permissions = new ArrayList<UserPermission>();
    // user.permissions.add(UserPermission.findByValue("printers.edit"));
    user.active = true;
    user.lastLogin = new Date();
    user.linkedAccounts = Collections.singletonList(LinkedAccount.create(authUser));

    if (authUser instanceof EmailIdentity) {
      final EmailIdentity identity = (EmailIdentity) authUser;
      // Remember, even when getting them from FB & Co., emails should be
      // verified within the application as a security breach there might
      // break your security as well!
      user.email = identity.getEmail();
      user.emailValidated = false;
    }

    if (authUser instanceof NameIdentity) {
      final NameIdentity identity = (NameIdentity) authUser;
      final String name = identity.getName();
      if (name != null) {
        user.name = name;
      }
    }

    if (authUser instanceof FirstLastNameIdentity) {
      final FirstLastNameIdentity identity = (FirstLastNameIdentity) authUser;
      final String firstName = identity.getFirstName();
      final String lastName = identity.getLastName();
      if (firstName != null) {
        user.firstName = firstName;
      }
      if (lastName != null) {
        user.lastName = lastName;
      }
    }

    MorphiaObject.datastore.save(user);

    // user.saveManyToManyAssociations("roles");
    // user.saveManyToManyAssociations("permissions");
    return user;
  }
Пример #4
0
 public static void addLinkedAccount(final AuthUser oldUser, final AuthUser newUser) {
   final User u = User.findByAuthUserIdentity(oldUser);
   u.linkedAccounts.add(LinkedAccount.create(newUser));
   MorphiaObject.datastore.save(u);
 }