Class SimpleSession
java.lang.Object
org.apache.shiro.session.mgt.SimpleSession
- All Implemented Interfaces:
Serializable,ValidatingSession,Session
Simple
Session JavaBeans-compatible POJO implementation, intended to be used on the
business/server tier.- Since:
- 0.1
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final longprotected static final longprotected static final long -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanprotected voidexpire()getAttribute(Object key) Returns the object bound to this session identified by the specified key.Returns the keys of all the attributes stored under this session.getHost()Returns the host name or IP string of the host that originated this session, ornullif the host is unknown.getId()Returns the unique identifier assigned by the system upon session creation.Returns the last time the application received a request or method invocation from the user associated with this session.Returns the time the session was started; that is, the time the system created the instance.Returns the time the session was stopped, or null if the session is still active.longReturns the time in milliseconds that the session session may remain idle before expiring.inthashCode()Returns the hashCode.booleanReturns true if this session has expired, false otherwise.protected booleanprotected booleanDetermines if this session is expired.booleanisValid()protected booleanProvides an attribute-based comparison (no ID comparison) - incurred only when 'this' or the session object being compared for equality do not have a session id.removeAttribute(Object key) Removes (unbinds) the object bound to this session under the specifiedkeyname.voidsetAttribute(Object key, Object value) Binds the specifiedvalueto this session, uniquely identified by the specifiedkeyname.voidsetAttributes(Map<Object, Object> attributes) voidsetExpired(boolean expired) voidvoidsetId(Serializable id) voidsetLastAccessTime(Date lastAccessTime) voidsetStartTimestamp(Date startTimestamp) voidsetStopTimestamp(Date stopTimestamp) voidsetTimeout(long timeout) Sets the time in milliseconds that the session may remain idle before expiring.voidstop()Explicitly stops (invalidates) this session and releases all associated resources.toString()Returns the string representation of this SimpleSession, equal togetClass().getName() + ",id=" + getId().voidtouch()Explicitly updates thelastAccessTimeof this session to the current time when this method is invoked.voidvalidate()
-
Field Details
-
MILLIS_PER_SECOND
- See Also:
-
MILLIS_PER_MINUTE
- See Also:
-
MILLIS_PER_HOUR
- See Also:
-
-
Constructor Details
-
SimpleSession
public SimpleSession() -
SimpleSession
-
-
Method Details
-
getId
Description copied from interface:Session -
setId
-
getStartTimestamp
Description copied from interface:SessionReturns the time the session was started; that is, the time the system created the instance.- Specified by:
getStartTimestampin interfaceSession- Returns:
- The time the system created the session.
-
setStartTimestamp
-
getStopTimestamp
Returns the time the session was stopped, or null if the session is still active. A session may become stopped under a number of conditions:- If the user logs out of the system, their current session is terminated (released).
- If the session expires
- The application explicitly calls
stop() - If there is an internal system error and the session state can no longer accurately reflect the user's behavior, such in the case of a system crash
- Returns:
- The time the session was stopped, or null if the session is still active.
-
setStopTimestamp
-
getLastAccessTime
Description copied from interface:SessionReturns the last time the application received a request or method invocation from the user associated with this session. Application calls to this method do not affect this access time.- Specified by:
getLastAccessTimein interfaceSession- Returns:
- The time the user last interacted with the system.
- See Also:
-
setLastAccessTime
-
isExpired
Returns true if this session has expired, false otherwise. If the session has expired, no further user interaction with the system may be done under this session.- Returns:
- true if this session has expired, false otherwise.
-
setExpired
-
getTimeout
Description copied from interface:SessionReturns the time in milliseconds that the session session may remain idle before expiring.- A negative return value means the session will never expire.
- A non-negative return value (0 or greater) means the session expiration will occur if idle for that length of time.
HttpSession'sgetMaxInactiveInterval()method, the scale on this method is different: Shiro Sessions use millisecond values for timeout whereasHttpSession.getMaxInactiveIntervaluses seconds. Always use millisecond values with Shiro sessions.- Specified by:
getTimeoutin interfaceSession- Returns:
- the time in milliseconds the session may remain idle before expiring.
-
setTimeout
Description copied from interface:SessionSets the time in milliseconds that the session may remain idle before expiring.- A negative value means the session will never expire.
- A non-negative value (0 or greater) means the session expiration will occur if idle for that length of time.
HttpSession'sgetMaxInactiveInterval()method, the scale on this method is different: Shiro Sessions use millisecond values for timeout whereasHttpSession.getMaxInactiveIntervaluses seconds. Always use millisecond values with Shiro sessions.- Specified by:
setTimeoutin interfaceSession- Parameters:
timeout- the time in milliseconds that the session may remain idle before expiring.
-
getHost
Description copied from interface:SessionReturns the host name or IP string of the host that originated this session, ornullif the host is unknown. -
setHost
-
getAttributes
-
setAttributes
-
touch
Description copied from interface:SessionExplicitly updates thelastAccessTimeof this session to the current time when this method is invoked. This method can be used to ensure a session does not time out. Most programmers won't use this method directly and will instead rely on the last access time to be updated automatically as a result of an incoming web request or remote procedure call/method invocation. However, this method is particularly useful when supporting rich-client applications such as Java Web Start app, Java or Flash applets, etc. Although rare, it is possible in a rich-client environment that a user continuously interacts with the client-side application without a server-side method call ever being invoked. If this happens over a long enough period of time, the user's server-side session could time-out. Again, such cases are rare since most rich-clients frequently require server-side method invocations. In this example though, the user's session might still be considered valid because the user is actively "using" the application, just not communicating with the server. But because no server-side method calls are invoked, there is no way for the server to know if the user is sitting idle or not, so it must assume so to maintain session integrity. Thistouch()method could be invoked by the rich-client application code during those times to ensure that the next time a server-side method is invoked, the invocation will not throw anExpiredSessionException. In short terms, it could be used periodically to ensure a session does not time out. How often this rich-client "maintenance" might occur is entirely dependent upon the application and would be based on variables such as session timeout configuration, usage characteristics of the client application, network utilization and application server performance. -
stop
Description copied from interface:SessionExplicitly stops (invalidates) this session and releases all associated resources. If this session has already been authenticated (i.e. theSubjectthat owns this session has logged-in), calling this method explicitly might have undesired side effects: It is common for aSubjectimplementation to retain authentication state in theSession. If the session is explicitly stopped by application code by calling this method directly, it could clear out any authentication state that might exist, thereby effectively removing the "authenticated" state of theSubject. As such, you might considerlogging-outthe 'owning'Subjectinstead of manually calling this method, as a log out is expected to stop the corresponding session automatically, and also allows framework code to execute additional cleanup logic. -
isStopped
-
expire
-
isValid
- Specified by:
isValidin interfaceValidatingSession- Since:
- 0.9
-
isTimedOut
Determines if this session is expired.- Returns:
- true if the specified session has expired, false otherwise.
-
validate
- Specified by:
validatein interfaceValidatingSession- Throws:
InvalidSessionException
-
getAttributeKeys
Description copied from interface:SessionReturns the keys of all the attributes stored under this session. If there are no attributes, this returns an empty collection.- Specified by:
getAttributeKeysin interfaceSession- Returns:
- the keys of all attributes stored under this session, or an empty collection if there are no session attributes.
- Throws:
InvalidSessionException- if this session has stopped or expired prior to calling this method.
-
getAttribute
Description copied from interface:SessionReturns the object bound to this session identified by the specified key. If there is no object bound under the key,nullis returned.- Specified by:
getAttributein interfaceSession- Parameters:
key- the unique name of the object bound to this session- Returns:
- the object bound under the specified
keyname ornullif there is no object bound under that name.
-
setAttribute
Description copied from interface:SessionBinds the specifiedvalueto this session, uniquely identified by the specifiedkeyname. If there is already an object bound under thekeyname, that existing object will be replaced by the newvalue. If thevalueparameter is null, it has the same effect as ifremoveAttributewas called.- Specified by:
setAttributein interfaceSession- Parameters:
key- the name under which thevalueobject will be bound in this sessionvalue- the object to bind in this session.
-
removeAttribute
Description copied from interface:SessionRemoves (unbinds) the object bound to this session under the specifiedkeyname.- Specified by:
removeAttributein interfaceSession- Parameters:
key- the name uniquely identifying the object to remove- Returns:
- the object removed or
nullif there was no object bound under the namekey.
-
equals
Returnstrueif the specified argument is aninstanceofSimpleSessionand bothids are equal. If the argument is aSimpleSessionand either 'this' or the argument does not yet have an ID assigned, the value ofonEqualsis returned, which does a necessary attribute-based comparison when IDs are not available. Do your best to ensureSimpleSessioninstances receive an ID very early in their lifecycle to avoid the more expensive attributes-based comparison. -
onEquals
Provides an attribute-based comparison (no ID comparison) - incurred only when 'this' or the session object being compared for equality do not have a session id.- Parameters:
ss- the SimpleSession instance to compare for equality.- Returns:
- true if all the attributes, except the id, are equal to this object's attributes.
- Since:
- 1.0
-
hashCode
Returns the hashCode. If theidis notnull, its hashcode is returned immediately. If it isnull, an attributes-based hashCode will be calculated and returned. Do your best to ensureSimpleSessioninstances receive an ID very early in their lifecycle to avoid the more expensive attributes-based calculation. -
toString
-