|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.shiro.session.mgt.AbstractSessionManager org.apache.shiro.session.mgt.AbstractNativeSessionManager
public abstract class AbstractNativeSessionManager
Abstract implementation supporting the NativeSessionManager
interface, supporting
SessionListener
s and application of the
globalSessionTimeout
.
Field Summary |
---|
Fields inherited from class org.apache.shiro.session.mgt.AbstractSessionManager |
---|
DEFAULT_GLOBAL_SESSION_TIMEOUT, MILLIS_PER_HOUR, MILLIS_PER_MINUTE, MILLIS_PER_SECOND |
Constructor Summary | |
---|---|
AbstractNativeSessionManager()
|
Method Summary | |
---|---|
protected void |
afterStopped(Session session)
|
protected void |
applyGlobalSessionTimeout(Session session)
|
protected Session |
beforeInvalidNotification(Session session)
Returns the session instance to use to pass to registered SessionListener s for notification
that the session has been invalidated (stopped or expired). |
void |
checkValid(SessionKey key)
Returns quietly if the associated session is valid (it exists and is not stopped or expired) or throws an InvalidSessionException indicating that the session id is invalid. |
protected Session |
createExposedSession(Session session,
SessionContext context)
|
protected Session |
createExposedSession(Session session,
SessionKey key)
|
protected abstract Session |
createSession(SessionContext context)
Creates a new Session Session instance based on the specified (possibly null )
initialization data. |
protected abstract Session |
doGetSession(SessionKey key)
|
Object |
getAttribute(SessionKey sessionKey,
Object attributeKey)
Returns the object bound to the associated session identified by the specified attribute key. |
Collection<Object> |
getAttributeKeys(SessionKey key)
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 associated Session last interacted with the system. |
Session |
getSession(SessionKey key)
Retrieves the session corresponding to the specified contextual data (such as a session ID if applicable), or null if no Session could be found. |
Collection<SessionListener> |
getSessionListeners()
|
Date |
getStartTimestamp(SessionKey key)
Returns the time the associated Session 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)
Returns true if the associated session is valid (it exists and is not stopped nor expired),
false otherwise. |
protected void |
notifyExpiration(Session session)
|
protected void |
notifyStart(Session session)
Notifies any interested SessionListener s that a Session has started. |
protected void |
notifyStop(Session session)
|
protected void |
onChange(Session s)
|
protected void |
onStart(Session session,
SessionContext context)
Template method that allows subclasses to react to a new session being created. |
protected void |
onStop(Session session)
|
protected void |
onStop(Session session,
SessionKey key)
|
Object |
removeAttribute(SessionKey sessionKey,
Object attributeKey)
Removes (unbinds) the object bound to associated Session under the given attributeKey . |
void |
setAttribute(SessionKey sessionKey,
Object attributeKey,
Object value)
Binds the specified value to the associated session uniquely identified by the attributeKey . |
void |
setSessionListeners(Collection<SessionListener> listeners)
|
void |
setTimeout(SessionKey key,
long maxIdleTimeInMillis)
Sets the time in milliseconds that the associated session may remain idle before expiring. |
Session |
start(SessionContext context)
Starts a new session based on the specified contextual initialization data, which can be used by the underlying implementation to determine how exactly to create the internal Session instance. |
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 by sessionId . |
Methods inherited from class org.apache.shiro.session.mgt.AbstractSessionManager |
---|
getGlobalSessionTimeout, setGlobalSessionTimeout |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public AbstractNativeSessionManager()
Method Detail |
---|
public void setSessionListeners(Collection<SessionListener> listeners)
public Collection<SessionListener> getSessionListeners()
public Session start(SessionContext context)
SessionManager
SessionFactory
which could use the context to construct the internal Session
instance in a specific manner. This allows pluggable Session
creation
logic by simply injecting a SessionFactory
into the SessionManager
instance.
start
in interface SessionManager
context
- the contextual initialization data that can be used by the implementation or underlying
SessionFactory
when instantiating the internal Session
instance.
SessionFactory.createSession(SessionContext)
protected abstract Session createSession(SessionContext context) throws AuthorizationException
Session Session
instance based on the specified (possibly null
)
initialization data. Implementing classes must manage the persistent state of the returned session such that it
could later be acquired via the getSession(SessionKey)
method.
context
- the initialization data that can be used by the implementation or underlying
SessionFactory
when instantiating the internal Session
instance.
Session
instance.
HostUnauthorizedException
- if the system access control policy restricts access based
on client location/IP and the specified hostAddress hasn't been enabled.
AuthorizationException
- if the system access control policy does not allow the currently executing
caller to start sessions.protected void applyGlobalSessionTimeout(Session session)
protected void onStart(Session session, SessionContext context)
session
- the session that was just created
.context
- the SessionContext
that was used to start the session.public Session getSession(SessionKey key) throws SessionException
SessionManager
null
if no Session could be found. If a session is found but invalid (stopped or expired), a
SessionException
will be thrown.
getSession
in interface SessionManager
key
- the Session key to use to look-up the Session
Session
instance corresponding to the given lookup key or null
if no session
could be acquired.
SessionException
- if a session was found but it was invalid (stopped/expired).protected abstract Session doGetSession(SessionKey key) throws InvalidSessionException
InvalidSessionException
protected Session createExposedSession(Session session, SessionContext context)
protected Session createExposedSession(Session session, SessionKey key)
protected Session beforeInvalidNotification(Session session)
SessionListener
s for notification
that the session has been invalidated (stopped or expired).
The default implementation returns an ImmutableProxiedSession
instance to ensure
that the specified session
argument is not modified by any listeners.
session
- the Session
object being invalidated.
Session
instance to use to pass to registered SessionListener
s for notification.protected void notifyStart(Session session)
SessionListener
s that a Session has started. This method is invoked
after the onStart
method is called.
session
- the session that has just started that will be delivered to any
registered
session listeners.SessionListener.onStart(org.apache.shiro.session.Session)
protected void notifyStop(Session session)
protected void notifyExpiration(Session session)
public Date getStartTimestamp(SessionKey key)
NativeSessionManager
Session
started (was created).
getStartTimestamp
in interface NativeSessionManager
key
- the session key to use to look up the target session.
Session
started (was created).Session.getStartTimestamp()
public Date getLastAccessTime(SessionKey key)
NativeSessionManager
Session
last interacted with the system.
getLastAccessTime
in interface NativeSessionManager
key
- the session key to use to look up the target session.
Session.getLastAccessTime()
,
Session.touch()
public long getTimeout(SessionKey key) throws InvalidSessionException
NativeSessionManager
getTimeout
in interface NativeSessionManager
key
- the session key to use to look up the target session.
InvalidSessionException
- if the session has been stopped or expired prior to calling this method.public void setTimeout(SessionKey key, long maxIdleTimeInMillis) throws InvalidSessionException
NativeSessionManager
setTimeout
in interface NativeSessionManager
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.
InvalidSessionException
- if the session has been stopped or expired prior to calling this method.public void touch(SessionKey key) throws InvalidSessionException
NativeSessionManager
sessionId
. This
can be used to explicitly ensure that a session does not time out.
touch
in interface NativeSessionManager
key
- the session key to use to look up the target session.
InvalidSessionException
- if the session has been stopped or expired prior to calling this method.Session.touch()
public String getHost(SessionKey key)
NativeSessionManager
null
getHost
in interface NativeSessionManager
key
- the session key to use to look up the target session.
null
.public Collection<Object> getAttributeKeys(SessionKey key)
NativeSessionManager
getAttributeKeys
in interface NativeSessionManager
key
- the session key to use to look up the target session.
Session.getAttributeKeys()
public Object getAttribute(SessionKey sessionKey, Object attributeKey) throws InvalidSessionException
NativeSessionManager
null
is returned.
getAttribute
in interface NativeSessionManager
sessionKey
- session key to use to look up the target session.attributeKey
- the unique name of the object bound to the associated session
attributeKey
or null
if there is no object bound.
InvalidSessionException
- if the specified session has stopped or expired prior to calling this method.Session.getAttribute(Object key)
public void setAttribute(SessionKey sessionKey, Object attributeKey, Object value) throws InvalidSessionException
NativeSessionManager
value
to the associated session uniquely identified by the attributeKey
.
If there is already a session attribute bound under the attributeKey
, that existing object will be
replaced by the new value
.
If the value
parameter is null, it has the same effect as if the
NativeSessionManager.removeAttribute(SessionKey sessionKey, Object attributeKey)
method was called.
setAttribute
in interface NativeSessionManager
sessionKey
- the session key to use to look up the target session.attributeKey
- the key under which the value
object will be bound in this sessionvalue
- the object to bind in this session.
InvalidSessionException
- if the specified session has stopped or expired prior to calling this method.Session.setAttribute(Object key, Object value)
public Object removeAttribute(SessionKey sessionKey, Object attributeKey) throws InvalidSessionException
NativeSessionManager
Session
under the given attributeKey
.
removeAttribute
in interface NativeSessionManager
sessionKey
- session key to use to look up the target session.attributeKey
- the key uniquely identifying the object to remove
null
if there was no object bound under the specified attributeKey
.
InvalidSessionException
- if the specified session has stopped or expired prior to calling this method.Session.removeAttribute(Object key)
public boolean isValid(SessionKey key)
NativeSessionManager
true
if the associated session is valid (it exists and is not stopped nor expired),
false
otherwise.
isValid
in interface NativeSessionManager
key
- the session key to use to look up the target session.
true
if the session is valid (exists and is not stopped or expired), false
otherwise.public void stop(SessionKey key) throws InvalidSessionException
NativeSessionManager
stop
in interface NativeSessionManager
key
- the session key to use to look up the target session.
InvalidSessionException
- if the session has stopped or expired prior to calling this method.Session.stop()
protected void onStop(Session session, SessionKey key)
protected void onStop(Session session)
protected void afterStopped(Session session)
public void checkValid(SessionKey key) throws InvalidSessionException
NativeSessionManager
InvalidSessionException
indicating that the session id is invalid. This
might be preferred to be used instead of NativeSessionManager.isValid(org.apache.shiro.session.mgt.SessionKey)
since any exception thrown will definitively explain
the reason for invalidation.
checkValid
in interface NativeSessionManager
key
- the session key to use to look up the target session.
InvalidSessionException
- if the session id is invalid (it does not exist or it is stopped or expired).protected void onChange(Session s)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |