Class UserManager


  • public final class UserManager
    extends java.lang.Object
    Manages all user accounts in the database.
    Since:
    1.4.0
    • Constructor Summary

      Constructors 
      Constructor Description
      UserManager​(Database db)
      Creates a new instance of the User Manager.
      UserManager​(Database db, java.lang.String appIconPath)
      Creates a new instance of the User Manager.
      UserManager​(Database db, java.lang.String appIconPath, java.lang.String programName)
      Creates a new instance of the User Manager.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean checkPasswordMatches​(java.lang.String username, java.lang.String password)
      Checks to see if the specified password matches the stored password in the database.
      java.lang.Object clone()  
      boolean createUser​(java.lang.String username, java.lang.String password, UserRoleManager.SystemUserRoles userRole)
      Creates a new user in the database using BCrypt password hashing.
      boolean createUser​(java.lang.String username, java.lang.String password, java.lang.String userRole)
      Creates a new user in the database using BCrypt password hashing.
      boolean deleteUser​(java.lang.String username)
      Deletes the specified user.
      boolean disablePasswordExpiration​(java.lang.String username)
      Disables the specified user's password expiration.
      java.lang.String getAppIconPath()
      Returns the path to the icon to use for all dialogs.
      java.lang.String getProgramName()
      Returns the program name to use for all dialogs.
      SessionManager getSessionManager()
      Returns an instance of the SessionManager for login use.
      UserAccount getUser​(java.lang.String username)
      Returns a UserAccount object representing the specified username.
      java.util.HashSet<java.lang.String> getUsernameList()
      Returns a list of the user names in the database.
      UserRole getUserRole​(java.lang.String username)
      Returns user role for the specified username.
      java.util.HashSet<UserAccount> getUsersList()
      Returns a list of user accounts.
      void setAppIconPath​(java.lang.String appIconPath)
      Sets the path to the icon to use for all dialogs.
      boolean setLockStatus​(java.lang.String username, java.lang.Boolean status)
      Sets the lock status for the specified user.
      boolean setPassword​(java.lang.String username, java.lang.String password)
      Sets a new password for an existing user using BCrypt password hashing.
      boolean setPasswordExpirationDate​(java.lang.String username, java.time.LocalDateTime date)
      Sets the specified user's password expiration date.
      void setProgramName​(java.lang.String programName)
      Sets the program name to use for all dialogs.
      boolean setUserRole​(java.lang.String username, UserRoleManager.SystemUserRoles userRole)
      Sets the user role of the specified user.
      boolean setUserRole​(java.lang.String username, java.lang.String userRole)
      Sets the user role of the specified user.
      boolean userExists​(java.lang.String username)
      Checks if the specified username exists in the database.
      • Methods inherited from class java.lang.Object

        equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • UserManager

        public UserManager​(Database db)
        Creates a new instance of the User Manager.
        Parameters:
        db - the database to use
        Throws:
        java.lang.IllegalArgumentException - if db is null
        UserManagerException - if an error occurs while creating the users table
      • UserManager

        public UserManager​(Database db,
                           java.lang.String appIconPath)
        Creates a new instance of the User Manager.
        Parameters:
        db - the database to use
        appIconPath - the path to the icon to use for all dialogs
        Throws:
        java.lang.IllegalArgumentException - if db is null
        UserManagerException - if an error occurs while creating the users table
      • UserManager

        public UserManager​(Database db,
                           java.lang.String appIconPath,
                           java.lang.String programName)
        Creates a new instance of the User Manager.
        Parameters:
        db - the database to use
        appIconPath - the path to the icon to use for all dialogs
        programName - the program name to use for all dialogs
        Throws:
        java.lang.IllegalArgumentException - if db is null
        UserManagerException - if an error occurs while creating the users table
    • Method Detail

      • createUser

        public boolean createUser​(java.lang.String username,
                                  java.lang.String password,
                                  UserRoleManager.SystemUserRoles userRole)
        Creates a new user in the database using BCrypt password hashing.
        Parameters:
        username - the username to add
        password - the password for the new user
        userRole - the system user role for the new user
        Returns:
        true if user creation is successful
        Throws:
        java.lang.IllegalArgumentException - if values are null or empty
        TableNotFoundException - if users table is missing
        UserManagerException - if an error occurs while creating the user
        PasswordHashingFailedException - if an error occurs while hashing the password
      • createUser

        public boolean createUser​(java.lang.String username,
                                  java.lang.String password,
                                  java.lang.String userRole)
        Creates a new user in the database using BCrypt password hashing.
        Parameters:
        username - the username to add
        password - the password for the new user
        userRole - the name of the user role for the new user
        Returns:
        true if user creation is successful
        Throws:
        java.lang.IllegalArgumentException - if values are null or empty
        TableNotFoundException - if users table is missing
        UserManagerException - if an error occurs while creating the user
        PasswordHashingFailedException - if an error occurs while hashing the password
      • deleteUser

        public boolean deleteUser​(java.lang.String username)
        Deletes the specified user.
        Parameters:
        username - the username of the user to delete
        Returns:
        true if no errors occur
        Throws:
        java.lang.IllegalArgumentException - if username is null or empty
        TableNotFoundException - if users table is missing
        UserManagerException - if an error occurs while deleting user
      • getUser

        public UserAccount getUser​(java.lang.String username)
        Returns a UserAccount object representing the specified username.
        Parameters:
        username - the username to lookup
        Returns:
        a UserAccount object representing the specified username
        Throws:
        java.lang.IllegalArgumentException - if username is null or empty
        TableNotFoundException - if users table is missing
        UserManagerException - if an error occurs during lookup
      • userExists

        public boolean userExists​(java.lang.String username)
        Checks if the specified username exists in the database.
        Parameters:
        username - the username to check
        Returns:
        true if the user exists
        Throws:
        java.lang.IllegalArgumentException - if username is null or empty
        TableNotFoundException - if users table is missing
        UserManagerException - if an error occurs during lookup
      • getUserRole

        public UserRole getUserRole​(java.lang.String username)
        Returns user role for the specified username.
        Parameters:
        username - the username to lookup
        Returns:
        the user role
        Throws:
        java.lang.IllegalArgumentException - if username is null or empty or if username does not exist
        TableNotFoundException - if users table is missing
        UserManagerException - if error occurs during lookup
      • setUserRole

        public boolean setUserRole​(java.lang.String username,
                                   UserRoleManager.SystemUserRoles userRole)
        Sets the user role of the specified user.
        Parameters:
        username - the username of the user to update
        userRole - the system user role to change to
        Returns:
        true if no errors occurred
        Throws:
        java.lang.IllegalArgumentException - if values are null or empty
        TableNotFoundException - if users table is missing
        UserManagerException - if an error occurs while changing user role
      • setUserRole

        public boolean setUserRole​(java.lang.String username,
                                   java.lang.String userRole)
        Sets the user role of the specified user.
        Parameters:
        username - the username of the user to update
        userRole - the name of the user role to change to
        Returns:
        true if no errors occurred
        Throws:
        java.lang.IllegalArgumentException - if values are null or empty
        TableNotFoundException - if users table is missing
        UserManagerException - if an error occurs while changing user role
      • setPassword

        public boolean setPassword​(java.lang.String username,
                                   java.lang.String password)
        Sets a new password for an existing user using BCrypt password hashing.
        Parameters:
        username - the username to change
        password - the new password
        Returns:
        true if password is changed successfully
        Throws:
        java.lang.IllegalArgumentException - if values are null or empty
        TableNotFoundException - if users table is missing
        UserManagerException - if an error occurs while changing password
        PasswordHashingFailedException - if an error occurs while hashing the password
      • setLockStatus

        public boolean setLockStatus​(java.lang.String username,
                                     java.lang.Boolean status)
        Sets the lock status for the specified user.
        Parameters:
        username - the username to change
        status - the status to set
        Returns:
        true if the status is changed successfully
        Throws:
        java.lang.IllegalArgumentException - if values are null or empty
        TableNotFoundException - if users table is missing
        UserManagerException - if an error occurs while changing password
        PasswordHashingFailedException - if an error occurs while hashing the password
        Since:
        1.5.0
      • disablePasswordExpiration

        public boolean disablePasswordExpiration​(java.lang.String username)
        Disables the specified user's password expiration.
        Parameters:
        username - the username to change
        Returns:
        true if password expiration disabled successfully
        Throws:
        java.lang.IllegalArgumentException - if the username is null or empty
        TableNotFoundException - if users table is missing
        UserManagerException - if an error occurs while changing password
        PasswordHashingFailedException - if an error occurs while hashing the password
        Since:
        1.5.0
      • setPasswordExpirationDate

        public boolean setPasswordExpirationDate​(java.lang.String username,
                                                 java.time.LocalDateTime date)
        Sets the specified user's password expiration date.
        Parameters:
        username - the username to change
        date - the date to set
        Returns:
        true if the date is changed successfully
        Throws:
        java.lang.IllegalArgumentException - if values are null or empty
        TableNotFoundException - if users table is missing
        UserManagerException - if an error occurs while changing password
        PasswordHashingFailedException - if an error occurs while hashing the password
        Since:
        1.5.0
      • checkPasswordMatches

        public boolean checkPasswordMatches​(java.lang.String username,
                                            java.lang.String password)
        Checks to see if the specified password matches the stored password in the database.
        Parameters:
        username - the username to check against
        password - the password to check against
        Returns:
        true if the passwords match
        Throws:
        java.lang.IllegalArgumentException - if values are null or empty or if username does not exist
        TableNotFoundException - if users table is missing
        UserManagerException - if an error occurs during lookup
        PasswordHashingFailedException - if an error occurs while hashing the password
      • getUsersList

        public java.util.HashSet<UserAccount> getUsersList()
        Returns a list of user accounts.
        Returns:
        a HashSet of UserAccount objects representing the users in the users table
        Throws:
        TableNotFoundException - if users table is missing
        UserManagerException - if an error occurs during lookup
      • getUsernameList

        public java.util.HashSet<java.lang.String> getUsernameList()
        Returns a list of the user names in the database.
        Returns:
        a list of the user names in the database
        Throws:
        TableNotFoundException - if users table is missing
      • getSessionManager

        public SessionManager getSessionManager()
        Returns an instance of the SessionManager for login use.
        Returns:
        an instance of the SessionManager
      • getAppIconPath

        public java.lang.String getAppIconPath()
        Returns the path to the icon to use for all dialogs.
        Returns:
        the path to the icon to use for all dialogs
      • setAppIconPath

        public void setAppIconPath​(java.lang.String appIconPath)
        Sets the path to the icon to use for all dialogs.
        Parameters:
        appIconPath - the path to set
      • getProgramName

        public java.lang.String getProgramName()
        Returns the program name to use for all dialogs.
        Returns:
        the program name to use for all dialogs
      • setProgramName

        public void setProgramName​(java.lang.String programName)
        Sets the program name to use for all dialogs.
        Parameters:
        programName - the program name to set
      • clone

        @Contract(" -> fail")
        public java.lang.Object clone()
                               throws java.lang.CloneNotSupportedException
        Overrides:
        clone in class java.lang.Object
        Throws:
        java.lang.CloneNotSupportedException