public class GetUserAuthenticator extends AbstractModule implements UserAuthenticator
A simple user authenticator that takes the user name and password from the HTTP request parameters. Note that this is a bad solution for general authentication and should only be used in very specific circumstances. The passwords are not encrypted in the request and they are stored in plain text on the server side as well.
One use case where using this would be acceptable is when all passwords are empty and only the user name is needed. For example, the user name might be a server assigned API key for accessing some service.
You can set the request parameters where user name and password are read from using initialisation parameters userParam and passwordParam, respectively.
UserAuthenticator.AuthenticationResult
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
PASSWORD_KEY |
protected java.lang.String |
passwordParam |
protected java.lang.String |
realm |
protected java.lang.String |
userParam |
protected UserStore |
userStore |
autoStart, isInitialized, isRunning, logging, loggingModule, moduleManager
Constructor and Description |
---|
GetUserAuthenticator() |
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) |
protected UserAuthenticator.AuthenticationResult |
replyNotAuthorized(java.lang.String realm,
javax.servlet.http.HttpServletResponse resp,
User user) |
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 userParam
protected java.lang.String passwordParam
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
protected UserAuthenticator.AuthenticationResult replyNotAuthorized(java.lang.String realm, javax.servlet.http.HttpServletResponse resp, User user) 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