Class MongoUserDao

java.lang.Object
dev.getelements.elements.dao.mongo.MongoUserDao
All Implemented Interfaces:
UserDao

@Singleton public class MongoUserDao extends Object implements UserDao
MongoDB implementation of UserDao. Created by patricktwohig on 3/26/15.
  • Constructor Details

    • MongoUserDao

      public MongoUserDao()
  • Method Details

    • getUser

      public User getUser(String userId)
      Description copied from interface: UserDao
      Gets the user with the userId. If the user is not active, then this method will behave as if the user does not exist.
      Specified by:
      getUser in interface UserDao
      Parameters:
      userId - the user's as determined by User.getId()
      Returns:
      the active user
    • getMongoUser

      public MongoUser getMongoUser(User user)
    • findMongoUser

      public Optional<MongoUser> findMongoUser(User user)
    • findMongoUser

      public Optional<MongoUser> findMongoUser(String userId)
    • findMongoUser

      public Optional<MongoUser> findMongoUser(org.bson.types.ObjectId userId)
    • getMongoUser

      public MongoUser getMongoUser(String userId)
    • getMongoUser

      public MongoUser getMongoUser(org.bson.types.ObjectId mongoUserId)
    • findUserByNameOrEmail

      public Optional<User> findUserByNameOrEmail(String userNameOrEmail)
      Description copied from interface: UserDao
      Finds a user either by email or name.
      Specified by:
      findUserByNameOrEmail in interface UserDao
      Parameters:
      userNameOrEmail - the username or email
      Returns:
      an Optional<User>
    • getUsers

      public Pagination<User> getUsers(int offset, int count)
      Description copied from interface: UserDao
      Gets a listing of all users given the offset, and count. Additionally, the user requested must be active. Users not active will be treated as if they do not exist.
      Specified by:
      getUsers in interface UserDao
      Parameters:
      offset - the offset
      count - the count
      Returns:
      the users in the system
    • getUsers

      public Pagination<User> getUsers(int offset, int count, String queryString)
      Description copied from interface: UserDao
      Gets a listing of all users given the offset, and count. Additionally, the user requested must be active.
      Specified by:
      getUsers in interface UserDao
      Parameters:
      offset - the offset
      count - the count
      queryString - a query to filter the results
      Returns:
      the users in the system
    • getUsersByPrimaryPhoneNumbers

      public Pagination<User> getUsersByPrimaryPhoneNumbers(int offset, int count, List<String> phones)
      Description copied from interface: UserDao
      Gets a listing of all users given the offset, count and phone number
      Specified by:
      getUsersByPrimaryPhoneNumbers in interface UserDao
      Parameters:
      offset - the offset
      count - the count
      phones - a phone numberto filter the results
      Returns:
      the users in the system
    • createUserStrict

      public User createUserStrict(User user)
      Description copied from interface: UserDao
      Creates a user with the given User object. Using "Strict" semantics, if the user exists then this will throw an exception. The resulting user will have a scrambled password.
      Specified by:
      createUserStrict in interface UserDao
      Parameters:
      user - the user to create
      Returns:
      the User as it was created.
    • createUserWithPasswordStrict

      public User createUserWithPasswordStrict(User user, String password)
      Description copied from interface: UserDao
      Creates a user with the given User object and password. Using "Strict" semantics, if the user exists then this will throw an exception. The resulting user will be assigned the given password.
      Specified by:
      createUserWithPasswordStrict in interface UserDao
      Parameters:
      user - the user to create
      password - the password to assign the user
      Returns:
      the User as it was created.
    • createUserWithPassword

      public User createUserWithPassword(User user, String password)
      Description copied from interface: UserDao
      Creates a user and sets the user's password. If the user exists then this will reinstate the user's account with a new password.
      Specified by:
      createUserWithPassword in interface UserDao
      Parameters:
      user - the user to create
      password - the password for the user to use
      Returns:
      the User, as was written to the database
    • createUser

      public User createUser(User user)
      Description copied from interface: UserDao
      Creates or activates a user, or if the user is currently inactive this will reinstate access. This securely scrambles the user's password and therefore the user must change password at a later date.

      Similar to UserDao.createUserStrict(User) the user will be assigned a scrambled password if the user does not exist (or was previously inactive). This will not touch the user's password if the user both exists and was flagged as active.

      Specified by:
      createUser in interface UserDao
      Parameters:
      user - the user
      Returns:
      the User, as written to the database
    • updateUserStrict

      public User updateUserStrict(User user)
      Description copied from interface: UserDao
      Updates the given user, regardless of active status and then returns the user instance as it was written to the database.

      This will only apply to a User with a UserUid containing a schema with an id prepended with dev.getelements. Other schemas will be assumed to external login methods.

      This does not change the user's password.
      Specified by:
      updateUserStrict in interface UserDao
      Parameters:
      user - the user to update
      Returns:
      the user as was written to the database
    • updateUserStrict

      public User updateUserStrict(User user, String password)
      Description copied from interface: UserDao
      Updates the given user, regardless of active status and then returns the user instance as it was written to the database.

      This will only apply to a User with a UserUid containing a schema with an id prepended with dev.getelements. Other schemas will be assumed to external login methods.

      This will update the user's password.
      Specified by:
      updateUserStrict in interface UserDao
      Parameters:
      user - the user to update
      Returns:
      the user as was written to the database
    • updateUser

      public User updateUser(User user)
      Description copied from interface: UserDao
      Updates the given active user. If the user has been deleted or has been flagged as inactive, then this method will fail.

      This will only apply to a User with a UserUid containing a schema with an id prepended with dev.getelements. Other schemas will be assumed to external login methods.

      This does not change the user's password.
      Specified by:
      updateUser in interface UserDao
      Parameters:
      user - the user to update
      Returns:
      the User as written to the database
    • updateUser

      public User updateUser(User user, String password)
      Description copied from interface: UserDao
      Updates the given active user. If the user has been deleted or has been flagged as inactive, then this method will fail.

      This will only apply to a User with a UserUid containing a schema with an id prepended with dev.getelements. Other schemas will be assumed to external login methods.

      Specified by:
      updateUser in interface UserDao
      Parameters:
      user - the user to update
      password - the user password
      Returns:
      the User, as written to the database
    • updateUser

      public User updateUser(User user, String newPassword, String oldPassword)
      Description copied from interface: UserDao
      Updates the given active user. If the user has been deleted or has been flagged as inactive, then this method will fail.

      This will only apply to a User with a UserUid containing a schema with an id prepended with dev.getelements. Other schemas will be assumed to external login methods.

      Specified by:
      updateUser in interface UserDao
      Parameters:
      user - the user to update
      newPassword - the user's new password
      oldPassword - the user's old password
      Returns:
      the User, as written to the database
    • createOrUpdateUser

      public User createOrUpdateUser(User user)
      Description copied from interface: UserDao
      Creates a user if one does not exist for the provided info or updates a user if one does exist.

      If the user is currently inactive this will reinstate access. This securely scrambles the user's password and therefore the user must change password at a later date.

      Similar to UserDao.createUserStrict(User) the user will be assigned a scrambled password if the user does not exist (or was previously inactive). This will not touch the user's password if the user both exists and was flagged as active.

      Specified by:
      createOrUpdateUser in interface UserDao
      Parameters:
      user - the user
      Returns:
      the User, as written to the database
    • softDeleteUser

      public void softDeleteUser(String userId)
      Description copied from interface: UserDao
      Deletes a user from the database. In actuality, this isn't a true delete, but rather just flags the user as inactive. LazyValue flagged inactive, a user will not show up in any results for active users.
      Specified by:
      softDeleteUser in interface UserDao
      Parameters:
      userId - the user's as determined by User.getId()
    • validate

      public void validate(User user)
    • findUserWithLoginAndPassword

      public Optional<User> findUserWithLoginAndPassword(String userNameOrEmail, String password)
      Description copied from interface: UserDao
      Finds a User given the login credentials and assword. If the password validation fails, then this will return an empty Optional. If the password validation succeeds, then this returns the user that matched.
      Specified by:
      findUserWithLoginAndPassword in interface UserDao
      Parameters:
      userNameOrEmail - the user's name or email address
      password - the password
      Returns:
      the User, never null
    • getDatastore

      public dev.morphia.Datastore getDatastore()
    • setDatastore

      @Inject public void setDatastore(dev.morphia.Datastore datastore)
    • getPasswordEncoding

      public String getPasswordEncoding()
    • setPasswordEncoding

      @Inject public void setPasswordEncoding(@Named("dev.getelements.elements.password.encoding") String passwordEncoding)
    • getValidationHelper

      public ValidationHelper getValidationHelper()
    • setValidationHelper

      @Inject public void setValidationHelper(ValidationHelper validationHelper)
    • getMongoDBUtils

      public MongoDBUtils getMongoDBUtils()
    • setMongoDBUtils

      @Inject public void setMongoDBUtils(MongoDBUtils mongoDBUtils)
    • getDozerMapper

      public MapperRegistry getDozerMapper()
    • setDozerMapper

      @Inject public void setDozerMapper(MapperRegistry dozerMapperRegistry)
    • getMongoPasswordUtils

      public MongoPasswordUtils getMongoPasswordUtils()
    • setMongoPasswordUtils

      @Inject public void setMongoPasswordUtils(MongoPasswordUtils mongoPasswordUtils)
    • getMongoProfileDao

      public MongoProfileDao getMongoProfileDao()
    • setMongoProfileDao

      @Inject public void setMongoProfileDao(MongoProfileDao mongoProfileDao)
    • getMongoUserUidDao

      public MongoUserUidDao getMongoUserUidDao()
    • setMongoUserUidDao

      @Inject public void setMongoUserUidDao(MongoUserUidDao mongoUserUidDao)