Package org.springframework.session
Class MapSession
java.lang.Object
org.springframework.session.MapSession
- All Implemented Interfaces:
Serializable,Session
A Session implementation that is backed by a Map. The
defaults for the properties are:
- id - a secure random generated id
- creationTime - the moment the
MapSessionwas instantiated - lastAccessedTime - the moment the
MapSessionwas instantiated - maxInactiveInterval - 30 minutes
This implementation has no synchronization, so it is best to use the copy constructor when working on multiple threads.
- Since:
- 1.0
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final DurationDefaultsetMaxInactiveInterval(Duration)(30 minutes).static final intDefaultsetMaxInactiveInterval(Duration)(30 minutes) in seconds. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new instance with a secure randomly generated identifier.MapSession(String id) Creates a new instance with the specified id.MapSession(Session session) Creates a new instance from the providedSession.MapSession(SessionIdGenerator sessionIdGenerator) Creates a new instance using the specifiedSessionIdGeneratorto generate the session id. -
Method Summary
Modifier and TypeMethodDescriptionChanges the session id.boolean<T> TgetAttribute(String attributeName) Gets the Object associated with the specified name or null if no Object is associated to that name.Gets the attribute names that have a value associated with it.Gets the time when this session was created.getId()Gets a unique string that identifies theSession.Gets the last time thisSessionwas accessed.Gets the maximum inactive interval between requests before this session will be invalidated.Get the original session id.inthashCode()booleanReturns true if the session is expired.voidremoveAttribute(String attributeName) Removes the attribute with the provided attribute name.voidsetAttribute(String attributeName, Object attributeValue) Sets the attribute value for the provided attribute name.voidsetCreationTime(Instant creationTime) Sets the time that thisSessionwas created.voidSets the identifier for thisSession.voidsetLastAccessedTime(Instant lastAccessedTime) Sets the last accessed time.voidsetMaxInactiveInterval(Duration interval) Sets the maximum inactive interval between requests before this session will be invalidated.voidsetSessionIdGenerator(SessionIdGenerator sessionIdGenerator) Sets theSessionIdGeneratorto use when generating a new session id.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.session.Session
getAttributeOrDefault, getRequiredAttribute
-
Field Details
-
DEFAULT_MAX_INACTIVE_INTERVAL_SECONDS
public static final int DEFAULT_MAX_INACTIVE_INTERVAL_SECONDSDefaultsetMaxInactiveInterval(Duration)(30 minutes) in seconds.- See Also:
-
DEFAULT_MAX_INACTIVE_INTERVAL
DefaultsetMaxInactiveInterval(Duration)(30 minutes).
-
-
Constructor Details
-
MapSession
public MapSession()Creates a new instance with a secure randomly generated identifier. -
MapSession
Creates a new instance using the specifiedSessionIdGeneratorto generate the session id.- Parameters:
sessionIdGenerator- theSessionIdGeneratorto use.- Since:
- 3.2
-
MapSession
Creates a new instance with the specified id. This is preferred to the default constructor when the id is known to prevent unnecessary consumption on entropy which can be slow.- Parameters:
id- the identifier to use
-
MapSession
Creates a new instance from the providedSession.
-
-
Method Details
-
setLastAccessedTime
Description copied from interface:SessionSets the last accessed time.- Specified by:
setLastAccessedTimein interfaceSession- Parameters:
lastAccessedTime- the last accessed time
-
getCreationTime
Description copied from interface:SessionGets the time when this session was created.- Specified by:
getCreationTimein interfaceSession- Returns:
- the time when this session was created.
-
getId
Description copied from interface:SessionGets a unique string that identifies theSession. -
getOriginalId
Get the original session id.- Returns:
- the original session id
- See Also:
-
changeSessionId
Description copied from interface:SessionChanges the session id. After invoking theSession.getId()will return a new identifier.- Specified by:
changeSessionIdin interfaceSession- Returns:
- the new session id which
Session.getId()will now return
-
getLastAccessedTime
Description copied from interface:SessionGets the last time thisSessionwas accessed.- Specified by:
getLastAccessedTimein interfaceSession- Returns:
- the last time the client sent a request associated with the session
-
setMaxInactiveInterval
Description copied from interface:SessionSets the maximum inactive interval between requests before this session will be invalidated. A negative time indicates that the session will never timeout.- Specified by:
setMaxInactiveIntervalin interfaceSession- Parameters:
interval- the amount of time that theSessionshould be kept alive between client requests.
-
getMaxInactiveInterval
Description copied from interface:SessionGets the maximum inactive interval between requests before this session will be invalidated. A negative time indicates that the session will never timeout.- Specified by:
getMaxInactiveIntervalin interfaceSession- Returns:
- the maximum inactive interval between requests before this session will be invalidated. A negative time indicates that the session will never timeout.
-
isExpired
public boolean isExpired()Description copied from interface:SessionReturns true if the session is expired. -
getAttribute
Description copied from interface:SessionGets the Object associated with the specified name or null if no Object is associated to that name.- Specified by:
getAttributein interfaceSession- Type Parameters:
T- the return type of the attribute- Parameters:
attributeName- the name of the attribute to get- Returns:
- the Object associated with the specified name or null if no Object is associated to that name
-
getAttributeNames
Description copied from interface:SessionGets the attribute names that have a value associated with it. Each value can be passed intoSession.getAttribute(String)to obtain the attribute value.- Specified by:
getAttributeNamesin interfaceSession- Returns:
- the attribute names that have a value associated with it.
- See Also:
-
setAttribute
Description copied from interface:SessionSets the attribute value for the provided attribute name. If the attributeValue is null, it has the same result as removing the attribute withSession.removeAttribute(String).- Specified by:
setAttributein interfaceSession- Parameters:
attributeName- the attribute name to setattributeValue- the value of the attribute to set. If null, the attribute will be removed.
-
removeAttribute
Description copied from interface:SessionRemoves the attribute with the provided attribute name.- Specified by:
removeAttributein interfaceSession- Parameters:
attributeName- the name of the attribute to remove
-
setCreationTime
- Parameters:
creationTime- the time that thisSessionwas created.
-
setId
Sets the identifier for thisSession. The id should be a secure random generated value to prevent malicious users from guessing this value. The default is a secure random generated identifier.- Parameters:
id- the identifier for this session.
-
equals
-
hashCode
public int hashCode() -
setSessionIdGenerator
Sets theSessionIdGeneratorto use when generating a new session id.- Parameters:
sessionIdGenerator- theSessionIdGeneratorto use.- Since:
- 3.2
-