Package org.apache.shiro.session.mgt
Interface NativeSessionManager
-
- All Superinterfaces:
SessionManager
- All Known Implementing Classes:
AbstractNativeSessionManager
,AbstractValidatingSessionManager
,DefaultSessionManager
public interface NativeSessionManager extends SessionManager
ANative
session manager is one that manages sessions natively - that is, it is directly responsible for the creation, persistence and removal ofSession
instances and their lifecycles.- Since:
- 1.0
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
checkValid(SessionKey key)
Returns quietly if the associated session is valid (it exists and is not stopped or expired) or throws anInvalidSessionException
indicating that the session id is invalid.Object
getAttribute(SessionKey sessionKey, Object attributeKey)
Returns the object bound to the associated session identified by the specified attribute key.Collection<Object>
getAttributeKeys(SessionKey sessionKey)
Returns all attribute keys maintained by the target session or an empty collection if there are no attributes.String
getHost(SessionKey key)
Returns the host name or IP string of the host where the session was started, if known.Date
getLastAccessTime(SessionKey key)
Returns the time the associatedSession
last interacted with the system.Date
getStartTimestamp(SessionKey key)
Returns the time the associatedSession
started (was created).long
getTimeout(SessionKey key)
Returns the time in milliseconds that the associated session may remain idle before expiring.boolean
isValid(SessionKey key)
Returnstrue
if the associated session is valid (it exists and is not stopped nor expired),false
otherwise.Object
removeAttribute(SessionKey sessionKey, Object attributeKey)
Removes (unbinds) the object bound to associatedSession
under the givenattributeKey
.void
setAttribute(SessionKey sessionKey, Object attributeKey, Object value)
Binds the specifiedvalue
to the associated session uniquely identified by theattributeKey
.void
setTimeout(SessionKey key, long maxIdleTimeInMillis)
Sets the time in milliseconds that the associated session may remain idle before expiring.void
stop(SessionKey key)
Explicitly stops the associated session, thereby releasing all of its resources.void
touch(SessionKey key)
Updates the last accessed time of the session identified bysessionId
.-
Methods inherited from interface org.apache.shiro.session.mgt.SessionManager
getSession, start
-
-
-
-
Method Detail
-
getStartTimestamp
Date getStartTimestamp(SessionKey key)
Returns the time the associatedSession
started (was created).- Parameters:
key
- the session key to use to look up the target session.- Returns:
- the time the specified
Session
started (was created). - See Also:
Session.getStartTimestamp()
-
getLastAccessTime
Date getLastAccessTime(SessionKey key)
Returns the time the associatedSession
last interacted with the system.- Parameters:
key
- the session key to use to look up the target session.- Returns:
- time the session last accessed the system
- See Also:
Session.getLastAccessTime()
,Session.touch()
-
isValid
boolean isValid(SessionKey key)
Returnstrue
if the associated session is valid (it exists and is not stopped nor expired),false
otherwise.- Parameters:
key
- the session key to use to look up the target session.- Returns:
true
if the session is valid (exists and is not stopped or expired),false
otherwise.
-
checkValid
void checkValid(SessionKey key) throws InvalidSessionException
Returns quietly if the associated session is valid (it exists and is not stopped or expired) or throws anInvalidSessionException
indicating that the session id is invalid. This might be preferred to be used instead ofisValid(org.apache.shiro.session.mgt.SessionKey)
since any exception thrown will definitively explain the reason for invalidation.- Parameters:
key
- the session key to use to look up the target session.- Throws:
InvalidSessionException
- if the session id is invalid (it does not exist or it is stopped or expired).
-
getTimeout
long getTimeout(SessionKey key) throws InvalidSessionException
Returns the time in milliseconds that the associated 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.
- Parameters:
key
- the session key to use to look up the target session.- Returns:
- the time in milliseconds that the associated session may remain idle before expiring.
- Throws:
InvalidSessionException
- if the session has been stopped or expired prior to calling this method.
-
setTimeout
void setTimeout(SessionKey key, long maxIdleTimeInMillis) throws InvalidSessionException
Sets the time in milliseconds that the associated 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.
- Parameters:
key
- the session key to use to look up the target session.maxIdleTimeInMillis
- the time in milliseconds that the associated session may remain idle before expiring.- Throws:
InvalidSessionException
- if the session has been stopped or expired prior to calling this method.
-
touch
void touch(SessionKey key) throws InvalidSessionException
Updates the last accessed time of the session identified bysessionId
. This can be used to explicitly ensure that a session does not time out.- Parameters:
key
- the session key to use to look up the target session.- Throws:
InvalidSessionException
- if the session has been stopped or expired prior to calling this method.- See Also:
Session.touch()
-
getHost
String getHost(SessionKey key)
Returns the host name or IP string of the host where the session was started, if known. If no host name or IP was specified when starting the session, this method returnsnull
- Parameters:
key
- the session key to use to look up the target session.- Returns:
- the host name or ip address of the host where the session originated, if known. If unknown,
this method returns
null
.
-
stop
void stop(SessionKey key) throws InvalidSessionException
Explicitly stops the associated session, thereby releasing all of its resources.- Parameters:
key
- the session key to use to look up the target session.- Throws:
InvalidSessionException
- if the session has stopped or expired prior to calling this method.- See Also:
Session.stop()
-
getAttributeKeys
Collection<Object> getAttributeKeys(SessionKey sessionKey)
Returns all attribute keys maintained by the target session or an empty collection if there are no attributes.- Parameters:
sessionKey
- the session key to use to look up the target session.- Returns:
- all attribute keys maintained by the target session or an empty collection if there are no attributes.
- Throws:
InvalidSessionException
- if the associated session has stopped or expired prior to calling this method.- See Also:
Session.getAttributeKeys()
-
getAttribute
Object getAttribute(SessionKey sessionKey, Object attributeKey) throws InvalidSessionException
Returns the object bound to the associated session identified by the specified attribute key. If there is no object bound under the attribute key for the given session,null
is returned.- Parameters:
sessionKey
- session key to use to look up the target session.attributeKey
- the unique name of the object bound to the associated session- Returns:
- the object bound under the
attributeKey
ornull
if there is no object bound. - Throws:
InvalidSessionException
- if the specified session has stopped or expired prior to calling this method.- See Also:
Session.getAttribute(Object key)
-
setAttribute
void setAttribute(SessionKey sessionKey, Object attributeKey, Object value) throws InvalidSessionException
Binds the specifiedvalue
to the associated session uniquely identified by theattributeKey
. If there is already a session attribute bound under theattributeKey
, that existing object will be replaced by the newvalue
. If thevalue
parameter is null, it has the same effect as if theremoveAttribute(SessionKey sessionKey, Object attributeKey)
method was called.- Parameters:
sessionKey
- the session key to use to look up the target session.attributeKey
- the key under which thevalue
object will be bound in this sessionvalue
- the object to bind in this session.- Throws:
InvalidSessionException
- if the specified session has stopped or expired prior to calling this method.- See Also:
Session.setAttribute(Object key, Object value)
-
removeAttribute
Object removeAttribute(SessionKey sessionKey, Object attributeKey) throws InvalidSessionException
Removes (unbinds) the object bound to associatedSession
under the givenattributeKey
.- Parameters:
sessionKey
- session key to use to look up the target session.attributeKey
- the key uniquely identifying the object to remove- Returns:
- the object removed or
null
if there was no object bound under the specifiedattributeKey
. - Throws:
InvalidSessionException
- if the specified session has stopped or expired prior to calling this method.- See Also:
Session.removeAttribute(Object key)
-
-