Class BasicUserManager

  • All Implemented Interfaces:
    IUserManager, SnapshotProcessor
    Direct Known Subclasses:
    LocalFileUserManager

    public abstract class BasicUserManager
    extends java.lang.Object
    implements IUserManager
    This class stores information of each user in a separate file within a directory, and cache them in memory when a user is accessed.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected BasicUserManager​(IUserAccessor accessor)
      BasicUserManager Constructor.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean createUser​(java.lang.String username, java.lang.String password)
      Create a user with given username and password.
      boolean deleteUser​(java.lang.String username)
      Delete a user.
      User getUser​(java.lang.String username)
      Get a user object.
      boolean grantPrivilegeToUser​(java.lang.String username, PartialPath path, int privilegeId)
      Grant a privilege on a seriesPath to a user.
      boolean grantRoleToUser​(java.lang.String roleName, java.lang.String username)
      Add a role to a user.
      boolean isUserUseWaterMark​(java.lang.String username)
      Whether data water-mark is enabled for user 'userName'.
      java.util.List<java.lang.String> listAllUsers()
      List all users in the database.
      void replaceAllUsers​(java.util.Map<java.lang.String,​User> users)
      clear all old users info, replace the old users with the new one.
      void reset()
      Re-initialize this object.
      boolean revokePrivilegeFromUser​(java.lang.String username, PartialPath path, int privilegeId)
      Revoke a privilege on seriesPath from a user.
      boolean revokeRoleFromUser​(java.lang.String roleName, java.lang.String username)
      Revoke a role from a user.
      void setUserUseWaterMark​(java.lang.String username, boolean useWaterMark)
      Enable or disable data water-mark for user 'userName'.
      boolean updateUserPassword​(java.lang.String username, java.lang.String newPassword)
      Modify the password of a user.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • userMap

        protected java.util.Map<java.lang.String,​User> userMap
    • Constructor Detail

      • BasicUserManager

        protected BasicUserManager​(IUserAccessor accessor)
                            throws AuthException
        BasicUserManager Constructor.
        Parameters:
        accessor - user accessor
        Throws:
        AuthException - Authentication Exception
    • Method Detail

      • getUser

        public User getUser​(java.lang.String username)
                     throws AuthException
        Description copied from interface: IUserManager
        Get a user object.
        Specified by:
        getUser in interface IUserManager
        Parameters:
        username - The name of the user.
        Returns:
        A user object whose name is username or null if such user does not exist.
        Throws:
        AuthException - if an exception is raised when interacting with the lower storage.
      • createUser

        public boolean createUser​(java.lang.String username,
                                  java.lang.String password)
                           throws AuthException
        Description copied from interface: IUserManager
        Create a user with given username and password. New users will only be granted no privileges.
        Specified by:
        createUser in interface IUserManager
        Parameters:
        username - is not null or empty
        password - is not null or empty
        Returns:
        True if the user is successfully created, false when the user already exists.
        Throws:
        AuthException - if the given username or password is illegal.
      • deleteUser

        public boolean deleteUser​(java.lang.String username)
                           throws AuthException
        Description copied from interface: IUserManager
        Delete a user.
        Specified by:
        deleteUser in interface IUserManager
        Parameters:
        username - the username of the user.
        Returns:
        True if the user is successfully deleted, false if the user does not exists.
        Throws:
        AuthException - .
      • grantPrivilegeToUser

        public boolean grantPrivilegeToUser​(java.lang.String username,
                                            PartialPath path,
                                            int privilegeId)
                                     throws AuthException
        Description copied from interface: IUserManager
        Grant a privilege on a seriesPath to a user.
        Specified by:
        grantPrivilegeToUser in interface IUserManager
        Parameters:
        username - The username of the user to which the privilege should be added.
        path - The seriesPath on which the privilege takes effect. If the privilege is a seriesPath-free privilege, this should be "root".
        privilegeId - An integer that represents a privilege.
        Returns:
        True if the permission is successfully added, false if the permission already exists.
        Throws:
        AuthException - If the user does not exist or the privilege or the seriesPath is illegal.
      • revokePrivilegeFromUser

        public boolean revokePrivilegeFromUser​(java.lang.String username,
                                               PartialPath path,
                                               int privilegeId)
                                        throws AuthException
        Description copied from interface: IUserManager
        Revoke a privilege on seriesPath from a user.
        Specified by:
        revokePrivilegeFromUser in interface IUserManager
        Parameters:
        username - The username of the user from which the privilege should be removed.
        path - The seriesPath on which the privilege takes effect. If the privilege is a seriesPath-free privilege, this should be "root".
        privilegeId - An integer that represents a privilege.
        Returns:
        True if the permission is successfully revoked, false if the permission does not exists.
        Throws:
        AuthException - If the user does not exist or the privilege or the seriesPath is illegal.
      • updateUserPassword

        public boolean updateUserPassword​(java.lang.String username,
                                          java.lang.String newPassword)
                                   throws AuthException
        Description copied from interface: IUserManager
        Modify the password of a user.
        Specified by:
        updateUserPassword in interface IUserManager
        Parameters:
        username - The user whose password is to be modified.
        newPassword - The new password.
        Returns:
        True if the password is successfully modified, false if the new password is illegal.
        Throws:
        AuthException - If the user does not exists.
      • grantRoleToUser

        public boolean grantRoleToUser​(java.lang.String roleName,
                                       java.lang.String username)
                                throws AuthException
        Description copied from interface: IUserManager
        Add a role to a user.
        Specified by:
        grantRoleToUser in interface IUserManager
        Parameters:
        roleName - The name of the role to be added.
        username - The name of the user to which the role is added.
        Returns:
        True if the role is successfully added, false if the role already exists.
        Throws:
        AuthException - If the user does not exist.
      • revokeRoleFromUser

        public boolean revokeRoleFromUser​(java.lang.String roleName,
                                          java.lang.String username)
                                   throws AuthException
        Description copied from interface: IUserManager
        Revoke a role from a user.
        Specified by:
        revokeRoleFromUser in interface IUserManager
        Parameters:
        roleName - The name of the role to be removed.
        username - The name of the user from which the role is removed.
        Returns:
        True if the role is successfully removed, false if the role does not exist.
        Throws:
        AuthException - If the user does not exist.
      • listAllUsers

        public java.util.List<java.lang.String> listAllUsers()
        Description copied from interface: IUserManager
        List all users in the database.
        Specified by:
        listAllUsers in interface IUserManager
        Returns:
        A list that contains all users'name.
      • setUserUseWaterMark

        public void setUserUseWaterMark​(java.lang.String username,
                                        boolean useWaterMark)
                                 throws AuthException
        Description copied from interface: IUserManager
        Enable or disable data water-mark for user 'userName'.
        Specified by:
        setUserUseWaterMark in interface IUserManager
        Throws:
        AuthException - if the user does not exist.
      • replaceAllUsers

        public void replaceAllUsers​(java.util.Map<java.lang.String,​User> users)
                             throws AuthException
        Description copied from interface: IUserManager
        clear all old users info, replace the old users with the new one. The caller should guarantee that no other methods of this interface are invoked concurrently when this method is called.
        Specified by:
        replaceAllUsers in interface IUserManager
        Parameters:
        users - new users info
        Throws:
        AuthException