public class DefaultSecurityManager extends SessionsSecurityManager
SecurityManager interface, based around a collection of
Realms. This implementation delegates its authentication, authorization, and session operations to wrapped
Authenticator,
Authorizer, and
SessionManager instances respectively via superclass implementation.
To greatly reduce and simplify configuration, this implementation (and its superclasses) will create suitable defaults for all of its required dependencies,
except the required one or more
Realms. Because
Realm implementations usually interact with an application's data model, they are almost always application specific; you will want to specify at least one custom
Realm implementation that 'knows' about your application's data/security model (via
RealmSecurityManager.setRealm(org.apache.shiro.realm.Realm) or one of the overloaded constructors). All other attributes in this class hierarchy will have suitable defaults for most enterprise applications.
RememberMe notice: This class supports the ability to configure a
RememberMeManager for
RememberMe identity services for login/logout, BUT, a default instance
will not be created for this attribute at startup.
Because RememberMe services are inherently client tier-specific and therefore aplication-dependent, if you want
RememberMe services enabled, you will have to specify an instance yourself via the
setRememberMeManager mutator. However if you're reading this JavaDoc with the expectation of operating in a Web environment, take a look at the
org.apache.shiro.web.DefaultWebSecurityManager implementation, which
does support
RememberMe services by default at startup.
| Modifier and Type | Field and Description |
|---|---|
protected RememberMeManager |
rememberMeManager
|
protected SubjectDAO |
subjectDAO
|
protected SubjectFactory |
subjectFactory
|
| Constructor and Description |
|---|
DefaultSecurityManager()
Default no-arg constructor.
|
DefaultSecurityManager(Collection
Supporting constructor for multiple
realms.
|
DefaultSecurityManager(Realm
Supporting constructor for a single-realm application.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
beforeLogout(Subject
|
protected void |
bind(Subject
Deprecated.
in favor of
save(subject).
|
protected SubjectContext |
copy(SubjectContext
|
protected SessionContext |
createSessionContext(SubjectContext
|
protected Subject |
createSubject(AuthenticationToken
Creates a
Subject instance for the user represented by the given method arguments.
|
Subject |
createSubject(SubjectContext
This implementation functions as follows:
Ensures the
SubjectContext is as populated as it can be, using heuristics to acquire data that may not have already been available to it (such as a referenced session or remembered principals). Calls
doCreateSubject(org.apache.shiro.subject.SubjectContext) to actually perform the
Subject instance creation. calls
save(subject) to ensure the constructed
Subject's state is accessible for future requests/invocations if necessary. returns the constructed
Subject instance.
|
protected SubjectContext |
createSubjectContext()
|
protected void |
delete(Subject
Removes (or 'unbinds') the Subject's state from the application, typically called during
logout(org.apache.shiro.subject.Subject)..
|
protected Subject |
doCreateSubject(SubjectContext
Actually creates a
Subject instance by delegating to the internal
subjectFactory.
|
protected SubjectContext |
ensureSecurityManager(SubjectContext
Determines if there is a
SecurityManager instance in the context, and if not, adds 'this' to the context.
|
protected PrincipalCollection |
getRememberedIdentity(SubjectContext
|
RememberMeManager |
getRememberMeManager()
|
protected SessionKey |
getSessionKey(SubjectContext
|
SubjectDAO |
getSubjectDAO()
Returns the
SubjectDAO responsible for persisting Subject state, typically used after login or when an Subject identity is discovered (eg after RememberMe services).
|
SubjectFactory |
getSubjectFactory()
Returns the
SubjectFactory responsible for creating
Subject instances exposed to the application.
|
Subject |
login(Subject
First authenticates the
AuthenticationToken argument, and if successful, constructs a
Subject instance representing the authenticated account's identity.
|
void |
logout(Subject
Logs out the specified Subject from the system.
|
protected void |
onFailedLogin(AuthenticationToken
|
protected void |
onSuccessfulLogin(AuthenticationToken
|
protected void |
rememberMeFailedLogin(AuthenticationToken
|
protected void |
rememberMeLogout(Subject
|
protected void |
rememberMeSuccessfulLogin(AuthenticationToken
|
protected Session |
resolveContextSession(SubjectContext
|
protected SubjectContext |
resolvePrincipals(SubjectContext
Attempts to resolve an identity (a
PrincipalCollection) for the context using heuristics.
|
protected SubjectContext |
resolveSession(SubjectContext
Attempts to resolve any associated session based on the context and returns a context that represents this resolved
Session to ensure it may be referenced if necessary by the invoked
SubjectFactory that performs actual
Subject construction.
|
protected void |
save(Subject
Saves the subject's state to a persistent location for future reference if necessary.
|
void |
setRememberMeManager(RememberMeManager
|
void |
setSubjectDAO(SubjectDAO
Sets the
SubjectDAO responsible for persisting Subject state, typically used after login or when an Subject identity is discovered (eg after RememberMe services).
|
void |
setSubjectFactory(SubjectFactory
Sets the
SubjectFactory responsible for creating
Subject instances exposed to the application.
|
protected void |
stopSession(Subject
|
protected void |
unbind(Subject
Deprecated.
in Shiro 1.2 in favor of
delete(org.apache.shiro.subject.Subject)
|
afterCacheManagerSet, afterSessionManagerSet, applyCacheManagerToSessionManager, destroy, getSession, getSessionManager, setSessionManager, startafterRealmsSet, checkPermission, checkPermission, checkPermissions, checkPermissions, checkRole, checkRoles, checkRoles, getAuthorizer, hasAllRoles, hasRole, hasRoles, isPermitted, isPermitted, isPermitted, isPermitted, isPermittedAll, isPermittedAll, setAuthorizerauthenticate, getAuthenticator, setAuthenticatorapplyCacheManagerToRealms, getRealms, setRealm, setRealmsgetCacheManager, setCacheManagerprotected RememberMeManagerrememberMeManager
protected SubjectDAOsubjectDAO
protected SubjectFactorysubjectFactory
public DefaultSecurityManager()
public DefaultSecurityManager(RealmsingleRealm)
singleRealm - the single realm used by this SecurityManager.
public DefaultSecurityManager(Collection<Realm > realms)
realms.
realms - the realm instances backing this SecurityManager.
public SubjectFactorygetSubjectFactory()
SubjectFactory responsible for creating
Subject instances exposed to the application.
SubjectFactory responsible for creating
Subject instances exposed to the application.
public void setSubjectFactory(SubjectFactorysubjectFactory)
SubjectFactory responsible for creating
Subject instances exposed to the application.
subjectFactory - the
SubjectFactory responsible for creating
Subject instances exposed to the application.
public SubjectDAOgetSubjectDAO()
SubjectDAO responsible for persisting Subject state, typically used after login or when an Subject identity is discovered (eg after RememberMe services). Unless configured otherwise, the default implementation is a
DefaultSubjectDAO.
SubjectDAO responsible for persisting Subject state, typically used after login or when an Subject identity is discovered (eg after RememberMe services).
DefaultSubjectDAO
public void setSubjectDAO(SubjectDAOsubjectDAO)
SubjectDAO responsible for persisting Subject state, typically used after login or when an Subject identity is discovered (eg after RememberMe services). Unless configured otherwise, the default implementation is a
DefaultSubjectDAO.
subjectDAO - the
SubjectDAO responsible for persisting Subject state, typically used after login or when an Subject identity is discovered (eg after RememberMe services).
DefaultSubjectDAO
public RememberMeManagergetRememberMeManager()
public void setRememberMeManager(RememberMeManagerrememberMeManager)
protected SubjectContextcreateSubjectContext()
protected SubjectcreateSubject(AuthenticationToken token, AuthenticationInfo info, Subject existing)
Subject instance for the user represented by the given method arguments.
token - the
AuthenticationToken submitted for the successful authentication.
info - the
AuthenticationInfo of a newly authenticated user.
existing - the existing
Subject instance that initiated the authentication attempt
Subject instance that represents the context and session data for the newly authenticated subject.
@Deprecated protected void bind(Subjectsubject)
save(subject).
Subject instance created after authentication to the application for later use.
As of Shiro 1.2, this method has been deprecated in favor of
save(org.apache.shiro.subject.Subject), which this implementation now calls.
subject - the
Subject instance created after authentication to be bound to the application for later use.
save(org.apache.shiro.subject.Subject)
protected void rememberMeSuccessfulLogin(AuthenticationTokentoken, AuthenticationInfo info, Subject subject)
protected void rememberMeFailedLogin(AuthenticationTokentoken, AuthenticationException ex, Subject subject)
protected void rememberMeLogout(Subjectsubject)
public Subjectlogin(Subject subject, AuthenticationToken token) throws AuthenticationException
AuthenticationToken argument, and if successful, constructs a
Subject instance representing the authenticated account's identity.
Once constructed, the
Subject instance is then
bound to the application for subsequent access before being returned to the caller.
token - the authenticationToken to process for the login attempt.
subject - the subject against which the authentication attempt will occur
AuthenticationException - if there is a problem authenticating the specified
token.
protected void onSuccessfulLogin(AuthenticationTokentoken, AuthenticationInfo info, Subject subject)
protected void onFailedLogin(AuthenticationTokentoken, AuthenticationException ae, Subject subject)
protected void beforeLogout(Subjectsubject)
protected SubjectContextcopy(SubjectContext subjectContext)
public SubjectcreateSubject(SubjectContext subjectContext)
SubjectContext is as populated as it can be, using heuristics to acquire data that may not have already been available to it (such as a referenced session or remembered principals).doCreateSubject(org.apache.shiro.subject.SubjectContext) to actually perform the Subject instance creation.save(subject) to ensure the constructed Subject's state is accessible for future requests/invocations if necessary.Subject instance.subjectContext - any data needed to direct how the Subject should be constructed.
Subject instance reflecting the specified contextual data.
ensureSecurityManager(org.apache.shiro.subject.SubjectContext),
resolveSession(org.apache.shiro.subject.SubjectContext),
resolvePrincipals(org.apache.shiro.subject.SubjectContext),
doCreateSubject(org.apache.shiro.subject.SubjectContext),
save(org.apache.shiro.subject.Subject)
protected SubjectdoCreateSubject(SubjectContext context)
Subject instance by delegating to the internal
subjectFactory. By the time this method is invoked, all possible
SubjectContext data (session, principals, et. al.) has been made accessible using all known heuristics and will be accessible to the
subjectFactory via the
subjectContext.resolve* methods.
context - the populated context (data map) to be used by the
SubjectFactory when creating a
Subject instance.
Subject instance reflecting the data in the specified
SubjectContext data map.
getSubjectFactory(),
SubjectFactory.createSubject(org.apache.shiro.subject.SubjectContext)
protected void save(Subjectsubject)
subjectDAO and calls
subjectDAO.save(subject).
subject - the subject for which state will potentially be persisted
SubjectDAO.save(org.apache.shiro.subject.Subject)
protected void delete(Subjectsubject)
logout(org.apache.shiro.subject.Subject)..
This implementation merely delegates to the internal
subjectDAO and calls
delete(subject).
subject - the subject for which state will be removed
SubjectDAO.delete(org.apache.shiro.subject.Subject)
protected SubjectContextensureSecurityManager(SubjectContext context)
SecurityManager instance in the context, and if not, adds 'this' to the context. This ensures the SubjectFactory instance will have access to a SecurityManager during Subject construction if necessary.
context - the subject context data that may contain a SecurityManager instance.
SubjectFactory for subject creation.
protected SubjectContextresolveSession(SubjectContext context)
Session to ensure it may be referenced if necessary by the invoked
SubjectFactory that performs actual
Subject construction.
If there is a
Session already in the context because that is what the caller wants to be used for
Subject construction, or if no session is resolved, this method effectively does nothing returns the context method argument unaltered.
context - the subject context data that may resolve a Session instance.
SubjectFactory for subject creation.
protected SessionresolveContextSession(SubjectContext context) throws InvalidSessionException
InvalidSessionException
protected SessionKeygetSessionKey(SubjectContext context)
protected SubjectContextresolvePrincipals(SubjectContext context)
PrincipalCollection) for the context using heuristics. This implementation functions as follows:
resolve an identity. If so, this method does nothing and returns the method argument unaltered.getRememberedIdentity(org.apache.shiro.subject.SubjectContext). If that method returns a non-null value, place the remembered PrincipalCollection in the context.context - the subject context data that may provide (directly or indirectly through one of its values) a
PrincipalCollection identity.
SubjectFactory for subject creation.
protected SessionContextcreateSessionContext(SubjectContext subjectContext)
public void logout(Subjectsubject)
SecurityManager
Subject.logout(), not the
SecurityManager directly.
Framework developers on the other hand might find calling this method directly useful in certain cases.
subject - the subject to log out.
protected void stopSession(Subjectsubject)
@Deprecated protected void unbind(Subjectsubject)
delete(org.apache.shiro.subject.Subject)
logout(org.apache.shiro.subject.Subject).
This has been deprecated in Shiro 1.2 in favor of the
delete method. The implementation has been updated to invoke that method.
subject - the subject to unbind from the application as it will no longer be used.
protected PrincipalCollectiongetRememberedIdentity(SubjectContext subjectContext)