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 DefaultSessionStorageEvaluatorthat 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 booleanisSessionStorageEnabled()Returnstrueif any Subject'sSessionmay be used to persist thatSubject's state,falseotherwise.booleanisSessionStorageEnabled(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 thesessionStorageEnabledproperty: IfsessionStorageEnabledis true (the default setting), a new session may be created to persist Subject state if necessary. IfsessionStorageEnabledisfalse, a new session will not be created to persist session state. Most applications use Sessions and are OK with the defaulttruesetting forsessionStorageEnabled.voidsetSessionStorageEnabled(boolean sessionStorageEnabled)Sets if any Subject'sSessionmay 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
sessionStorageEnabledproperty:- If
sessionStorageEnabledis true (the default setting), a new session may be created to persist Subject state if necessary. - If
sessionStorageEnabledisfalse, a new session will not be created to persist session state.
- If
truesetting forsessionStorageEnabled. However, if your application is a purely 100% stateless application that never uses sessions, you will want to setsessionStorageEnabledtofalse. Realize that afalsevalue 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:
isSessionStorageEnabledin interfaceSessionStorageEvaluator- Parameters:
subject- theSubjectfor which session state persistence may be enabled- Returns:
- the value of
isSessionStorageEnabled()and ignores theSubjectargument. - See Also:
Subject.getSession(),Subject.getSession(boolean)
- If the specified Subject already has an existing
-
isSessionStorageEnabled
public boolean isSessionStorageEnabled()
Returnstrueif any Subject'sSessionmay be used to persist thatSubject's state,falseotherwise. The default value istrue. N.B. This is a global configuration setting; setting this value tofalsewill disable sessions to persist Subject state for all Subjects that do not already have a Session. It should typically only be set tofalsefor 100% stateless applications (e.g. when sessions aren't used or when remote clients authenticate on every request).- Returns:
trueif any Subject'sSessionmay be used to persist thatSubject's state,falseotherwise.
-
setSessionStorageEnabled
public void setSessionStorageEnabled(boolean sessionStorageEnabled)
Sets if any Subject'sSessionmay be used to persist thatSubject's state. The default value istrue. N.B. This is a global configuration setting; setting this value tofalsewill disable sessions to persist Subject state for all Subjects that do not already have a Session. It should typically only be set tofalsefor 100% stateless applications (e.g. when sessions aren't used or when remote clients authenticate on every request).- Parameters:
sessionStorageEnabled- if any Subject'sSessionmay be used to persist thatSubject's state.
-
-