|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.shiro.session.mgt.eis.AbstractSessionDAO
public abstract class AbstractSessionDAO
An abstract SessionDAO
implementation that performs some sanity checks on session creation and reading and
allows for pluggable Session ID generation strategies if desired. The SessionDAO
update
and delete
methods are left to
subclasses.
SessionIdGenerator
for custom ID generation strategies. This is
optional, as the default generator is probably sufficient for most cases. Subclass implementations that do use a
generator (default or custom) will want to call the
generateSessionId(org.apache.shiro.session.Session)
method from within their doCreate(org.apache.shiro.session.Session)
implementations.
Subclass implementations that rely on the EIS data store to generate the ID automatically (e.g. when the session
ID is also an auto-generated primary key), they can simply ignore the SessionIdGenerator
concept
entirely and just return the data store's ID from the doCreate(org.apache.shiro.session.Session)
implementation.
Constructor Summary | |
---|---|
AbstractSessionDAO()
Default no-arg constructor that defaults the sessionIdGenerator to be a
JavaUuidSessionIdGenerator . |
Method Summary | |
---|---|
protected void |
assignSessionId(Session session,
Serializable sessionId)
Utility method available to subclasses that wish to assign a generated session ID to the session instance directly. |
Serializable |
create(Session session)
Creates the session by delegating EIS creation to subclasses via the doCreate(org.apache.shiro.session.Session) method, and then
asserting that the returned sessionId is not null. |
protected abstract Serializable |
doCreate(Session session)
Subclass hook to actually persist the given Session instance to the underlying EIS. |
protected abstract Session |
doReadSession(Serializable sessionId)
Subclass implementation hook that retrieves the Session object from the underlying EIS or null if a
session with that ID could not be found. |
protected Serializable |
generateSessionId(Session session)
Generates a new ID to be applied to the specified session instance. |
SessionIdGenerator |
getSessionIdGenerator()
Returns the SessionIdGenerator used by the generateSessionId(org.apache.shiro.session.Session)
method. |
Session |
readSession(Serializable sessionId)
Retrieves the Session object from the underlying EIS identified by sessionId by delegating to the doReadSession(java.io.Serializable) method. |
void |
setSessionIdGenerator(SessionIdGenerator sessionIdGenerator)
Sets the SessionIdGenerator used by the generateSessionId(org.apache.shiro.session.Session)
method. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface org.apache.shiro.session.mgt.eis.SessionDAO |
---|
delete, getActiveSessions, update |
Constructor Detail |
---|
public AbstractSessionDAO()
sessionIdGenerator
to be a
JavaUuidSessionIdGenerator
.
Method Detail |
---|
public SessionIdGenerator getSessionIdGenerator()
SessionIdGenerator
used by the generateSessionId(org.apache.shiro.session.Session)
method. Unless overridden by the setSessionIdGenerator(SessionIdGenerator)
method, the default instance
is a JavaUuidSessionIdGenerator
.
SessionIdGenerator
used by the generateSessionId(org.apache.shiro.session.Session)
method.public void setSessionIdGenerator(SessionIdGenerator sessionIdGenerator)
SessionIdGenerator
used by the generateSessionId(org.apache.shiro.session.Session)
method. Unless overridden by this method, the default instance ss a JavaUuidSessionIdGenerator
.
sessionIdGenerator
- the SessionIdGenerator
to use in the
generateSessionId(org.apache.shiro.session.Session)
method.protected Serializable generateSessionId(Session session)
session
instance. This method is usually called
from within a subclass's doCreate(org.apache.shiro.session.Session)
implementation where they assign the returned id to the session
instance and then create a record with this ID in the EIS data store.
Subclass implementations backed by EIS data stores that auto-generate IDs during record creation, such as
relational databases, don't need to use this method or the sessionIdGenerator
attribute - they can simply return the data store's generated ID from the doCreate(org.apache.shiro.session.Session)
implementation
if desired.
This implementation uses the configured
SessionIdGenerator
to create
the ID.
session
- the new session instance for which an ID will be generated and then assigned
public Serializable create(Session session)
doCreate(org.apache.shiro.session.Session)
method, and then
asserting that the returned sessionId is not null.
create
in interface SessionDAO
session
- Session object to create in the EIS and associate with an ID.
Session
object.protected void assignSessionId(Session session, Serializable sessionId)
AbstractSessionDAO
implementation directly, but it is provided so subclasses don't
need to know the Session
implementation if they don't need to.
This default implementation casts the argument to a SimpleSession
, Shiro's default EIS implementation.
session
- the session instance to which the sessionId will be appliedsessionId
- the id to assign to the specified session instance.protected abstract Serializable doCreate(Session session)
session
- the Session instance to persist to the EIS.
Session.getId()
.public Session readSession(Serializable sessionId) throws UnknownSessionException
doReadSession(java.io.Serializable)
method. If null
is returned from that method, an
UnknownSessionException
will be thrown.
readSession
in interface SessionDAO
sessionId
- the id of the session to retrieve from the EIS.
UnknownSessionException
- if the id specified does not correspond to any session in the EIS.protected abstract Session doReadSession(Serializable sessionId)
null
if a
session with that ID could not be found.
sessionId
- the id of the Session to retrieve.
null
if a
session with that ID could not be found.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |