public class FileUserStore extends AbstractModule implements ModifyableUserStore
A user store that reads users from a json file. Also supports modifying the users and automatically saving the modified user store.
Auto saving is turned on by default. It can be turned off with the initialisation parameter autoSave and setting it to false. The file name must be specified with the initialisation parameter userFile.
Modifier and Type | Field and Description |
---|---|
protected boolean |
autoSave |
protected boolean |
autoSaveRunning |
protected boolean |
changed |
protected java.lang.Object |
saveMonitor |
protected java.lang.Thread |
saveThread |
protected long |
saveTime |
protected java.lang.String |
userFile |
protected java.util.HashMap<java.lang.String,User> |
users |
autoStart, isInitialized, isRunning, logging, loggingModule, moduleManager
Constructor and Description |
---|
FileUserStore() |
Modifier and Type | Method and Description |
---|---|
boolean |
deleteUser(java.lang.String user)
Deletes a user from this user store.
|
java.util.Collection<User> |
findUsers(java.lang.String key,
java.lang.String value)
Finds users based on a property value.
|
java.util.Collection<User> |
getAllUsers()
Returns a collection of all users.
|
java.util.Collection<Module> |
getDependencies(ModuleManager manager)
Returns all the modules this module depends on.
|
User |
getUser(java.lang.String user)
Finds a user with a user name.
|
void |
init(ModuleManager manager,
java.util.HashMap<java.lang.String,java.lang.Object> settings)
Initialises the module.
|
User |
newUser(java.lang.String user)
Creates a new user in the user store.
|
protected boolean |
readJsonUsers(java.lang.String userFile) |
protected void |
saveThreadRun() |
boolean |
saveUser(User user)
Saves a user which originates from this database.
|
void |
start(ModuleManager manager)
Starts the module.
|
void |
stop(ModuleManager manager)
Stops the module.
|
protected void |
writeJsonUsers(java.lang.String userFile) |
isInitialized, isRunning, requireLogging, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
isInitialized, isRunning
protected final java.util.HashMap<java.lang.String,User> users
protected java.lang.String userFile
protected long saveTime
protected boolean autoSaveRunning
protected boolean autoSave
protected final java.lang.Object saveMonitor
protected java.lang.Thread saveThread
protected boolean changed
public java.util.Collection<Module> getDependencies(ModuleManager manager) throws ModuleException
Module
getDependencies
in interface Module
getDependencies
in class AbstractModule
manager
- The module manager handling this module.ModuleException
public void init(ModuleManager manager, java.util.HashMap<java.lang.String,java.lang.Object> settings) throws ModuleException
Module
Initialises the module. After constructor, this is the first method called in the life cycle of a module. It should not perform anything time consuming or anything with notable outside side effects. It should only read the parameters and initialise the module so that it can later be started. Note that a module being initialised doesn't mean that it necessarily will ever be started.
A ModuleException may be thrown if something vital is missing from the parameters or they are not sensible. In some cases you may not want to throw an exception even if vital initialisation information is missing. If, for example, it is possible that the module is initialised in some other way between the init and the start method calls. A ModuleException may also be thrown at the start method if the module is still not initialised.
init
in interface Module
init
in class AbstractModule
manager
- The module manager handling this module. You may keep a
reference to it if needed.ModuleException
public void start(ModuleManager manager) throws ModuleException
Module
start
in interface Module
start
in class AbstractModule
manager
- The module manager handling this module.ModuleException
public void stop(ModuleManager manager)
Module
stop
in interface Module
stop
in class AbstractModule
manager
- The module manager handling this module.protected boolean readJsonUsers(java.lang.String userFile)
protected void writeJsonUsers(java.lang.String userFile)
public java.util.Collection<User> getAllUsers()
UserStore
getAllUsers
in interface UserStore
public User getUser(java.lang.String user)
UserStore
public User newUser(java.lang.String user)
ModifyableUserStore
newUser
in interface ModifyableUserStore
user
- The user name of the new user.public boolean saveUser(User user)
ModifyableUserStore
saveUser
in interface ModifyableUserStore
user
- The user object to save.public boolean deleteUser(java.lang.String user)
ModifyableUserStore
deleteUser
in interface ModifyableUserStore
user
- The user name of the user to delete.public java.util.Collection<User> findUsers(java.lang.String key, java.lang.String value)
UserStore
protected void saveThreadRun()
Copyright 2004-2015 Wandora Team