Class LocalFileUserAccessor
- java.lang.Object
-
- org.apache.iotdb.commons.auth.user.LocalFileUserAccessor
-
- All Implemented Interfaces:
IUserAccessor,SnapshotProcessor
public class LocalFileUserAccessor extends java.lang.Object implements IUserAccessor
This class loads a user's information from the corresponding file.The user file is a sequential file. User file schema: Int32 username bytes size Utf-8 username bytes Int32 Password bytes size Utf-8 password bytes Int32 seriesPath privilege number n Int32 seriesPath[1] size Utf-8 seriesPath[1] bytes Int32 privilege num k1 Int32 privilege[1][1] Int32 privilege[1][2] ... Int32 privilege[1][k1] Int32 seriesPath[2] size Utf-8 seriesPath[2] bytes Int32 privilege num k2 Int32 privilege[2][1] Int32 privilege[2][2] ... Int32 privilege[2][k2] ... Int32 seriesPath[n] size Utf-8 seriesPath[n] bytes Int32 privilege num kn Int32 privilege[n][1] Int32 privilege[n][2] ... Int32 privilege[n][kn] Int32 user name number m Int32 user name[1] size Utf-8 user name[1] bytes Int32 user name[2] size Utf-8 user name[2] bytes ... Int32 user name[m] size Utf-8 user name[m] bytes
-
-
Constructor Summary
Constructors Constructor Description LocalFileUserAccessor(java.lang.String userDirPath)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleandeleteUser(java.lang.String username)Delete a user's user file.java.lang.StringgetDirPath()get UserDirPathjava.util.List<java.lang.String>listAllUsers()List all users existing in the database.UserloadUser(java.lang.String username)Deserialize a user from its user file.voidprocessLoadSnapshot(java.io.File snapshotDir)Load snapshotbooleanprocessTakeSnapshot(java.io.File snapshotDir)Take snapshotvoidreset()Re-initialize this object.voidsaveUser(User user)Serialize the user object to a temp file, then replace the old user file with the new file.
-
-
-
Method Detail
-
loadUser
public User loadUser(java.lang.String username) throws java.io.IOException
Deserialize a user from its user file.- Specified by:
loadUserin interfaceIUserAccessor- Parameters:
username- The name of the user to be deserialized.- Returns:
- The user object or null if no such user.
- Throws:
java.io.IOException- if an exception is raised when interacting with the lower storage.
-
saveUser
public void saveUser(User user) throws java.io.IOException
Serialize the user object to a temp file, then replace the old user file with the new file.- Specified by:
saveUserin interfaceIUserAccessor- Parameters:
user- The user object that is to be saved.- Throws:
java.io.IOException- if an exception is raised when interacting with the lower storage.
-
deleteUser
public boolean deleteUser(java.lang.String username) throws java.io.IOExceptionDelete a user's user file.- Specified by:
deleteUserin interfaceIUserAccessor- Parameters:
username- The name of the user to be deleted.- Returns:
- True if the file is successfully deleted, false if the file does not exists.
- Throws:
java.io.IOException- when the file cannot be deleted.
-
listAllUsers
public java.util.List<java.lang.String> listAllUsers()
Description copied from interface:IUserAccessorList all users existing in the database.- Specified by:
listAllUsersin interfaceIUserAccessor- Returns:
- A list that contains names of all users.
-
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
-
reset
public void reset()
Description copied from interface:IUserAccessorRe-initialize this object.- Specified by:
resetin interfaceIUserAccessor
-
getDirPath
public java.lang.String getDirPath()
Description copied from interface:IUserAccessorget UserDirPath- Specified by:
getDirPathin interfaceIUserAccessor- Returns:
- userDirPath
-
-