|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.samskivert.servlet.user.UserManager
public class UserManager
The user manager provides easy access to user objects for servlets. It takes care of cookie management involved in login, logout and loading a user record during an authenticated session.
| Nested Class Summary | |
|---|---|
static class |
UserManager.InsecureAuthenticator
A totally insecure authenticator that authenticates any user. |
static class |
UserManager.PasswordAuthenticator
An authenticator that requires that the user-supplied password match the actual user password. |
| Field Summary | |
|---|---|
protected Properties |
_config
Our user manager configuration. |
protected String |
_loginURL
The URL for the user login page. |
protected Interval |
_pruner
The interval for user session pruning. |
protected UserRepository |
_repository
The user repository. |
protected String |
_userAuthCookie
The name of our user authentication cookie. |
static Authenticator |
AUTH_INSECURE
An instance of the insecure authenticator for general-purpose use. |
static Authenticator |
AUTH_PASSWORD
An instance of the password authenticator for general-purpose use. |
protected static int |
NON_PERSIST_EXPIRE_DAYS
Indicates how long (in days) that a "non-persisting" session token should last. |
protected static int |
PERSIST_EXPIRE_DAYS
Indicates how long (in days) that a "persisting" session token should last. |
protected static long |
SESSION_PRUNE_INTERVAL
Prune the session table every hour. |
protected static String |
USERAUTH_COOKIE
The user authentication cookie name. |
protected static boolean |
USERMGR_DEBUG
Change this to true and recompile to debug cookie handling. |
| Constructor Summary | |
|---|---|
UserManager()
|
|
| Method Summary | |
|---|---|
protected UserRepository |
createRepository(ConnectionProvider conprov)
Called by the user manager to create the user repository. |
void |
effectLogin(User user,
int expires,
javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse rsp)
If a user is already known to be authenticated for one reason or other, this method can be used to give them the appropriate authentication cookies to effect their login. |
UserRepository |
getRepository()
Returns a reference to the repository in use by this user manager. |
void |
init(Properties config,
ConnectionProvider conprov)
Prepares this user manager for operation. |
void |
init(Properties config,
ConnectionProvider conprov,
RunQueue pruneQueue)
Prepares this user manager for operation. |
User |
loadUser(javax.servlet.http.HttpServletRequest req)
Fetches the necessary authentication information from the http request and loads the user identified by that information. |
User |
loadUser(String authcode)
Loads up a user based on the supplied session authentication token. |
User |
login(String username,
Password password,
boolean persist,
javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse rsp,
Authenticator auth)
Attempts to authenticate the requester and initiate an authenticated session for them. |
Tuple<User,String> |
login(String username,
Password password,
int expires,
Authenticator auth)
Attempts to authenticate the requester and initiate an authenticated session for them. |
void |
logout(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse rsp)
Logs the user out. |
boolean |
refreshSession(String sessionKey,
int expireDays)
Validates that the supplied session key is still valid and if so, refreshes it for the specified number of days. |
User |
requireUser(javax.servlet.http.HttpServletRequest req)
Fetches the necessary authentication information from the http request and loads the user identified by that information. |
void |
shutdown()
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final Authenticator AUTH_INSECURE
public static final Authenticator AUTH_PASSWORD
protected Properties _config
protected UserRepository _repository
protected Interval _pruner
protected String _loginURL
protected String _userAuthCookie
protected static final String USERAUTH_COOKIE
protected static final long SESSION_PRUNE_INTERVAL
protected static final int PERSIST_EXPIRE_DAYS
protected static final int NON_PERSIST_EXPIRE_DAYS
protected static final boolean USERMGR_DEBUG
| Constructor Detail |
|---|
public UserManager()
| Method Detail |
|---|
public void init(Properties config,
ConnectionProvider conprov)
throws PersistenceException
login_url: Should be set to the URL to which to redirect a requester if
they are required to login before accessing the requested page. For example:
login_url = /usermgmt/login.ajsp?return=%RThe
%R will be replaced with the URL encoded URL the user is currently
requesting (complete with query parameters) so that the login code can redirect the user
back to this request once they are authenticated.
config - the user manager configuration properties.conprov - the database connection provider that will be used to obtain a connection to
the user database.
PersistenceException
public void init(Properties config,
ConnectionProvider conprov,
RunQueue pruneQueue)
throws PersistenceException
init(Properties,ConnectionProvider).
pruneQueue - an optional run queue on which to run our periodic session pruning task.
PersistenceExceptionpublic void shutdown()
public UserRepository getRepository()
public User loadUser(javax.servlet.http.HttpServletRequest req)
throws PersistenceException
PersistenceException
public User loadUser(String authcode)
throws PersistenceException
PersistenceException
public User requireUser(javax.servlet.http.HttpServletRequest req)
throws PersistenceException,
RedirectException
PersistenceException
RedirectException
public User login(String username,
Password password,
boolean persist,
javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse rsp,
Authenticator auth)
throws PersistenceException,
AuthenticationFailedException
username - The username supplied by the user.password - The password supplied by the user.persist - If true, the cookie will expire in one month, if false, the cookie will
expire at the end of the user's browser session.req - The request via which the login page was loaded.rsp - The response in which the cookie is to be set.auth - The authenticator used to check whether the user should be authenticated.
PersistenceException
AuthenticationFailedException
public Tuple<User,String> login(String username,
Password password,
int expires,
Authenticator auth)
throws PersistenceException,
AuthenticationFailedException
User record. It is assumed that the client will maintain the session token via its own
means.
username - the username supplied by the user.password - the password supplied by the user.expires - the number of days in which this session should expire.auth - the authenticator used to check whether the user should be authenticated.
PersistenceException
AuthenticationFailedException
public void effectLogin(User user,
int expires,
javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse rsp)
throws PersistenceException
expires - the number of days in which to expire the session cookie, 0 means expire at
the end of the browser session.
PersistenceException
public void logout(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse rsp)
public boolean refreshSession(String sessionKey,
int expireDays)
throws PersistenceException
PersistenceException
protected UserRepository createRepository(ConnectionProvider conprov)
throws PersistenceException
PersistenceException
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||