Class BasicAuthorizer
- java.lang.Object
-
- org.apache.iotdb.commons.auth.authorizer.BasicAuthorizer
-
- All Implemented Interfaces:
IAuthorizer,IService,SnapshotProcessor
- Direct Known Subclasses:
LocalFileAuthorizer,OpenIdAuthorizer
public abstract class BasicAuthorizer extends java.lang.Object implements IAuthorizer, IService
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancheckUserPrivileges(java.lang.String username, PartialPath path, int privilegeId)Check if the user have the privilege on the seriesPath.voidcreateRole(java.lang.String roleName)Add a role.voidcreateUser(java.lang.String username, java.lang.String password)Create a user with given username and password.voiddeleteRole(java.lang.String roleName)Delete a role.voiddeleteUser(java.lang.String username)Delete a user.java.util.Map<java.lang.String,Role>getAllRoles()get all rolejava.util.Map<java.lang.String,User>getAllUsers()get all userjava.util.Map<java.lang.String,java.lang.Boolean>getAllUserWaterMarkStatus()get all user water mark statusServiceTypegetID()Get the name of the the service.static IAuthorizergetInstance()Function for getting the instance of the local file authorizer.java.util.Set<java.lang.Integer>getPrivileges(java.lang.String username, PartialPath path)Get the all the privileges of a user on a seriesPath.RolegetRole(java.lang.String roleName)Find a role by its name.UsergetUser(java.lang.String username)Find a user by its name.voidgrantPrivilegeToRole(java.lang.String roleName, PartialPath path, int privilegeId)Add a privilege on a seriesPath to a role.voidgrantPrivilegeToUser(java.lang.String username, PartialPath path, int privilegeId)Grant a privilege on a seriesPath to a user.voidgrantRoleToUser(java.lang.String roleName, java.lang.String username)Add a role to a user.protected voidinit()booleanisUserUseWaterMark(java.lang.String userName)Whether data water-mark is enabled for user 'userName'.java.util.List<java.lang.String>listAllRoles()List existing roles in the database.java.util.List<java.lang.String>listAllUsers()List existing users in the database.booleanlogin(java.lang.String username, java.lang.String password)Login for a user.voidprocessLoadSnapshot(java.io.File snapshotDir)Load snapshotbooleanprocessTakeSnapshot(java.io.File snapshotDir)Take snapshotvoidreplaceAllRoles(java.util.Map<java.lang.String,Role> roles)clear all old role info, replace the old roles with the new onevoidreplaceAllUsers(java.util.Map<java.lang.String,User> users)clear all old user info, replace the old users with the new onevoidreset()Reset the Authorizer to initiative status.voidrevokePrivilegeFromRole(java.lang.String roleName, PartialPath path, int privilegeId)Remove a privilege on a seriesPath from a role.voidrevokePrivilegeFromUser(java.lang.String username, PartialPath path, int privilegeId)Revoke a privilege on seriesPath from a user.voidrevokeRoleFromUser(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'.voidstart()Start current service.voidstop()Stop current service.voidupdateUserPassword(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.service.IService
shutdown, waitAndStop
-
-
-
-
Method Detail
-
init
protected void init() throws AuthException- Throws:
AuthException
-
getInstance
public static IAuthorizer getInstance() throws AuthException
Function for getting the instance of the local file authorizer.- Throws:
AuthException- Failed to initialize authorizer
-
login
public boolean login(java.lang.String username, java.lang.String password) throws AuthExceptionDescription copied from interface:IAuthorizerLogin for a user.- Specified by:
loginin interfaceIAuthorizer- Parameters:
username- The username of the user.password- The password of the user.- Returns:
- True if such user exists and the given password is correct, else return false.
- Throws:
AuthException- if exception raised when searching for the user.
-
createUser
public void createUser(java.lang.String username, java.lang.String password) throws AuthExceptionDescription copied from interface:IAuthorizerCreate a user with given username and password. New users will only be granted no privileges.- Specified by:
createUserin interfaceIAuthorizer- Parameters:
username- is not null or emptypassword- is not null or empty- Throws:
AuthException- if the given username or password is illegal or the user already exists.
-
deleteUser
public void deleteUser(java.lang.String username) throws AuthExceptionDescription copied from interface:IAuthorizerDelete a user.- Specified by:
deleteUserin interfaceIAuthorizer- Parameters:
username- the username of the user.- Throws:
AuthException- When attempting to delete the default administrator or the user does not exists.
-
grantPrivilegeToUser
public void grantPrivilegeToUser(java.lang.String username, PartialPath path, int privilegeId) throws AuthExceptionDescription copied from interface:IAuthorizerGrant a privilege on a seriesPath to a user.- Specified by:
grantPrivilegeToUserin interfaceIAuthorizer- 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.- Throws:
AuthException- If the user does not exist or the privilege or the seriesPath is illegal or the permission already exists.
-
revokePrivilegeFromUser
public void revokePrivilegeFromUser(java.lang.String username, PartialPath path, int privilegeId) throws AuthExceptionDescription copied from interface:IAuthorizerRevoke a privilege on seriesPath from a user.- Specified by:
revokePrivilegeFromUserin interfaceIAuthorizer- 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.- Throws:
AuthException- If the user does not exist or the privilege or the seriesPath is illegal or if the permission does not exist.
-
createRole
public void createRole(java.lang.String roleName) throws AuthExceptionDescription copied from interface:IAuthorizerAdd a role.- Specified by:
createRolein interfaceIAuthorizer- Parameters:
roleName- the name of the role to be added.- Throws:
AuthException- if exception raised when adding the role or the role already exists.
-
deleteRole
public void deleteRole(java.lang.String roleName) throws AuthExceptionDescription copied from interface:IAuthorizerDelete a role.- Specified by:
deleteRolein interfaceIAuthorizer- Parameters:
roleName- the name of the role tobe deleted.- Throws:
AuthException- if exception raised when deleting the role or the role does not exists.
-
grantPrivilegeToRole
public void grantPrivilegeToRole(java.lang.String roleName, PartialPath path, int privilegeId) throws AuthExceptionDescription copied from interface:IAuthorizerAdd a privilege on a seriesPath to a role.- Specified by:
grantPrivilegeToRolein interfaceIAuthorizer- Parameters:
roleName- The name of the role to which the privilege is 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.- Throws:
AuthException- If the role does not exist or the privilege or the seriesPath is illegal or the privilege already exists.
-
revokePrivilegeFromRole
public void revokePrivilegeFromRole(java.lang.String roleName, PartialPath path, int privilegeId) throws AuthExceptionDescription copied from interface:IAuthorizerRemove a privilege on a seriesPath from a role.- Specified by:
revokePrivilegeFromRolein interfaceIAuthorizer- Parameters:
roleName- The name of the role from which the privilege is 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.- Throws:
AuthException- If the role does not exist or the privilege or the seriesPath is illegal or the privilege does not exists.
-
grantRoleToUser
public void grantRoleToUser(java.lang.String roleName, java.lang.String username) throws AuthExceptionDescription copied from interface:IAuthorizerAdd a role to a user.- Specified by:
grantRoleToUserin interfaceIAuthorizer- Parameters:
roleName- The name of the role to be added.username- The name of the user to which the role is added.- Throws:
AuthException- If either the role or the user does not exist or the role already exists.
-
revokeRoleFromUser
public void revokeRoleFromUser(java.lang.String roleName, java.lang.String username) throws AuthExceptionDescription copied from interface:IAuthorizerRevoke a role from a user.- Specified by:
revokeRoleFromUserin interfaceIAuthorizer- Parameters:
roleName- The name of the role to be removed.username- The name of the user from which the role is removed.- Throws:
AuthException- If either the role or the user does not exist or the role already exists.
-
getPrivileges
public java.util.Set<java.lang.Integer> getPrivileges(java.lang.String username, PartialPath path) throws AuthExceptionDescription copied from interface:IAuthorizerGet the all the privileges of a user on a seriesPath.- Specified by:
getPrivilegesin interfaceIAuthorizer- Parameters:
username- The user whose privileges are to be queried.path- The seriesPath on which the privileges take effect. If the privilege is a seriesPath-free privilege, this should be "root".- Returns:
- A set of integers each present a privilege.
- Throws:
AuthException- if exception raised when finding the privileges.
-
updateUserPassword
public void updateUserPassword(java.lang.String username, java.lang.String newPassword) throws AuthExceptionDescription copied from interface:IAuthorizerModify the password of a user.- Specified by:
updateUserPasswordin interfaceIAuthorizer- Parameters:
username- The user whose password is to be modified.newPassword- The new password.- Throws:
AuthException- If the user does not exists or the new password is illegal.
-
checkUserPrivileges
public boolean checkUserPrivileges(java.lang.String username, PartialPath path, int privilegeId) throws AuthExceptionDescription copied from interface:IAuthorizerCheck if the user have the privilege on the seriesPath.- Specified by:
checkUserPrivilegesin interfaceIAuthorizer- Parameters:
username- The name of the user whose privileges are checked.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 user has such privilege, false if the user does not have such privilege.
- Throws:
AuthException- If the seriesPath or the privilege is illegal.
-
getAllUserWaterMarkStatus
public java.util.Map<java.lang.String,java.lang.Boolean> getAllUserWaterMarkStatus()
Description copied from interface:IAuthorizerget all user water mark status- Specified by:
getAllUserWaterMarkStatusin interfaceIAuthorizer- Returns:
- key->userName, value->useWaterMark or not
-
getAllUsers
public java.util.Map<java.lang.String,User> getAllUsers()
Description copied from interface:IAuthorizerget all user- Specified by:
getAllUsersin interfaceIAuthorizer- Returns:
- key-> userName, value->user
-
getAllRoles
public java.util.Map<java.lang.String,Role> getAllRoles()
Description copied from interface:IAuthorizerget all role- Specified by:
getAllRolesin interfaceIAuthorizer- Returns:
- key->userName, value->role
-
reset
public void reset() throws AuthExceptionDescription copied from interface:IAuthorizerReset the Authorizer to initiative status.- Specified by:
resetin interfaceIAuthorizer- Throws:
AuthException
-
start
public void start() throws StartupExceptionDescription copied from interface:IServiceStart current service.- Specified by:
startin interfaceIService- Throws:
StartupException
-
stop
public void stop()
Description copied from interface:IServiceStop current service. If current service uses thread or thread pool, current service should guarantee to putBack thread or thread pool.
-
getID
public ServiceType getID()
Description copied from interface:IServiceGet the name of the the service.
-
listAllUsers
public java.util.List<java.lang.String> listAllUsers()
Description copied from interface:IAuthorizerList existing users in the database.- Specified by:
listAllUsersin interfaceIAuthorizer- Returns:
- A list contains all usernames.
-
listAllRoles
public java.util.List<java.lang.String> listAllRoles()
Description copied from interface:IAuthorizerList existing roles in the database.- Specified by:
listAllRolesin interfaceIAuthorizer- Returns:
- A list contains all roleNames.
-
getRole
public Role getRole(java.lang.String roleName) throws AuthException
Description copied from interface:IAuthorizerFind a role by its name.- Specified by:
getRolein interfaceIAuthorizer- Parameters:
roleName- the name of the role.- Returns:
- A role whose name is roleName or null if such role does not exist.
- Throws:
AuthException
-
getUser
public User getUser(java.lang.String username) throws AuthException
Description copied from interface:IAuthorizerFind a user by its name.- Specified by:
getUserin interfaceIAuthorizer- Parameters:
username- the name of the user.- Returns:
- A user whose name is username or null if such user does not exist.
- Throws:
AuthException
-
isUserUseWaterMark
public boolean isUserUseWaterMark(java.lang.String userName) throws AuthExceptionDescription copied from interface:IAuthorizerWhether data water-mark is enabled for user 'userName'.- Specified by:
isUserUseWaterMarkin interfaceIAuthorizer- Parameters:
userName- the name of user- Throws:
AuthException- if the user does not exist
-
setUserUseWaterMark
public void setUserUseWaterMark(java.lang.String userName, boolean useWaterMark) throws AuthExceptionDescription copied from interface:IAuthorizerEnable or disable data water-mark for user 'userName'.- Specified by:
setUserUseWaterMarkin interfaceIAuthorizer- Parameters:
userName- the name of useruseWaterMark- whether to use water-mark or not- 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:IAuthorizerclear all old user info, replace the old users with the new one- Specified by:
replaceAllUsersin interfaceIAuthorizer- Parameters:
users- new users info- Throws:
AuthException- IOException
-
replaceAllRoles
public void replaceAllRoles(java.util.Map<java.lang.String,Role> roles) throws AuthException
Description copied from interface:IAuthorizerclear all old role info, replace the old roles with the new one- Specified by:
replaceAllRolesin interfaceIAuthorizer- Parameters:
roles- new roles info- Throws:
AuthException- IOException
-
processTakeSnapshot
public boolean processTakeSnapshot(java.io.File snapshotDir) throws org.apache.thrift.TException, java.io.IOExceptionDescription copied from interface:SnapshotProcessorTake snapshot- Specified by:
processTakeSnapshotin interfaceSnapshotProcessor- Parameters:
snapshotDir- Where snapshot files are stored.- Returns:
- Whether the snapshot is successfully executed
- Throws:
org.apache.thrift.TException- Exception occurred during the thrift serialize structjava.io.IOException- Exception related to file read and write
-
processLoadSnapshot
public void processLoadSnapshot(java.io.File snapshotDir) throws org.apache.thrift.TException, java.io.IOExceptionDescription copied from interface:SnapshotProcessorLoad snapshot- Specified by:
processLoadSnapshotin interfaceSnapshotProcessor- Parameters:
snapshotDir- Load snapshot from here- Throws:
org.apache.thrift.TException- Exception occurred during the thrift deserialize structjava.io.IOException- Exception related to file read and write
-
-