Package org.apache.shiro.web.subject
Class WebSubject.Builder
- java.lang.Object
-
- org.apache.shiro.subject.Subject.Builder
-
- org.apache.shiro.web.subject.WebSubject.Builder
-
- Enclosing interface:
- WebSubject
public static class WebSubject.Builder extends Subject.Builder
AWebSubject.Builder
performs the same function as aSubject.Builder
, but additionally ensures that the Servlet request/response pair that is triggering the Subject instance's creation is retained for use by internal Shiro components as necessary.
-
-
Constructor Summary
Constructors Constructor Description Builder(ServletRequest request, ServletResponse response)
Constructs a newWeb.Builder
instance using theSecurityManager
obtained by callingSecurityUtils.
getSecurityManager()
.Builder(SecurityManager securityManager, ServletRequest request, ServletResponse response)
Constructs a newWeb.Builder
instance using the specifiedSecurityManager
instance to create theWebSubject
instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description WebSubject
buildWebSubject()
Returnssuper.buildSubject()
, but additionally ensures that the returned instance is aninstanceof
WebSubject
and to support a type-safe method so a caller does not have to cast.protected SubjectContext
newSubjectContextInstance()
Overrides the parent implementation to return a new instance of aDefaultWebSubjectContext
to account for the additional request/response pair.protected WebSubject.Builder
setRequest(ServletRequest request)
Called by theWebSubject.Builder
constructor, this method places the request object in the context map for later retrieval.protected WebSubject.Builder
setResponse(ServletResponse response)
Called by theWebSubject.Builder
constructor, this method places the response object in the context map for later retrieval.-
Methods inherited from class org.apache.shiro.subject.Subject.Builder
authenticated, buildSubject, contextAttribute, getSubjectContext, host, principals, session, sessionCreationEnabled, sessionId
-
-
-
-
Constructor Detail
-
Builder
public Builder(ServletRequest request, ServletResponse response)
Constructs a newWeb.Builder
instance using theSecurityManager
obtained by callingSecurityUtils.
getSecurityManager()
. If you want to specify your own SecurityManager instance, use theBuilder(SecurityManager, ServletRequest, ServletResponse)
constructor instead.- Parameters:
request
- the incoming ServletRequest that will be associated with the builtWebSubject
instance.response
- the outgoing ServletRequest paired with the ServletRequest that will be associated with the builtWebSubject
instance.
-
Builder
public Builder(SecurityManager securityManager, ServletRequest request, ServletResponse response)
Constructs a newWeb.Builder
instance using the specifiedSecurityManager
instance to create theWebSubject
instance.- Parameters:
securityManager
- theSecurityManager SecurityManager
instance to use to build theWebSubject
instance.request
- the incoming ServletRequest that will be associated with the builtWebSubject
instance.response
- the outgoing ServletRequest paired with the ServletRequest that will be associated with the builtWebSubject
instance.
-
-
Method Detail
-
newSubjectContextInstance
protected SubjectContext newSubjectContextInstance()
Overrides the parent implementation to return a new instance of aDefaultWebSubjectContext
to account for the additional request/response pair.- Overrides:
newSubjectContextInstance
in classSubject.Builder
- Returns:
- a new instance of a
DefaultWebSubjectContext
to account for the additional request/response pair.
-
setRequest
protected WebSubject.Builder setRequest(ServletRequest request)
Called by theWebSubject.Builder
constructor, this method places the request object in the context map for later retrieval.- Parameters:
request
- the incoming ServletRequest that triggered the creation of theWebSubject
instance.- Returns:
- 'this' for method chaining.
-
setResponse
protected WebSubject.Builder setResponse(ServletResponse response)
Called by theWebSubject.Builder
constructor, this method places the response object in the context map for later retrieval.- Parameters:
response
- the outgoing ServletRequest paired with the ServletRequest that triggered the creation of theWebSubject
instance.- Returns:
- 'this' for method chaining.
-
buildWebSubject
public WebSubject buildWebSubject()
Returnssuper.buildSubject()
, but additionally ensures that the returned instance is aninstanceof
WebSubject
and to support a type-safe method so a caller does not have to cast. Per the parent class's method JavaDoc, this method will return a new instance each time it is called.- Returns:
- a new
WebSubject
instance built by thisBuilder
.
-
-