public class BasicUserAuthenticator extends AbstractModule implements UserAuthenticator
A simple user authenticator that performs standard HTTP authentication using the BASIC scheme. Even if you use this over a secure connection, this might still not be suitable for a production environment, except in specific circumstances. The reason is that all user password are stored as plain text in the user objects. Thus collecting user supplied password would be a very bad idea and go against good security practices. However, if the user passwords are assigned by the system, or there is only a limited number of users who are aware of the risks, this may still be a usable solution. In any case, this can be used in a development environment and later replaced with a more suitable solution.
You can set the realm for the authentication using the realm initialisation parameter.
UserAuthenticator.AuthenticationResult
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
PASSWORD_KEY |
protected java.lang.String |
realm |
protected UserStore |
userStore |
autoStart, isInitialized, isRunning, logging, loggingModule, moduleManager
Constructor and Description |
---|
BasicUserAuthenticator() |
Modifier and Type | Method and Description |
---|---|
UserAuthenticator.AuthenticationResult |
authenticate(java.lang.String requiredRole,
javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse resp,
ModulesServlet.HttpMethod method)
Authenticates a user.
|
java.util.Collection<Module> |
getDependencies(ModuleManager manager)
Returns all the modules this module depends on.
|
void |
init(ModuleManager manager,
java.util.HashMap<java.lang.String,java.lang.Object> settings)
Initialises the module.
|
protected UserAuthenticator.AuthenticationResult |
replyNotAuthorized(java.lang.String realm,
javax.servlet.http.HttpServletResponse resp) |
void |
start(ModuleManager manager)
Starts the module.
|
void |
stop(ModuleManager manager)
Stops the module.
|
isInitialized, isRunning, requireLogging, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
isInitialized, isRunning
public static final java.lang.String PASSWORD_KEY
protected java.lang.String realm
protected UserStore userStore
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 UserAuthenticator.AuthenticationResult replyNotAuthorized(java.lang.String realm, javax.servlet.http.HttpServletResponse resp) throws java.io.IOException
java.io.IOException
public UserAuthenticator.AuthenticationResult authenticate(java.lang.String requiredRole, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp, ModulesServlet.HttpMethod method) throws java.io.IOException, AuthenticationException
UserAuthenticator
Authenticates a user. If requiredRole is non-null, the logged in user must be of that role for the authentication to succeed. Otherwise there are two possible options in how to implement the authentication. It may be required that the user provides valid login details for authentication to succeed. Or it could be that anonymous logins are also authorised and the authentication succeeds without the user field set in the result. What exactly happens is implementation specific, possibly even dependent on the authenticator initialisation parameters.
authenticate
in interface UserAuthenticator
requiredRole
- The role the user should have or null if no role is required.req
- The HTTP request.resp
- The HTTP response.method
- The method of the HTTP request.java.io.IOException
AuthenticationException
Copyright 2004-2015 Wandora Team