@ManagedObject(value="Abstract Session Manager") public abstract class AbstractSessionManager extends ContainerLifeCycle implements SessionManager
The partial implementation of SessionManager interface provides the majority of the handling required to implement a SessionManager. Concrete implementations of SessionManager based on AbstractSessionManager need only implement the newSession method to return a specialized version of the Session inner class that provides an attribute Map.
Modifier and Type | Class and Description |
---|---|
class |
AbstractSessionManager.CookieConfig
CookieConfig
Implementation of the javax.servlet.SessionCookieConfig.
|
static interface |
AbstractSessionManager.SessionIf
Interface that any session wrapper should implement so that
SessionManager may access the Jetty session implementation.
|
AbstractLifeCycle.AbstractLifeCycleListener
LifeCycle.Listener
Container.InheritedListener, Container.Listener
FAILED, RUNNING, STARTED, STARTING, STOPPED, STOPPING
__CheckRemoteSessionEncoding, __DefaultSessionCookie, __DefaultSessionDomain, __DefaultSessionIdPathParameterName, __MaxAgeProperty, __SessionCookieProperty, __SessionDomainProperty, __SessionIdPathParameterNameProperty, __SessionPathProperty
Constructor and Description |
---|
AbstractSessionManager() |
Modifier and Type | Method and Description |
---|---|
HttpCookie |
access(HttpSession session,
boolean secure)
Called by the
SessionHandler when a session is first accessed by a request. |
void |
addEventListener(EventListener listener)
Adds an event listener for session-related events.
|
protected abstract void |
addSession(AbstractSession session) |
protected void |
addSession(AbstractSession session,
boolean created)
Add the session Registers the session with this manager and registers the
session ID with the sessionIDManager;
|
void |
clearEventListeners()
Removes all event listeners for session-related events.
|
void |
complete(HttpSession session)
Called by the
SessionHandler when a session is last accessed by a request. |
void |
doSessionAttributeListeners(AbstractSession session,
String name,
Object old,
Object value) |
void |
doStart() |
void |
doStop() |
String |
getClusterId(HttpSession session) |
ContextHandler.Context |
getContext() |
ContextHandler |
getContextHandler() |
Set<SessionTrackingMode> |
getDefaultSessionTrackingModes() |
Set<SessionTrackingMode> |
getEffectiveSessionTrackingModes() |
boolean |
getHttpOnly() |
HttpSession |
getHttpSession(String nodeId)
Returns the
HttpSession with the given session id |
int |
getMaxCookieAge() |
int |
getMaxInactiveInterval() |
SessionIdManager |
getMetaManager()
Deprecated.
|
String |
getNodeId(HttpSession session) |
int |
getRefreshCookieAge() |
boolean |
getSecureCookies() |
abstract AbstractSession |
getSession(String idInCluster)
Get a known existing session
|
String |
getSessionCookie() |
HttpCookie |
getSessionCookie(HttpSession session,
String contextPath,
boolean requestIsSecure)
A sessioncookie is marked as secure IFF any of the following conditions are true:
SessionCookieConfig.setSecure == true
SessionCookieConfig.setSecure == false && _secureRequestOnly==true && request is HTTPS
According to SessionCookieConfig javadoc, case 1 can be used when:
"...
|
SessionCookieConfig |
getSessionCookieConfig() |
String |
getSessionDomain() |
SessionHandler |
getSessionHandler() |
SessionIdManager |
getSessionIdManager() |
String |
getSessionIdPathParameterName() |
String |
getSessionIdPathParameterNamePrefix() |
String |
getSessionPath() |
int |
getSessions() |
int |
getSessionsMax() |
int |
getSessionsTotal() |
long |
getSessionTimeMax() |
double |
getSessionTimeMean() |
double |
getSessionTimeStdDev() |
long |
getSessionTimeTotal() |
boolean |
isCheckingRemoteSessionIdEncoding() |
boolean |
isNodeIdInSessionId() |
boolean |
isSecureRequestOnly() |
boolean |
isUsingCookies() |
boolean |
isUsingURLs() |
boolean |
isValid(HttpSession session) |
HttpSession |
newHttpSession(HttpServletRequest request)
Create a new HttpSession for a request
|
protected abstract AbstractSession |
newSession(HttpServletRequest request)
Create a new session instance
|
void |
removeEventListener(EventListener listener)
Removes an event listener for for session-related events.
|
boolean |
removeSession(AbstractSession session,
boolean invalidate)
Remove session from manager
|
void |
removeSession(HttpSession session,
boolean invalidate)
Remove session from manager
|
protected abstract boolean |
removeSession(String idInCluster) |
void |
renewSessionId(String oldClusterId,
String oldNodeId,
String newClusterId,
String newNodeId)
Tell the HttpSessionIdListeners the id changed.
|
void |
setCheckingRemoteSessionIdEncoding(boolean remote) |
void |
setHttpOnly(boolean httpOnly) |
void |
setMaxInactiveInterval(int seconds)
Sets the max period of inactivity, after which the session is invalidated, in seconds.
|
void |
setNodeIdInSessionId(boolean nodeIdInSessionId) |
void |
setRefreshCookieAge(int ageInSeconds) |
void |
setSecureRequestOnly(boolean secureRequestOnly)
HTTPS request.
|
void |
setSessionCookie(String cookieName) |
void |
setSessionHandler(SessionHandler sessionHandler)
Sets the
SessionHandler . |
void |
setSessionIdManager(SessionIdManager metaManager)
Sets the cross context session id manager
|
void |
setSessionIdPathParameterName(String param)
Sets the session id URL path parameter name.
|
void |
setSessionTrackingModes(Set<SessionTrackingMode> sessionTrackingModes) |
void |
setUsingCookies(boolean usingCookies) |
protected abstract void |
shutdownSessions()
Prepare sessions for session manager shutdown
|
void |
statsReset()
Reset statistics values
|
addBean, addBean, addBean, addEventListener, addManaged, contains, destroy, dump, dump, dump, dump, dump, dumpBeans, dumpObject, dumpStdErr, dumpThis, getBean, getBeans, getBeans, isManaged, manage, removeBean, removeBeans, removeEventListener, setBeans, setStopTimeout, start, stop, unmanage, updateBean, updateBean, updateBeans
addLifeCycleListener, getState, getState, getStopTimeout, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
addLifeCycleListener, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop
public Set<SessionTrackingMode> __defaultSessionTrackingModes
public static final int __distantFuture
public static final BigDecimal MAX_INACTIVE_MINUTES
protected int _dftMaxIdleSecs
protected SessionHandler _sessionHandler
protected boolean _httpOnly
protected SessionIdManager _sessionIdManager
protected boolean _secureCookies
protected boolean _secureRequestOnly
protected final List<HttpSessionAttributeListener> _sessionAttributeListeners
protected final List<HttpSessionListener> _sessionListeners
protected final List<HttpSessionIdListener> _sessionIdListeners
protected ClassLoader _loader
protected ContextHandler.Context _context
protected String _sessionCookie
protected String _sessionIdPathParameterName
protected String _sessionIdPathParameterNamePrefix
protected String _sessionDomain
protected String _sessionPath
protected int _maxCookieAge
protected int _refreshCookieAge
protected boolean _nodeIdInSessionId
protected boolean _checkingRemoteSessionIdEncoding
protected String _sessionComment
public Set<SessionTrackingMode> _sessionTrackingModes
protected final CounterStatistic _sessionsStats
protected final SampleStatistic _sessionTimeStats
public ContextHandler.Context getContext()
public ContextHandler getContextHandler()
@ManagedAttribute(value="path of the session cookie, or null for default") public String getSessionPath()
@ManagedAttribute(value="if greater the zero, the time in seconds a session cookie will last for") public int getMaxCookieAge()
public HttpCookie access(HttpSession session, boolean secure)
SessionManager
SessionHandler
when a session is first accessed by a request.access
in interface SessionManager
session
- the session objectsecure
- whether the request is secure or notSessionManager.complete(HttpSession)
public void addEventListener(EventListener listener)
SessionManager
addEventListener
in interface SessionManager
listener
- the session event listener to add
Individual SessionManagers implementations may accept arbitrary listener types,
but they are expected to at least handle HttpSessionActivationListener,
HttpSessionAttributeListener, HttpSessionBindingListener and HttpSessionListener.SessionManager.removeEventListener(EventListener)
public void clearEventListeners()
SessionManager
clearEventListeners
in interface SessionManager
SessionManager.removeEventListener(EventListener)
public void complete(HttpSession session)
SessionManager
SessionHandler
when a session is last accessed by a request.complete
in interface SessionManager
session
- the session objectSessionManager.access(HttpSession, boolean)
public void doStart() throws Exception
doStart
in class ContainerLifeCycle
Exception
public void doStop() throws Exception
doStop
in class ContainerLifeCycle
Exception
@ManagedAttribute(value="true if cookies use the http only flag") public boolean getHttpOnly()
getHttpOnly
in interface SessionManager
HttpCookie.isHttpOnly()
public HttpSession getHttpSession(String nodeId)
SessionManager
HttpSession
with the given session idgetHttpSession
in interface SessionManager
nodeId
- the session idHttpSession
with the corresponding id or null if no session with the given id exists@ManagedAttribute(value="Session ID Manager") public SessionIdManager getSessionIdManager()
getSessionIdManager
in interface SessionManager
SessionManager.setSessionIdManager(SessionIdManager)
@ManagedAttribute(value="defailt maximum time a session may be idle for (in s)") public int getMaxInactiveInterval()
getMaxInactiveInterval
in interface SessionManager
SessionManager.setMaxInactiveInterval(int)
@ManagedAttribute(value="maximum number of simultaneous sessions") public int getSessionsMax()
@ManagedAttribute(value="total number of sessions") public int getSessionsTotal()
@ManagedAttribute(value="time before a session cookie is re-set (in s)") public int getRefreshCookieAge()
@ManagedAttribute(value="if true, secure cookie flag is set on session cookies") public boolean getSecureCookies()
public boolean isSecureRequestOnly()
public void setSecureRequestOnly(boolean secureRequestOnly)
secureRequestOnly
- true to set Session Cookie Config as secure@ManagedAttribute(value="the set session cookie") public String getSessionCookie()
public HttpCookie getSessionCookie(HttpSession session, String contextPath, boolean requestIsSecure)
For case 2, you can use _secureRequestOnly to determine if you want the Servlet Spec 3.0 default behavior when SessionCookieConfig.setSecure==false, which is: "they shall be marked as secure only if the request that initiated the corresponding session was also secure"
The default for _secureRequestOnly is true, which gives the above behavior. If you set it to false, then a session cookie is NEVER marked as secure, even if the initiating request was secure.
getSessionCookie
in interface SessionManager
session
- the session to which the cookie should refer.contextPath
- the context to which the cookie should be linked.
The client will only send the cookie value when requesting resources under this path.requestIsSecure
- whether the client is accessing the server over a secure protocol (i.e. HTTPS).SessionManager
uses cookies, then this method will return a new
cookie object
that should be set on the client in order to link future HTTP requests
with the session
. If cookies are not in use, this method returns null
.SessionManager.getSessionCookie(javax.servlet.http.HttpSession, java.lang.String, boolean)
@ManagedAttribute(value="domain of the session cookie, or null for the default") public String getSessionDomain()
public SessionHandler getSessionHandler()
@ManagedAttribute(value="number of currently active sessions") public int getSessions()
@ManagedAttribute(value="name of use for URL session tracking") public String getSessionIdPathParameterName()
getSessionIdPathParameterName
in interface SessionManager
SessionManager.setSessionIdPathParameterName(String)
public String getSessionIdPathParameterNamePrefix()
getSessionIdPathParameterNamePrefix
in interface SessionManager
SessionManager.getSessionIdPathParameterName()
, by default
";" + sessionIdParameterName + "=", for easier lookup in URL strings.SessionManager.getSessionIdPathParameterName()
public boolean isUsingCookies()
isUsingCookies
in interface SessionManager
public boolean isValid(HttpSession session)
isValid
in interface SessionManager
session
- the session to test for validitypublic String getClusterId(HttpSession session)
getClusterId
in interface SessionManager
session
- the session objectSessionManager.getNodeId(HttpSession)
public String getNodeId(HttpSession session)
getNodeId
in interface SessionManager
session
- the session objectSessionManager.getClusterId(HttpSession)
public HttpSession newHttpSession(HttpServletRequest request)
newHttpSession
in interface SessionManager
request
- the HttpServletRequest containing the requested session idHttpSession
public void removeEventListener(EventListener listener)
SessionManager
removeEventListener
in interface SessionManager
listener
- the session event listener to removeSessionManager.addEventListener(EventListener)
@ManagedOperation(value="reset statistics", impact="ACTION") public void statsReset()
public void setHttpOnly(boolean httpOnly)
httpOnly
- The httpOnly to set.public void setSessionIdManager(SessionIdManager metaManager)
SessionManager
setSessionIdManager
in interface SessionManager
metaManager
- The metaManager used for cross context session management.SessionManager.getSessionIdManager()
public void setMaxInactiveInterval(int seconds)
SessionManager
setMaxInactiveInterval
in interface SessionManager
seconds
- the max inactivity period, in seconds.SessionManager.getMaxInactiveInterval()
public void setRefreshCookieAge(int ageInSeconds)
public void setSessionCookie(String cookieName)
public void setSessionHandler(SessionHandler sessionHandler)
SessionManager
SessionHandler
.setSessionHandler
in interface SessionManager
sessionHandler
- The sessionHandler to set.public void setSessionIdPathParameterName(String param)
SessionManager
setSessionIdPathParameterName
in interface SessionManager
param
- the URL path parameter name for session id URL rewriting (null or "none" for no rewriting).SessionManager.getSessionIdPathParameterName()
,
SessionManager.getSessionIdPathParameterNamePrefix()
public void setUsingCookies(boolean usingCookies)
usingCookies
- The usingCookies to set.protected abstract void addSession(AbstractSession session)
protected void addSession(AbstractSession session, boolean created)
session
- the sessioncreated
- true if session was createdpublic abstract AbstractSession getSession(String idInCluster)
idInCluster
- The session ID in the cluster, stripped of any worker name.protected abstract void shutdownSessions() throws Exception
Exception
- if unable to shutdown sesssionsprotected abstract AbstractSession newSession(HttpServletRequest request)
request
- the request to build the session frompublic boolean isNodeIdInSessionId()
HttpSession.getId()
. Default is false.public void setNodeIdInSessionId(boolean nodeIdInSessionId)
nodeIdInSessionId
- true if the cluster node id (worker id) will be returned as part of the session id by HttpSession.getId()
. Default is false.public void removeSession(HttpSession session, boolean invalidate)
session
- The session to removeinvalidate
- True if HttpSessionListener.sessionDestroyed(HttpSessionEvent)
and
SessionIdManager.invalidateAll(String)
should be called.public boolean removeSession(AbstractSession session, boolean invalidate)
session
- The session to removeinvalidate
- True if HttpSessionListener.sessionDestroyed(HttpSessionEvent)
and
SessionIdManager.invalidateAll(String)
should be called.protected abstract boolean removeSession(String idInCluster)
@ManagedAttribute(value="maximum amount of time sessions have remained active (in s)") public long getSessionTimeMax()
public Set<SessionTrackingMode> getDefaultSessionTrackingModes()
getDefaultSessionTrackingModes
in interface SessionManager
public Set<SessionTrackingMode> getEffectiveSessionTrackingModes()
getEffectiveSessionTrackingModes
in interface SessionManager
public void setSessionTrackingModes(Set<SessionTrackingMode> sessionTrackingModes)
setSessionTrackingModes
in interface SessionManager
public boolean isUsingURLs()
isUsingURLs
in interface SessionManager
public SessionCookieConfig getSessionCookieConfig()
getSessionCookieConfig
in interface SessionManager
@ManagedAttribute(value="total time sessions have remained valid") public long getSessionTimeTotal()
@ManagedAttribute(value="mean time sessions remain valid (in s)") public double getSessionTimeMean()
@ManagedAttribute(value="standard deviation a session remained valid (in s)") public double getSessionTimeStdDev()
@ManagedAttribute(value="check remote session id encoding") public boolean isCheckingRemoteSessionIdEncoding()
isCheckingRemoteSessionIdEncoding
in interface SessionManager
SessionManager.isCheckingRemoteSessionIdEncoding()
public void setCheckingRemoteSessionIdEncoding(boolean remote)
setCheckingRemoteSessionIdEncoding
in interface SessionManager
remote
- True if absolute URLs are check for remoteness before being session encoded.SessionManager.setCheckingRemoteSessionIdEncoding(boolean)
public void renewSessionId(String oldClusterId, String oldNodeId, String newClusterId, String newNodeId)
renewSessionId
in interface SessionManager
oldClusterId
- the old cluster idoldNodeId
- the old node idnewClusterId
- the new cluster idnewNodeId
- the new node idSessionManager.renewSessionId(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
public void doSessionAttributeListeners(AbstractSession session, String name, Object old, Object value)
@Deprecated public SessionIdManager getMetaManager()
getMetaManager
in interface SessionManager
Copyright © 1995-2016 Webtide. All Rights Reserved.