Top Description Inners Fields Constructors Methods
org.apache.catalina.session

public Class StandardSession

extends Object
implements HttpSession, Session, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, org.apache.catalina.Session, jakarta.servlet.http.HttpSession
Imports
java.beans.PropertyChangeSupport, java.io.IOException, .NotSerializableException, .ObjectInputStream, .ObjectOutputStream, .ObjectStreamException, .Serializable, .WriteAbortedException, java.security.AccessController, .Principal, .PrivilegedAction, java.util.ArrayList, .Collections, .Enumeration, .HashSet, .Iterator, .List, .Map, .Set, java.util.concurrent.ConcurrentHashMap, .ConcurrentMap, java.util.concurrent.atomic.AtomicInteger, jakarta.servlet.ServletContext, jakarta.servlet.http.HttpSession, .HttpSessionActivationListener, .HttpSessionAttributeListener, .HttpSessionBindingEvent, .HttpSessionBindingListener, .HttpSessionEvent, .HttpSessionIdListener, .HttpSessionListener, org.apache.catalina.Context, .Globals, .Manager, .Session, .SessionEvent, .SessionListener, .TomcatPrincipal, org.apache.catalina.authenticator.SavedRequest, org.apache.catalina.security.SecurityUtil, org.apache.tomcat.util.ExceptionUtils, org.apache.tomcat.util.res.StringManager

Standard implementation of the Session interface. This object is serializable, so that it can be stored in persistent storage or transferred to a different JVM for distributable session support.

Implementation Note

An instance of this class represents both the internal (Session) and application level (HttpSession) view of the session. However, because the class itself is not declared public, Java logic outside of the org.apache.catalina.session package cannot cast an HttpSession view of this instance back to a Session view.

Implementation Note

If you add fields to this class, you must make sure that you carry them over in the read/writeObject methods so that this class is properly serialized.

Authors
Craig R. McClanahan, Sean Legassick, Jon S. Stevens

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
protected transient AtomicInteger
accessCount

The access count for this session.

protected transient boolean
activityCheck

The activity check for this session.

protected ConcurrentMap<String, Object>
attributes

The collection of user data attributes associated with this Session.

protected transient String
authType

The authentication type used to authenticate our cached Principal, if any.

protected long
creationTime

The time this session was created, in milliseconds since midnight, January 1, 1970 GMT.

protected static final String[]
EMPTY_ARRAY

Type array.

protected transient volatile boolean
expiring

We are currently processing a session expiration, so bypass certain IllegalStateException tests.

protected transient StandardSessionFacade
facade

The facade associated with this session.

protected String
id

The session identifier of this Session.

protected volatile boolean
isNew

Flag indicating whether this session is new or not.

protected volatile boolean
isValid

Flag indicating whether this session is valid or not.

protected transient boolean
lastAccessAtStart

The behavior of the last access check.

protected volatile long
lastAccessedTime

The last accessed time for this Session.

protected transient ArrayList<SessionListener>
listeners

The session event listeners for this Session.

protected transient Manager
manager

The Manager with which this Session is associated.

protected volatile int
maxInactiveInterval

The maximum time interval, in seconds, between client requests before the servlet container may invalidate this session.

protected transient Map<String, Object>
notes

Internal notes associated with this session by Catalina components and event listeners.

protected transient Principal
principal

The authenticated Principal associated with this session, if any

Implementation Note

This object is not saved and restored across session serializations!

private static final long
protected static final StringManager
sm

The string manager for this package.

protected final transient PropertyChangeSupport
support

The property change support for this component.

protected volatile long
thisAccessedTime

The current accessed time for this session.

Constructor Summary

AccessConstructor and Description
public
StandardSession(Manager
The manager with which this Session is associated
manager
)

Construct a new Session associated with the specified Manager.

Method Summary

Modifier and TypeMethod and Description
public void
access()

Implements org.apache.catalina.Session.access.

Update the accessed time information for this session.

public void
activate()

Perform internal processing required to activate this session.

public void
addSessionListener(SessionListener
the SessionListener instance that should be notified for session events
listener
)

Implements org.apache.catalina.Session.addSessionListener.

Add a session event listener to this component.

protected void
doReadObject(ObjectInputStream
The input stream to read from
stream
)

Read a serialized version of this session object from the specified object input stream.

protected void
doWriteObject(ObjectOutputStream
The output stream to write to
stream
)

Write a serialized version of this session object to the specified object output stream.

public void
endAccess()

Implements org.apache.catalina.Session.endAccess.

End the access.

protected boolean

Returns:

true if the attribute should be excluded from distribution, otherwise false
exclude
(String
The attribute name
name
,
Object
The attribute value
value
)

Should the given session attribute be excluded?

