public class StaticUserStore extends AbstractModule implements UserStore
A very simple user store which reads user names and passwords and roles straight from the initialisation parameters. Does not support editing users or any other options than password and roles. As such, it's really only useful for rudimentary access control and even then, the passwords are stored in plain. Nevertheless, this can make an easy to set up user store for development which can then later be replaced with something more suitable.
The user data is read from the initialisation variable users. The contents of this is a list of users, each user on its own line. Each user line is of the following format:
username;0;password;role1,role2,role3
The digit 0 is meant to indicate the format of the rest of the line, with the idea that in the future, this class could support more options on each user line. At the moment, this is the only supported format however. The last part may contain any number of roles, separated by commas.
The password is stored in the user object using BasicUserAuthenticator.PASSWORD_KEY as the key.
Modifier and Type | Field and Description |
---|---|
protected java.lang.String |
userData |
private java.util.regex.Pattern |
userPattern1 |
private java.util.regex.Pattern |
userPattern2 |
protected java.util.HashMap<java.lang.String,User> |
users |
autoStart, isInitialized, isRunning, logging, loggingModule, moduleManager
Constructor and Description |
---|
StaticUserStore() |
Modifier and Type | Method and Description |
---|---|
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.
|
protected void |
parseUsers(java.lang.String userData) |
void |
start(ModuleManager manager)
Starts the module.
|
isInitialized, isRunning, requireLogging, stop, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
isInitialized, isRunning, stop
protected java.util.HashMap<java.lang.String,User> users
protected java.lang.String userData
private java.util.regex.Pattern userPattern1
private java.util.regex.Pattern userPattern2
protected void parseUsers(java.lang.String userData)
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 java.util.Collection<User> getAllUsers()
UserStore
getAllUsers
in interface UserStore
public User getUser(java.lang.String user)
UserStore
Copyright 2004-2015 Wandora Team