|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.tenduke.networking.http.ConfigurableHttpSessionHandler
com.tenduke.services.http.CookieBasedHttpSessionHandler
public class CookieBasedHttpSessionHandler
Session handler implementation class that uses cookies to manage user session. This class signs session using a configurable secret. Session signing allows handling client session validation in a distributed system without information exchange between the participating nodes that validate requests.
Table of configuration keys defined by this class.
| Key name | Description | Default value |
|---|---|---|
| usermanagement.ignoreloginnamecase |
Controls if case should be ignored in login names. Valid values are true and false.
|
false
|
| security.cookiebasedhttpsessionhandler.sessionsignaturekey | A key that is used to sign a session. Once a session has been created and signed using the configured kay it can be validated based on data in client cookies, the signature stored in a client cookie and the re-computed signature. |
Randomly generated signature
|
| Field Summary | |
|---|---|
static int |
MAX_COOKIE_AGE
Maximum age for a cookie for use cases where cookies are not set as session cookies. |
static java.lang.String |
PREFER_PERSISTENT_SESSION_PARAMETER_NAME
Constant for request parameter name that defines option to use persistent cookies instead of session cookies when logging in user. |
| Constructor Summary | |
|---|---|
CookieBasedHttpSessionHandler()
Creates new instance of CookieBasedHttpSessionHandler. |
|
| Method Summary | |
|---|---|
static boolean |
alwaysIgnoreLoginNameCase()
Checks whether login name case should always be ignored. |
protected void |
clearSessionDigest(javax.servlet.http.HttpServletResponse response)
Clear the session signing cookie containing digest for valid session. |
boolean |
createSession(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
java.lang.String sessionProfileId)
Created and identifies session based on two cookies. |
protected java.lang.String |
createSessionDigest(java.lang.String principal)
Create the digest to store in session. |
void |
endSession(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Clears all cookies used to store session data, resulting in a invalidated session. |
protected java.lang.String |
getSessionProfileIdByCookies(javax.servlet.http.HttpServletRequest request)
Retrieves session profile id stored in cookie after checking session digest to ensure that session profile id has not been tampered. |
protected byte[] |
getSessionSigningBytes(boolean forceRegenerate)
Gets the bytes set for signing sessions with. |
java.security.Principal |
getSessionUser(javax.servlet.http.HttpServletRequest request)
Gets user identifier bound to session, wrapped in a Principal object. |
java.security.Principal |
getSessionUserPrincipal(javax.servlet.http.HttpServletRequest request,
java.lang.String principalType)
Get current session user principal of given type. |
protected void |
parseConfiguration()
Reads value defined by key named observer. |
void |
setSessionSigningBytes(byte[] sessionSigningBytes)
Sets the bytes used to sign sessions created by this handler. |
protected boolean |
signSession(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
java.lang.String sessionPrincipal)
Sign session by writing a session digest in a cookie. |
LoginInformation |
validateInitialLogin(javax.servlet.http.HttpServletRequest request)
Validates user login using client HTTP request. |
LoginInformation |
validateSession(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Validates session based on two cookies. |
| Methods inherited from class com.tenduke.networking.http.ConfigurableHttpSessionHandler |
|---|
configure, getConfiguration, setConfiguration |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final int MAX_COOKIE_AGE
public static final java.lang.String PREFER_PERSISTENT_SESSION_PARAMETER_NAME
| Constructor Detail |
|---|
public CookieBasedHttpSessionHandler()
| Method Detail |
|---|
public static boolean alwaysIgnoreLoginNameCase()
protected void clearSessionDigest(javax.servlet.http.HttpServletResponse response)
response - The response object for client to reset session cookie.
public boolean createSession(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
java.lang.String sessionProfileId)
Created and identifies session based on two cookies. These cookies are:
KeyWords.SessionParameterKeywords.SESSION_SHORT_NAME_COOKIE
KeyWords.SessionParameterKeywords.LOGIN_STATE
In addition to the data stored in cookies a digest is computed (based on a configurable secret key) and stored in a cookie named:
KeyWords.SessionParameterKeywordsSESSION_DIGEST
request - Client HTTP request.response - Client HTTP response to write session to.sessionProfileId - Profile id to bind to the session
protected java.lang.String createSessionDigest(java.lang.String principal)
principal - The name to sign session for.
public void endSession(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
request - Client HTTP request to end session for.response - Client HTTP response to modify to apply changes in session.protected java.lang.String getSessionProfileIdByCookies(javax.servlet.http.HttpServletRequest request)
request - Client HTTP request to inspect for user session.
protected byte[] getSessionSigningBytes(boolean forceRegenerate)
forceRegenerate - Flag to force regenerating session signing bytes.
public java.security.Principal getSessionUser(javax.servlet.http.HttpServletRequest request)
Gets user identifier bound to session, wrapped in a Principal object.
Reads cookie by name from request.
KeyWords.SessionParameterKeywords.SESSION_PROFILE_ID_COOKIE
request - Client HTTP request for reading session user identification
Principal object representing the user bound to client HTTP session.
public java.security.Principal getSessionUserPrincipal(javax.servlet.http.HttpServletRequest request,
java.lang.String principalType)
request - Client HTTP request with data to use for resolving Principal object.principalType - Principal type. Recognized principal types are defined by UserDatabase.PrincipalType constants.
protected void parseConfiguration()
parseConfiguration in class ConfigurableHttpSessionHandlerpublic void setSessionSigningBytes(byte[] sessionSigningBytes)
sessionSigningBytes - the session signing bytes to set.
protected boolean signSession(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
java.lang.String sessionPrincipal)
request - Client HTTP request.response - Client HTTP response.sessionPrincipal - The principal name to bind to session.
public LoginInformation validateInitialLogin(javax.servlet.http.HttpServletRequest request)
Validates user login using client HTTP request.
Reads username from request parameters using following order and parameter names:
Profile.FIELD_NAME_SHORT_NAME.
Account.FIELD_NAME_PRIMARY_PRINCIPAL.
Account.FIELD_NAME_ACCOUNT_ID.
Reads password hash or plain text password from request parameters using following order and parameter names:
Implementation uses UserManager.loginWithPasswordHash(java.lang.String, java.lang.String) and
alternatively UserManager.login(java.lang.String, java.lang.String) with user name and password found in the request.
request - Client HTTP request holding credentials to login with.
public LoginInformation validateSession(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Validates session based on two cookies. These cookies are:
KeyWords.SessionParameterKeywords.SESSION_SHORT_NAME
KeyWords.SessionParameterKeywords.SESSION_DIGEST
request - Client HTTP request to validate.response - Client HTTP response to modify to apply changes in session.
LoginInformationProvider and carries information of login / session status. Null if
session not valid. If session is valid, LoginInformationProvider.getProfileId() return session user profile id.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||