Class BasicUserManager
- java.lang.Object
-
- org.apache.iotdb.commons.auth.user.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 protectedBasicUserManager(IUserAccessor accessor)BasicUserManager Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancreateUser(java.lang.String username, java.lang.String password)Create a user with given username and password.booleandeleteUser(java.lang.String username)Delete a user.UsergetUser(java.lang.String username)Get a user object.booleangrantPrivilegeToUser(java.lang.String username, PartialPath path, int privilegeId)Grant a privilege on a seriesPath to a user.booleangrantRoleToUser(java.lang.String roleName, java.lang.String username)Add a role to a user.booleanisUserUseWaterMark(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.voidreplaceAllUsers(java.util.Map<java.lang.String,User> users)clear all old users info, replace the old users with the new one.voidreset()Re-initialize this object.booleanrevokePrivilegeFromUser(java.lang.String username, PartialPath path, int privilegeId)Revoke a privilege on seriesPath from a user.booleanrevokeRoleFromUser(java.lang.String roleName, java.lang.String username)Revoke a role from a user.voidsetUserUseWaterMark(java.lang.String username, boolean useWaterMark)Enable or disable data water-mark for user 'userName'.booleanupdateUserPassword(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
-
Methods inherited from interface org.apache.iotdb.commons.snapshot.SnapshotProcessor
processLoadSnapshot, processTakeSnapshot
-
-
-
-
Field Detail
-
userMap
protected java.util.Map<java.lang.String,User> userMap
-
accessor
protected IUserAccessor accessor
-
lock
protected HashLock lock
-
-
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:IUserManagerGet a user object.- Specified by:
getUserin interfaceIUserManager- 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 AuthExceptionDescription copied from interface:IUserManagerCreate a user with given username and password. New users will only be granted no privileges.- Specified by:
createUserin interfaceIUserManager- Parameters:
username- is not null or emptypassword- 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 AuthExceptionDescription copied from interface:IUserManagerDelete a user.- Specified by:
deleteUserin interfaceIUserManager- 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 AuthExceptionDescription copied from interface:IUserManagerGrant a privilege on a seriesPath to a user.- Specified by:
grantPrivilegeToUserin interfaceIUserManager- 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 AuthExceptionDescription copied from interface:IUserManagerRevoke a privilege on seriesPath from a user.- Specified by:
revokePrivilegeFromUserin interfaceIUserManager- 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 AuthExceptionDescription copied from interface:IUserManagerModify the password of a user.- Specified by:
updateUserPasswordin interfaceIUserManager- 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 AuthExceptionDescription copied from interface:IUserManagerAdd a role to a user.- Specified by:
grantRoleToUserin interfaceIUserManager- 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 AuthExceptionDescription copied from interface:IUserManagerRevoke a role from a user.- Specified by:
revokeRoleFromUserin interfaceIUserManager- 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.
-
reset
public void reset() throws AuthExceptionDescription copied from interface:IUserManagerRe-initialize this object.- Specified by:
resetin interfaceIUserManager- Throws:
AuthException
-
listAllUsers
public java.util.List<java.lang.String> listAllUsers()
Description copied from interface:IUserManagerList all users in the database.- Specified by:
listAllUsersin interfaceIUserManager- Returns:
- A list that contains all users'name.
-
isUserUseWaterMark
public boolean isUserUseWaterMark(java.lang.String username) throws AuthExceptionDescription copied from interface:IUserManagerWhether data water-mark is enabled for user 'userName'.- Specified by:
isUserUseWaterMarkin interfaceIUserManager- Returns:
- Throws:
AuthException- if the user does not exist
-
setUserUseWaterMark
public void setUserUseWaterMark(java.lang.String username, boolean useWaterMark) throws AuthExceptionDescription copied from interface:IUserManagerEnable or disable data water-mark for user 'userName'.- Specified by:
setUserUseWaterMarkin interfaceIUserManager- 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:IUserManagerclear 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:
replaceAllUsersin interfaceIUserManager- Parameters:
users- new users info- Throws:
AuthException
-
-