Package org.apache.shiro.mgt
Class DefaultSessionStorageEvaluator
- java.lang.Object
-
- org.apache.shiro.mgt.DefaultSessionStorageEvaluator
-
- All Implemented Interfaces:
SessionStorageEvaluator
public class DefaultSessionStorageEvaluator extends Object implements SessionStorageEvaluator
A DefaultSessionStorageEvaluator
that provides reasonable control over if and how Sessions may be used for storing Subject state. See theisSessionStorageEnabled(org.apache.shiro.subject.Subject)
method for exact behavior.- Since:
- 1.2
-
-
Constructor Summary
Constructors Constructor Description DefaultSessionStorageEvaluator()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
isSessionStorageEnabled()
Returnstrue
if any Subject'sSession
may be used to persist thatSubject
's state,false
otherwise.boolean
isSessionStorageEnabled(Subject subject)
This implementation functions as follows: If the specified Subject already has an existingSession
(typically because an application developer has calledsubject.getSession()
already), Shiro will use that existing session to store subject state. If a Subject does not yet have a Session, this implementation checks thesessionStorageEnabled
property: IfsessionStorageEnabled
is true (the default setting), a new session may be created to persist Subject state if necessary. IfsessionStorageEnabled
isfalse
, a new session will not be created to persist session state. Most applications use Sessions and are OK with the defaulttrue
setting forsessionStorageEnabled
.void
setSessionStorageEnabled(boolean sessionStorageEnabled)
Sets if any Subject'sSession
may be used to persist thatSubject
's state.
-
-
-
Method Detail
-
isSessionStorageEnabled
public boolean isSessionStorageEnabled(Subject subject)
This implementation functions as follows:- If the specified Subject already has an existing
Session
(typically because an application developer has calledsubject.getSession()
already), Shiro will use that existing session to store subject state. - If a Subject does not yet have a Session, this implementation checks the
sessionStorageEnabled
property:- If
sessionStorageEnabled
is true (the default setting), a new session may be created to persist Subject state if necessary. - If
sessionStorageEnabled
isfalse
, a new session will not be created to persist session state.
- If
true
setting forsessionStorageEnabled
. However, if your application is a purely 100% stateless application that never uses sessions, you will want to setsessionStorageEnabled
tofalse
. Realize that afalse
value will ensure that any subject login only retains the authenticated identity for the duration of a request. Any other requests, invocations or messages will not be authenticated.- Specified by:
isSessionStorageEnabled
in interfaceSessionStorageEvaluator
- Parameters:
subject
- theSubject
for which session state persistence may be enabled- Returns:
- the value of
isSessionStorageEnabled()
and ignores theSubject
argument. - See Also:
Subject.getSession()
,Subject.getSession(boolean)
- If the specified Subject already has an existing
-
isSessionStorageEnabled
public boolean isSessionStorageEnabled()
Returnstrue
if any Subject'sSession
may be used to persist thatSubject
's state,false
otherwise. The default value istrue
. N.B. This is a global configuration setting; setting this value tofalse
will disable sessions to persist Subject state for all Subjects that do not already have a Session. It should typically only be set tofalse
for 100% stateless applications (e.g. when sessions aren't used or when remote clients authenticate on every request).- Returns:
true
if any Subject'sSession
may be used to persist thatSubject
's state,false
otherwise.
-
setSessionStorageEnabled
public void setSessionStorageEnabled(boolean sessionStorageEnabled)
Sets if any Subject'sSession
may be used to persist thatSubject
's state. The default value istrue
. N.B. This is a global configuration setting; setting this value tofalse
will disable sessions to persist Subject state for all Subjects that do not already have a Session. It should typically only be set tofalse
for 100% stateless applications (e.g. when sessions aren't used or when remote clients authenticate on every request).- Parameters:
sessionStorageEnabled
- if any Subject'sSession
may be used to persist thatSubject
's state.
-
-