public void
expire()

Implements org.apache.catalina.Session.expire.

Perform the internal processing required to invalidate this session, without triggering an exception if the session has already expired.

public void
expire(boolean
Should we notify listeners about the demise of this session?
notify
)

Perform the internal processing required to invalidate this session, without triggering an exception if the session has already expired.

public void
fireSessionEvent(String
Event type
type
,
Object
Event data
data
)

Notify all session event listeners that a particular event has occurred for this Session.

public Object
getAttribute(String
Name of the attribute to be returned
name
)

Implements jakarta.servlet.http.HttpSession.getAttribute.

Return the object bound with the specified name in this session, or null if no object is bound with that name.

public Enumeration<String>
getAttributeNames()

Implements jakarta.servlet.http.HttpSession.getAttributeNames.

Return an Enumeration of String objects containing the names of the objects bound to this session.

public String
getAuthType()

Implements org.apache.catalina.Session.getAuthType.

Return the authentication type used to authenticate our cached Principal, if any.

public long
getCreationTime()

Implements jakarta.servlet.http.HttpSession.getCreationTime, org.apache.catalina.Session.getCreationTime.

Return the time when this session was created, in milliseconds since midnight, January 1, 1970 GMT.

public long
getCreationTimeInternal()

Implements org.apache.catalina.Session.getCreationTimeInternal.

Return the time when this session was created, in milliseconds since midnight, January 1, 1970 GMT, bypassing the session validation checks.

public String
getId()

Implements jakarta.servlet.http.HttpSession.getId, org.apache.catalina.Session.getId.

Return the session identifier for this session.

public String
getIdInternal()

Implements org.apache.catalina.Session.getIdInternal.

Return the session identifier for this session.

public long
getIdleTime()

Implements org.apache.catalina.Session.getIdleTime.

Return the idle time (in milliseconds) from last client access time.

public long
getIdleTimeInternal()

Implements org.apache.catalina.Session.getIdleTimeInternal.

Return the idle time from last client access time without invalidation check

public long
getLastAccessedTime()

Implements jakarta.servlet.http.HttpSession.getLastAccessedTime, org.apache.catalina.Session.getLastAccessedTime.

Return the last time the client sent a request associated with this session, as the number of milliseconds since midnight, January 1, 1970 GMT.

public long
getLastAccessedTimeInternal()

Implements org.apache.catalina.Session.getLastAccessedTimeInternal.

Return the last client access time without invalidation check

public Manager
getManager()

Implements org.apache.catalina.Session.getManager.

Return the Manager within which this Session is valid.

public int
getMaxInactiveInterval()

Implements jakarta.servlet.http.HttpSession.getMaxInactiveInterval, org.apache.catalina.Session.getMaxInactiveInterval.

Return the maximum time interval, in seconds, between client requests before the servlet container will invalidate the session.

public Object
getNote(String
Name of the note to be returned
name
)

Implements org.apache.catalina.Session.getNote.

Return the object bound with the specified name to the internal notes for this session, or null if no such binding exists.

public Iterator<String>
getNoteNames()

Implements org.apache.catalina.Session.getNoteNames.

Return an Iterator containing the String names of all notes bindings that exist for this session.

private boolean

Returns:

true, if authentication information shall be persisted; false otherwise
getPersistAuthentication
()

Return whether authentication information shall be persisted or not.

public Principal
getPrincipal()

Implements org.apache.catalina.Session.getPrincipal.

Return the authenticated Principal that is associated with this Session.

public ServletContext
getServletContext()

Implements jakarta.servlet.http.HttpSession.getServletContext.

Return the ServletContext to which this session belongs.

public HttpSession
getSession()

Implements org.apache.catalina.Session.getSession.

Return the HttpSession for which this object is the facade.

public long
getThisAccessedTime()

Implements org.apache.catalina.Session.getThisAccessedTime.

Return the last time the client sent a request associated with this session, as the number of milliseconds since midnight, January 1, 1970 GMT.

public long
getThisAccessedTimeInternal()

Implements org.apache.catalina.Session.getThisAccessedTimeInternal.

Return the last client access time without invalidation check

public void
invalidate()

Implements jakarta.servlet.http.HttpSession.invalidate.

Invalidates this session and unbinds any objects bound to it.

public boolean
isAttributeDistributable(String
The attribute name
name
,
Object
The attribute value
value
)

Implements org.apache.catalina.Session.isAttributeDistributable.

Does the session implementation support the distributing of the given attribute?

public boolean
isNew()

Implements jakarta.servlet.http.HttpSession.isNew.

Return true if the client does not yet know about the session, or if the client chooses not to join the session.

public boolean
isValid()

Implements org.apache.catalina.Session.isValid.

Return the isValid flag for this session.

protected boolean

Returns:

the isValid flag for this session without any expiration check.
isValidInternal
()

protected String[]

Returns:

the names of all currently defined session attributes as an array of Strings. If there are no defined attributes, a zero-length array is returned.
keys
()

public void
passivate()

Perform the internal processing required to passivate this session.

public void
readObjectData(ObjectInputStream
The object input stream to read from
stream
)

Read a serialized version of the contents of this session object from the specified object input stream, without requiring that the StandardSession itself have been serialized.

public void
recycle()

Implements org.apache.catalina.Session.recycle.

Release all object references, and initialize instance variables, in preparation for reuse of this object.

public void
removeAttribute(String
Name of the object to remove from this session.
name
)

Implements jakarta.servlet.http.HttpSession.removeAttribute.

Remove the object bound with the specified name from this session.

public void
removeAttribute(String
Name of the object to remove from this session.
name
,
boolean
Should we notify interested listeners that this attribute is being removed?
notify
)

Remove the object bound with the specified name from this session.

protected void
removeAttributeInternal(String
Name of the object to remove from this session.
name
,
boolean
Should we notify interested listeners that this attribute is being removed?
notify
)

Remove the object bound with the specified name from this session.

public void
removeNote(String
Name of the note to be removed
name
)

Implements org.apache.catalina.Session.removeNote.

Remove any object bound to the specified name in the internal notes for this session.

public void
removeSessionListener(SessionListener
remove the session listener, which will no longer be notified
listener
)

Implements org.apache.catalina.Session.removeSessionListener.

Remove a session event listener from this component.

public void
setAttribute(String
Name to which the object is bound, cannot be null
name
,
Object
Object to be bound, cannot be null
value
)

Implements jakarta.servlet.http.HttpSession.setAttribute.

Bind an object to this session, using the specified name.

public void
setAttribute(String
Name to which the object is bound, cannot be null
name
,
Object
Object to be bound, cannot be null
value
,
boolean
whether to notify session listeners
notify
)

Bind an object to this session, using the specified name.

public void
setAuthType(String
The new cached authentication type
authType
)

Implements org.apache.catalina.Session.setAuthType.

Set the authentication type used to authenticate our cached Principal, if any.

public void
setCreationTime(long
The new creation time
time
)

Implements org.apache.catalina.Session.setCreationTime.

Set the creation time for this session.

public void
setId(String
The new session identifier
id
)

Implements org.apache.catalina.Session.setId.

Set the session identifier for this session.

public void
setId(String
The new session identifier
id
,
boolean
Should any associated listeners be notified that a new session has been created?
notify
)

Implements org.apache.catalina.Session.setId.

Set the session identifier for this session and optionally notifies any associated listeners that a new session has been created.

public void
setManager(Manager
The new Manager
manager
)

Implements org.apache.catalina.Session.setManager.

Set the Manager within which this Session is valid.

public void
setMaxInactiveInterval(int
The new maximum interval
interval
)

Implements jakarta.servlet.http.HttpSession.setMaxInactiveInterval, org.apache.catalina.Session.setMaxInactiveInterval.

Set the maximum time interval, in seconds, between client requests before the servlet container will invalidate the session.

public void
setNew(boolean
The new value for the isNew flag
isNew
)

Implements org.apache.catalina.Session.setNew.

Set the isNew flag for this session.

public void
setNote(String
Name to which the object should be bound
name
,
Object
Object to be bound to the specified name
value
)

Implements org.apache.catalina.Session.setNote.

Bind an object to a specified name in the internal notes associated with this session, replacing any existing binding for this name.

public void
setPrincipal(Principal
The new Principal, or null if none
principal
)

Implements org.apache.catalina.Session.setPrincipal.

Set the authenticated Principal that is associated with this Session.

public void
setValid(boolean
The new value for the isValid flag
isValid
)

Implements org.apache.catalina.Session.setValid.

Set the isValid flag for this session.

public void
tellChangedSessionId(String
new session ID
newId
,
String
old session ID
oldId
,
boolean
Should any associated sessionListeners be notified that session ID has been changed?
notifySessionListeners
,
boolean
Should any associated ContainerListeners be notified that session ID has been changed?
notifyContainerListeners
)

Implements org.apache.catalina.Session.tellChangedSessionId.

Inform the listeners about the change session ID.

public void
tellNew()

Inform the listeners about the new session.

public String
toString()

Overrides java.lang.Object.toString.

Return a string representation of this object.

public void
writeObjectData(ObjectOutputStream
The object output stream to write to
stream
)

Write a serialized version of the contents of this session object to the specified object output stream, without requiring that the StandardSession itself have been serialized.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait