DelegatingSubject

Implementation of the {@code Subject} interface that delegates method calls to an underlying {@link hunt.shiro.mgt.SecurityManager SecurityManager} instance for security checks. It is essentially a {@code SecurityManager} proxy. <p/> This implementation does not maintain state such as roles and permissions (only {@code Subject} {@link #getPrincipals() principals}, such as usernames or user primary keys) for better performance in a stateless architecture. It instead asks the underlying {@code SecurityManager} every time to perform the authorization check. <p/> A common misconception in using this implementation is that an EIS resource (RDBMS, etc) would be &quot;hit&quot; every time a method is called. This is not necessarily the case and is up to the implementation of the underlying {@code SecurityManager} instance. If caching of authorization data is desired (to eliminate EIS round trips and therefore improve database performance), it is considered much more elegant to let the underlying {@code SecurityManager} implementation or its delegate components manage caching, not this class. A {@code SecurityManager} is considered a business-tier component, where caching strategies are better managed. <p/> Applications from large and clustered to simple and JVM-local all benefit from stateless architectures. This implementation plays a part in the stateless programming paradigm and should be used whenever possible.

class DelegatingSubject : Subject {}

Constructors

this
this(SecurityManager securityManager)
Undocumented in source.
this
this(PrincipalCollection principals, bool authenticated, string host, Session session, SecurityManager securityManager)
Undocumented in source.
this
this(PrincipalCollection principals, bool authenticated, string host, Session session, bool sessionCreationEnabled, SecurityManager securityManager)
Undocumented in source.

Members

Functions

assertAuthzCheckPossible
void assertAuthzCheckPossible()
Undocumented in source. Be warned that the author may not have intended to support it.
associateWith
Callable!(V) associateWith(Callable!(V) callable)
Undocumented in source. Be warned that the author may not have intended to support it.
associateWith
Runnable associateWith(Runnable runnable)
Undocumented in source. Be warned that the author may not have intended to support it.
checkPermission
void checkPermission(string permission)
Undocumented in source. Be warned that the author may not have intended to support it.
checkPermission
void checkPermission(Permission permission)
Undocumented in source. Be warned that the author may not have intended to support it.
checkPermissions
void checkPermissions(string[] permissions)
Undocumented in source. Be warned that the author may not have intended to support it.
checkPermissions
void checkPermissions(Collection!(Permission) permissions)
Undocumented in source. Be warned that the author may not have intended to support it.
checkRole
void checkRole(string role)
Undocumented in source. Be warned that the author may not have intended to support it.
checkRoles
void checkRoles(string[] roleIdentifiers)
Undocumented in source. Be warned that the author may not have intended to support it.
checkRoles
void checkRoles(Collection!(string) roles)
Undocumented in source. Be warned that the author may not have intended to support it.
createSessionContext
SessionContext createSessionContext()
Undocumented in source. Be warned that the author may not have intended to support it.
decorate
Session decorate(Session session)
Undocumented in source. Be warned that the author may not have intended to support it.
execute
V execute(Callable!(V) callable)
Undocumented in source. Be warned that the author may not have intended to support it.
execute
void execute(Runnable runnable)
Undocumented in source. Be warned that the author may not have intended to support it.
getHost
string getHost()

Returns the host name or IP associated with the client who created/is interacting with this Subject.

getPreviousPrincipals
PrincipalCollection getPreviousPrincipals()
Undocumented in source. Be warned that the author may not have intended to support it.
getPrincipal
Object getPrincipal()

@see Subject#getPrincipal()

getPrincipals
PrincipalCollection getPrincipals()
Undocumented in source. Be warned that the author may not have intended to support it.
getSecurityManager
SecurityManager getSecurityManager()
Undocumented in source. Be warned that the author may not have intended to support it.
getSession
Session getSession()
Undocumented in source. Be warned that the author may not have intended to support it.
getSession
Session getSession(bool create)
Undocumented in source. Be warned that the author may not have intended to support it.
hasAllRoles
bool hasAllRoles(Collection!(string) roleIdentifiers)
Undocumented in source. Be warned that the author may not have intended to support it.
hasAllRoles
bool hasAllRoles(string[] roleIdentifiers)
Undocumented in source. Be warned that the author may not have intended to support it.
hasPrincipals
bool hasPrincipals()
Undocumented in source. Be warned that the author may not have intended to support it.
hasRole
bool hasRole(string roleIdentifier)
Undocumented in source. Be warned that the author may not have intended to support it.
hasRoles
bool[] hasRoles(List!(string) roleIdentifiers)
Undocumented in source. Be warned that the author may not have intended to support it.
hasRoles
bool[] hasRoles(string[] roleIdentifiers)
Undocumented in source. Be warned that the author may not have intended to support it.
isAuthenticated
bool isAuthenticated()
Undocumented in source. Be warned that the author may not have intended to support it.
isPermitted
bool isPermitted(string permission)
Undocumented in source. Be warned that the author may not have intended to support it.
isPermitted
bool isPermitted(Permission permission)
Undocumented in source. Be warned that the author may not have intended to support it.
isPermitted
bool[] isPermitted(string[] permissions)
Undocumented in source. Be warned that the author may not have intended to support it.
isPermitted
bool[] isPermitted(List!(Permission) permissions)
Undocumented in source. Be warned that the author may not have intended to support it.
isPermittedAll
bool isPermittedAll(string[] permissions)
Undocumented in source. Be warned that the author may not have intended to support it.
isPermittedAll
bool isPermittedAll(Collection!(Permission) permissions)
Undocumented in source. Be warned that the author may not have intended to support it.
isRemembered
bool isRemembered()
Undocumented in source. Be warned that the author may not have intended to support it.
isRunAs
bool isRunAs()
Undocumented in source. Be warned that the author may not have intended to support it.
isSessionCreationEnabled
bool isSessionCreationEnabled()

Returns {@code true} if this Subject is allowed to create sessions, {@code false} otherwise.

login
void login(AuthenticationToken token)
Undocumented in source. Be warned that the author may not have intended to support it.
logout
void logout()
Undocumented in source. Be warned that the author may not have intended to support it.
releaseRunAs
PrincipalCollection releaseRunAs()
Undocumented in source. Be warned that the author may not have intended to support it.
runAs
void runAs(PrincipalCollection principals)
Undocumented in source. Be warned that the author may not have intended to support it.

Variables

authenticated
bool authenticated;
Undocumented in source.
host
string host;
Undocumented in source.
principals
PrincipalCollection principals;
Undocumented in source.
securityManager
SecurityManager securityManager;
Undocumented in source.
session
Session session;
Undocumented in source.
sessionCreationEnabled
bool sessionCreationEnabled;

Inherited Members

From Subject

DEFAULT_NAME
enum string DEFAULT_NAME;
Undocumented in source.
getPrincipal
Object getPrincipal()

Returns this Subject's application-wide uniquely identifying principal, or {@code null} if this Subject is anonymous because it doesn't yet have any associated account data (for example, if they haven't logged in). <p/> The term <em>principal</em> is just a fancy security term for any identifying attribute(s) of an application user, such as a username, or user id, or public key, or anything else you might use in your application to identify a user. <h4>Uniqueness</h4> Although given names and family names (first/last) are technically considered principals as well, Shiro expects the object returned from this method to be an identifying attribute unique across your entire application. <p/> This implies that things like given names and family names are usually poor candidates as return values since they are rarely guaranteed to be unique; Things often used for this value: <ul> <li>A {@code long} RDBMS surrogate primary key</li> <li>An application-unique username</li> <li>A {@link java.util.UUID UUID}</li> <li>An LDAP Unique ID</li> </ul> or any other similar suitable unique mechanism valuable to your application. <p/> Most implementations will simply return <code>{@link #getPrincipals()}.{@link hunt.shiro.subject.PrincipalCollection#getPrimaryPrincipal() getPrimaryPrincipal()}</code>

getPrincipals
PrincipalCollection getPrincipals()

Returns this Subject's principals (identifying attributes) in the form of a {@code PrincipalCollection} or {@code null} if this Subject is anonymous because it doesn't yet have any associated account data (for example, if they haven't logged in). <p/> The word &quot;principals&quot; is nothing more than a fancy security term for identifying attributes associated with a Subject, aka, application user. For example, user id, a surname (family/last name), given (first) name, social security number, nickname, username, etc, are all examples of a principal.

isPermitted
bool isPermitted(string permission)

Returns {@code true} if this Subject is permitted to perform an action or access a resource summarized by the specified permission string. <p/> This is an overloaded method for the corresponding type-safe {@link Permission Permission} variant. Please see the class-level JavaDoc for more information on these string-based permission methods.

isPermitted
bool isPermitted(Permission permission)

Returns {@code true} if this Subject is permitted to perform an action or access a resource summarized by the specified permission. <p/> More specifically, this method determines if any {@code Permission}s associated with the subject {@link Permission#implies(Permission) imply} the specified permission.

isPermitted
bool[] isPermitted(string[] permissions)

Checks if this Subject implies the given permission strings and returns a bool array indicating which permissions are implied. <p/> This is an overloaded method for the corresponding type-safe {@link Permission Permission} variant. Please see the class-level JavaDoc for more information on these string-based permission methods.

isPermitted
bool[] isPermitted(List!(Permission) permissions)

Checks if this Subject implies the given Permissions and returns a bool array indicating which permissions are implied. <p/> More specifically, this method should determine if each {@code Permission} in the array is {@link Permission#implies(Permission) implied} by permissions already associated with the subject. <p/> This is primarily a performance-enhancing method to help reduce the number of {@link #isPermitted} invocations over the wire in client/server systems.

isPermittedAll
bool isPermittedAll(string[] permissions)

Returns {@code true} if this Subject implies all of the specified permission strings, {@code false} otherwise. <p/> This is an overloaded method for the corresponding type-safe {@link hunt.shiro.authz.Permission Permission} variant. Please see the class-level JavaDoc for more information on these string-based permission methods.

isPermittedAll
bool isPermittedAll(Collection!(Permission) permissions)

Returns {@code true} if this Subject implies all of the specified permissions, {@code false} otherwise. <p/> More specifically, this method determines if all of the given {@code Permission}s are {@link Permission#implies(Permission) implied by} permissions already associated with this Subject.

checkPermission
void checkPermission(string permission)

Ensures this Subject implies the specified permission string. <p/> If this subject's existing associated permissions do not {@link Permission#implies(Permission)} imply} the given permission, an {@link hunt.shiro.authz.AuthorizationException} will be thrown. <p/> This is an overloaded method for the corresponding type-safe {@link Permission Permission} variant. Please see the class-level JavaDoc for more information on these string-based permission methods.

checkPermission
void checkPermission(Permission permission)

Ensures this Subject {@link Permission#implies(Permission) implies} the specified {@code Permission}. <p/> If this subject's existing associated permissions do not {@link Permission#implies(Permission) imply} the given permission, an {@link hunt.shiro.authz.AuthorizationException} will be thrown.

checkPermissions
void checkPermissions(string[] permissions)

Ensures this Subject {@link hunt.shiro.authz.Permission#implies(hunt.shiro.authz.Permission) implies} all of the specified permission strings. <p/> If this subject's existing associated permissions do not {@link hunt.shiro.authz.Permission#implies(hunt.shiro.authz.Permission) imply} all of the given permissions, an {@link hunt.shiro.authz.AuthorizationException} will be thrown. <p/> This is an overloaded method for the corresponding type-safe {@link Permission Permission} variant. Please see the class-level JavaDoc for more information on these string-based permission methods.

checkPermissions
void checkPermissions(Collection!(Permission) permissions)

Ensures this Subject {@link hunt.shiro.authz.Permission#implies(hunt.shiro.authz.Permission) implies} all of the specified permission strings. <p/> If this subject's existing associated permissions do not {@link hunt.shiro.authz.Permission#implies(hunt.shiro.authz.Permission) imply} all of the given permissions, an {@link hunt.shiro.authz.AuthorizationException} will be thrown.

hasRole
bool hasRole(string roleIdentifier)

Returns {@code true} if this Subject has the specified role, {@code false} otherwise.

hasRoles
bool[] hasRoles(List!(string) roleIdentifiers)

Checks if this Subject has the specified roles, returning a bool array indicating which roles are associated. <p/> This is primarily a performance-enhancing method to help reduce the number of {@link #hasRole} invocations over the wire in client/server systems.

hasRoles
bool[] hasRoles(string[] roleIdentifiers)
Undocumented in source.
hasAllRoles
bool hasAllRoles(Collection!(string) roleIdentifiers)

Returns {@code true} if this Subject has all of the specified roles, {@code false} otherwise.

hasAllRoles
bool hasAllRoles(string[] roleIdentifiers)
Undocumented in source.
checkRole
void checkRole(string roleIdentifier)

Asserts this Subject has the specified role by returning quietly if they do or throwing an {@link hunt.shiro.authz.AuthorizationException} if they do not.

checkRoles
void checkRoles(Collection!(string) roleIdentifiers)

Asserts this Subject has all of the specified roles by returning quietly if they do or throwing an {@link hunt.shiro.authz.AuthorizationException} if they do not.

checkRoles
void checkRoles(string[] roleIdentifiers)

Same as {@link #checkRoles(Collection!(string) roleIdentifiers) checkRoles(Collection!(string) roleIdentifiers)} but doesn't require a collection as a an argument. Asserts this Subject has all of the specified roles by returning quietly if they do or throwing an {@link hunt.shiro.authz.AuthorizationException} if they do not.

login
void login(AuthenticationToken token)

Performs a login attempt for this Subject/user. If unsuccessful, an {@link AuthenticationException} is thrown, the subclass of which identifies why the attempt failed. If successful, the account data associated with the submitted principals/credentials will be associated with this {@code Subject} and the method will return quietly. <p/> Upon returning quietly, this {@code Subject} instance can be considered authenticated and {@link #getPrincipal() getPrincipal()} will be non-null and {@link #isAuthenticated() isAuthenticated()} will be {@code true}.

isAuthenticated
bool isAuthenticated()

Returns {@code true} if this Subject/user proved their identity <em>during their current session</em> by providing valid credentials matching those known to the system, {@code false} otherwise. <p/> Note that even if this Subject's identity has been remembered via 'remember me' services, this method will still return {@code false} unless the user has actually logged in with proper credentials <em>during their current session</em>. See the {@link #isRemembered() isRemembered()} method JavaDoc for more.

isRemembered
bool isRemembered()

Returns {@code true} if this {@code Subject} has an identity (it is not anonymous) and the identity (aka {@link #getPrincipals() principals}) is remembered from a successful authentication during a previous session. <p/> Although the underlying implementation determines exactly how this method functions, most implementations have this method act as the logical equivalent to this code: <pre> {@link #getPrincipal() getPrincipal()} !is null && !{@link #isAuthenticated() isAuthenticated()}</pre> <p/> Note as indicated by the above code example, if a {@code Subject} is remembered, they are <em>NOT</em> considered authenticated. A check against {@link #isAuthenticated() isAuthenticated()} is a more strict check than that reflected by this method. For example, a check to see if a subject can access financial information should almost always depend on {@link #isAuthenticated() isAuthenticated()} to <em>guarantee</em> a verified identity, and not this method. <p/> Once the subject is authenticated, they are no longer considered only remembered because their identity would have been verified during the current session. <h4>Remembered vs Authenticated</h4> Authentication is the process of <em>proving</em> you are who you say you are. When a user is only remembered, the remembered identity gives the system an idea who that user probably is, but in reality, has no way of absolutely <em>guaranteeing</em> if the remembered {@code Subject} represents the user currently using the application. <p/> So although many parts of the application can still perform user-specific logic based on the remembered {@link #getPrincipals() principals}, such as customized views, it should never perform highly-sensitive operations until the user has legitimately verified their identity by executing a successful authentication attempt. <p/> We see this paradigm all over the web, and we will use <a href="http://www.amazon.com">Amazon.com</a> as an

getSession
Session getSession()

Returns the application {@code Session} associated with this Subject. If no session exists when this method is called, a new session will be created, associated with this Subject, and then returned.

getSession
Session getSession(bool create)

Returns the application {@code Session} associated with this Subject. Based on the bool argument, this method functions as follows: <ul> <li>If there is already an existing session associated with this {@code Subject}, it is returned and the {@code create} argument is ignored.</li> <li>If no session exists and {@code create} is {@code true}, a new session will be created, associated with this {@code Subject} and then returned.</li> <li>If no session exists and {@code create} is {@code false}, {@code null} is returned.</li> </ul>

logout
void logout()

Logs out this Subject and invalidates and/or removes any associated entities, such as a {@link Session Session} and authorization data. After this method is called, the Subject is considered 'anonymous' and may continue to be used for another log-in if desired. <h3>Web Environment Warning</h3> Calling this method in web environments will usually remove any associated session cookie as part of session invalidation. Because cookies are part of the HTTP header, and headers can only be set before the response body (html, image, etc) is sent, this method in web environments must be called before <em>any</em> content has been rendered. <p/> The typical approach most applications use in this scenario is to redirect the user to a different location (e.g. home page) immediately after calling this method. This is an effect of the HTTP protocol itself and not a reflection of Shiro's implementation. <p/> Non-HTTP environments may of course use a logged-out subject for login again if desired.

execute
void execute(Runnable runnable)

Associates the specified {@code Runnable} with this {@code Subject} instance and then executes it on the currently running thread. If you want to execute the {@code Runnable} on a different thread, it is better to use the {@link #associateWith(Runnable)} method instead. <p/> <b>Note</b>: This method is primarily provided to execute existing/legacy Runnable implementations. It is better for new code to use {@link #execute(Callable)} since that supports the ability to return values and catch exceptions.

associateWith
Runnable associateWith(Runnable runnable)

Returns a {@code Runnable} instance matching the given argument while additionally ensuring that it will retain and execute under this Subject's identity. The returned object can be used with an {@link java.util.concurrent.Executor Executor} or another thread to execute as this Subject. <p/> This will effectively ensure that any calls to {@code SecurityUtils}.{@link SecurityUtils#getSubject() getSubject()} and related functionality will continue to function properly on any thread that executes the returned {@code Runnable} instance. <p/> *Note that if you need a return value to be returned as a result of the runnable's execution or if you need to react to any Exceptions, it is highly recommended to use the {@link #associateWith(java.util.concurrent.Callable) createCallable} method instead of this one.

runAs
void runAs(PrincipalCollection principals)

Allows this subject to 'run as' or 'assume' another identity indefinitely. This can only be called when the {@code Subject} instance already has an identity (i.e. they are remembered from a previous log-in or they have authenticated during their current session). <p/> Some notes about {@code runAs}: <ul> <li>You can tell if a {@code Subject} is 'running as' another identity by calling the {@link #isRunAs() isRunAs()} method.</li> <li>If running as another identity, you can determine what the previous 'pre run as' identity was by calling the {@link #getPreviousPrincipals() getPreviousPrincipals()} method.</li> <li>When you want a {@code Subject} to stop running as another identity, you can return to its previous 'pre run as' identity by calling the {@link #releaseRunAs() releaseRunAs()} method.</li> </ul>

isRunAs
bool isRunAs()

Returns {@code true} if this {@code Subject} is 'running as' another identity other than its original one or {@code false} otherwise (normal {@code Subject} state). See the {@link #runAs runAs} method for more information.

getPreviousPrincipals
PrincipalCollection getPreviousPrincipals()

Returns the previous 'pre run as' identity of this {@code Subject} before assuming the current {@link #runAs runAs} identity, or {@code null} if this {@code Subject} is not operating under an assumed identity (normal state). See the {@link #runAs runAs} method for more information.

releaseRunAs
PrincipalCollection releaseRunAs()

Releases the current 'run as' (assumed) identity and reverts back to the previous 'pre run as' identity that existed before {@code #runAs runAs} was called. <p/> This method returns 'run as' (assumed) identity being released or {@code null} if this {@code Subject} is not operating under an assumed identity.

Meta