Class AuthorizingRealm
- java.lang.Object
-
- org.apache.shiro.realm.CachingRealm
-
- org.apache.shiro.realm.AuthenticatingRealm
-
- org.apache.shiro.realm.AuthorizingRealm
-
- All Implemented Interfaces:
LogoutAware
,Authorizer
,PermissionResolverAware
,RolePermissionResolverAware
,org.apache.shiro.cache.CacheManagerAware
,Realm
,org.apache.shiro.util.Initializable
,org.apache.shiro.util.Nameable
- Direct Known Subclasses:
AbstractLdapRealm
,DefaultLdapRealm
,JdbcRealm
,SimpleAccountRealm
public abstract class AuthorizingRealm extends AuthenticatingRealm implements Authorizer, org.apache.shiro.util.Initializable, PermissionResolverAware, RolePermissionResolverAware
AnAuthorizingRealm
extends theAuthenticatingRealm
's capabilities by adding Authorization (access control) support. This implementation will perform all role and permission checks automatically (and subclasses do not have to write this logic) as long as thegetAuthorizationInfo(org.apache.shiro.subject.PrincipalCollection)
method returns anAuthorizationInfo
. Please see that method's JavaDoc for an in-depth explanation. If you find that you do not want to utilize theAuthorizationInfo
construct, you are of course free to subclass theAuthenticatingRealm
directly instead and implement the remaining Realm interface methods directly. You might do this if you want have better control over how the Role and Permission checks occur for your specific data source. However, using AuthorizationInfo (and its default implementationSimpleAuthorizationInfo
) is sufficient in the large majority of Realm cases.- Since:
- 0.2
- See Also:
SimpleAuthorizationInfo
-
-
Constructor Summary
Constructors Constructor Description AuthorizingRealm()
AuthorizingRealm(CredentialsMatcher matcher)
AuthorizingRealm(org.apache.shiro.cache.CacheManager cacheManager)
AuthorizingRealm(org.apache.shiro.cache.CacheManager cacheManager, CredentialsMatcher matcher)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected void
afterCacheManagerSet()
This implementation attempts to acquire an authentication cache if one is not already configured.protected void
checkPermission(Permission permission, AuthorizationInfo info)
void
checkPermission(PrincipalCollection subjectIdentifier, String permission)
Ensures the corresponding Subject/user implies the specified permission String.void
checkPermission(PrincipalCollection principal, Permission permission)
Ensures a subject/userPermission.implies(Permission)
implies} the specified Permission.protected void
checkPermissions(Collection<Permission> permissions, AuthorizationInfo info)
void
checkPermissions(PrincipalCollection subjectIdentifier, String... permissions)
Ensures the corresponding Subject/userimplies
all of the specified permission strings.void
checkPermissions(PrincipalCollection principal, Collection<Permission> permissions)
Ensures the corresponding Subject/userimplies
all of the specified permission strings.protected void
checkRole(String role, AuthorizationInfo info)
void
checkRole(PrincipalCollection principal, String role)
Asserts the corresponding Subject/user has the specified role by returning quietly if they do or throwing anAuthorizationException
if they do not.protected void
checkRoles(Collection<String> roles, AuthorizationInfo info)
void
checkRoles(PrincipalCollection principal, String... roles)
Same ascheckRoles(PrincipalCollection subjectPrincipal, Collection<String> roleIdentifiers)
but doesn't require a collection as an argument.void
checkRoles(PrincipalCollection principal, Collection<String> roles)
Asserts the corresponding Subject/user has all of the specified roles by returning quietly if they do or throwing anAuthorizationException
if they do not.protected void
clearCachedAuthorizationInfo(PrincipalCollection principals)
Clears out the AuthorizationInfo cache entry for the specified account.protected void
doClearCache(PrincipalCollection principals)
Callssuper.doClearCache
to ensure any cached authentication data is removed and then callsclearCachedAuthorizationInfo(org.apache.shiro.subject.PrincipalCollection)
to remove any cached authorization data.protected abstract AuthorizationInfo
doGetAuthorizationInfo(PrincipalCollection principals)
Retrieves the AuthorizationInfo for the given principals from the underlying data store.org.apache.shiro.cache.Cache<Object,AuthorizationInfo>
getAuthorizationCache()
protected Object
getAuthorizationCacheKey(PrincipalCollection principals)
String
getAuthorizationCacheName()
protected AuthorizationInfo
getAuthorizationInfo(PrincipalCollection principals)
Returns an account's authorization-specific information for the specifiedprincipals
, ornull
if no account could be found.PermissionResolver
getPermissionResolver()
protected Collection<Permission>
getPermissions(AuthorizationInfo info)
RolePermissionResolver
getRolePermissionResolver()
boolean
hasAllRoles(PrincipalCollection principal, Collection<String> roleIdentifiers)
Returns true if the corresponding Subject/user has all of the specified roles, false otherwise.protected boolean
hasRole(String roleIdentifier, AuthorizationInfo info)
boolean
hasRole(PrincipalCollection principal, String roleIdentifier)
Returns true if the corresponding Subject/user has the specified role, false otherwise.protected boolean[]
hasRoles(List<String> roleIdentifiers, AuthorizationInfo info)
boolean[]
hasRoles(PrincipalCollection principal, List<String> roleIdentifiers)
Checks if the corresponding Subject/user has the specified roles, returning a boolean array indicating which roles are associated with the given subject.boolean
isAuthorizationCachingEnabled()
Returnstrue
if authorization caching should be utilized if aCacheManager
has beenconfigured
,false
otherwise.protected boolean[]
isPermitted(List<Permission> permissions, AuthorizationInfo info)
protected boolean
isPermitted(Permission permission, AuthorizationInfo info)
boolean
isPermitted(PrincipalCollection principals, String permission)
Returns true if the corresponding subject/user is permitted to perform an action or access a resource summarized by the specified permission string.boolean[]
isPermitted(PrincipalCollection subjectIdentifier, String... permissions)
Checks if the corresponding Subject implies the given permission strings and returns a boolean array indicating which permissions are implied.boolean[]
isPermitted(PrincipalCollection principals, List<Permission> permissions)
Checks if the corresponding Subject/user implies the given Permissions and returns a boolean array indicating which permissions are implied.boolean
isPermitted(PrincipalCollection principals, Permission permission)
Returns true if the corresponding subject/user is permitted to perform an action or access a resource summarized by the specified permission.protected boolean
isPermittedAll(Collection<Permission> permissions, AuthorizationInfo info)
boolean
isPermittedAll(PrincipalCollection subjectIdentifier, String... permissions)
Returns true if the corresponding Subject/user implies all of the specified permission strings, false otherwise.boolean
isPermittedAll(PrincipalCollection principal, Collection<Permission> permissions)
Returns true if the corresponding Subject/user implies all of the specified permissions, false otherwise.protected void
onInit()
Initializes this realm and potentially enables a cache, depending on configuration.void
setAuthorizationCache(org.apache.shiro.cache.Cache<Object,AuthorizationInfo> authorizationCache)
void
setAuthorizationCacheName(String authorizationCacheName)
void
setAuthorizationCachingEnabled(boolean authenticationCachingEnabled)
Sets whether or not authorization caching should be utilized if aCacheManager
has beenconfigured
,false
otherwise.void
setName(String name)
void
setPermissionResolver(PermissionResolver permissionResolver)
Sets the specified PermissionResolver on this instance.void
setRolePermissionResolver(RolePermissionResolver permissionRoleResolver)
Sets the specified RolePermissionResolver on this instance.-
Methods inherited from class org.apache.shiro.realm.AuthenticatingRealm
assertCredentialsMatch, clearCachedAuthenticationInfo, doGetAuthenticationInfo, getAuthenticationCache, getAuthenticationCacheKey, getAuthenticationCacheKey, getAuthenticationCacheName, getAuthenticationInfo, getAuthenticationTokenClass, getCredentialsMatcher, init, isAuthenticationCachingEnabled, isAuthenticationCachingEnabled, setAuthenticationCache, setAuthenticationCacheName, setAuthenticationCachingEnabled, setAuthenticationTokenClass, setCredentialsMatcher, supports
-
Methods inherited from class org.apache.shiro.realm.CachingRealm
clearCache, getAvailablePrincipal, getCacheManager, getName, isCachingEnabled, onLogout, setCacheManager, setCachingEnabled
-
-
-
-
Constructor Detail
-
AuthorizingRealm
public AuthorizingRealm()
-
AuthorizingRealm
public AuthorizingRealm(org.apache.shiro.cache.CacheManager cacheManager)
-
AuthorizingRealm
public AuthorizingRealm(CredentialsMatcher matcher)
-
AuthorizingRealm
public AuthorizingRealm(org.apache.shiro.cache.CacheManager cacheManager, CredentialsMatcher matcher)
-
-
Method Detail
-
setName
public void setName(String name)
- Specified by:
setName
in interfaceorg.apache.shiro.util.Nameable
- Overrides:
setName
in classAuthenticatingRealm
-
setAuthorizationCache
public void setAuthorizationCache(org.apache.shiro.cache.Cache<Object,AuthorizationInfo> authorizationCache)
-
getAuthorizationCache
public org.apache.shiro.cache.Cache<Object,AuthorizationInfo> getAuthorizationCache()
-
getAuthorizationCacheName
public String getAuthorizationCacheName()
-
setAuthorizationCacheName
public void setAuthorizationCacheName(String authorizationCacheName)
-
isAuthorizationCachingEnabled
public boolean isAuthorizationCachingEnabled()
Returnstrue
if authorization caching should be utilized if aCacheManager
has beenconfigured
,false
otherwise. The default value istrue
.- Returns:
true
if authorization caching should be utilized,false
otherwise.
-
setAuthorizationCachingEnabled
public void setAuthorizationCachingEnabled(boolean authenticationCachingEnabled)
Sets whether or not authorization caching should be utilized if aCacheManager
has beenconfigured
,false
otherwise. The default value istrue
.- Parameters:
authenticationCachingEnabled
- the value to set
-
getPermissionResolver
public PermissionResolver getPermissionResolver()
-
setPermissionResolver
public void setPermissionResolver(PermissionResolver permissionResolver)
Description copied from interface:PermissionResolverAware
Sets the specified PermissionResolver on this instance.- Specified by:
setPermissionResolver
in interfacePermissionResolverAware
- Parameters:
permissionResolver
- the PermissionResolver being set.
-
getRolePermissionResolver
public RolePermissionResolver getRolePermissionResolver()
-
setRolePermissionResolver
public void setRolePermissionResolver(RolePermissionResolver permissionRoleResolver)
Description copied from interface:RolePermissionResolverAware
Sets the specified RolePermissionResolver on this instance.- Specified by:
setRolePermissionResolver
in interfaceRolePermissionResolverAware
- Parameters:
permissionRoleResolver
- the RolePermissionResolver being set.
-
onInit
protected void onInit()
Initializes this realm and potentially enables a cache, depending on configuration. When this method is called, the following logic is executed:- If the
cache
property has been set, it will be used to cache the AuthorizationInfo objects returned fromgetAuthorizationInfo(org.apache.shiro.subject.PrincipalCollection)
method invocations. All future calls togetAuthorizationInfo
will attempt to use this cache first to alleviate any potentially unnecessary calls to an underlying data store. - If the
cache
property has not been set, thecacheManager
property will be checked. If acacheManager
has been set, it will be used to create an authorizationcache
, and this newly created cache which will be used as specified in #1. - If neither the
(org.apache.shiro.cache.Cache) cache
orcacheManager
properties are set, caching will be disabled and authorization look-ups will be delegated to subclass implementations for each authorization check.
- Overrides:
onInit
in classAuthenticatingRealm
- If the
-
afterCacheManagerSet
protected void afterCacheManagerSet()
Description copied from class:AuthenticatingRealm
This implementation attempts to acquire an authentication cache if one is not already configured.- Overrides:
afterCacheManagerSet
in classAuthenticatingRealm
-
getAuthorizationInfo
protected AuthorizationInfo getAuthorizationInfo(PrincipalCollection principals)
Returns an account's authorization-specific information for the specifiedprincipals
, ornull
if no account could be found. The resultingAuthorizationInfo
object is used by the other method implementations in this class to automatically perform access control checks for the correspondingSubject
. This implementation obtains the actualAuthorizationInfo
object from the subclass's implementation ofdoGetAuthorizationInfo
, and then caches it for efficient reuse if caching is enabled (see below). Invocations of this method should be thought of as completely orthogonal to acquiringauthenticationInfo
, since either could occur in any order. For example, in "Remember Me" scenarios, the user identity is remembered (and assumed) for their current session and an authentication attempt during that session might never occur. But because their identity would be remembered, that is sufficient enough information to call this method to execute any necessary authorization checks. For this reason, authentication and authorization should be loosely coupled and not depend on each other.Caching
TheAuthorizationInfo
values returned from this method are cached for efficient reuse if caching is enabled. Caching is enabled automatically when anauthorizationCache
instance has been explicitly configured, or if acacheManager
has been configured, which will be used to lazily create theauthorizationCache
as needed. If caching is enabled, the authorization cache will be checked first and if found, will return the cachedAuthorizationInfo
immediately. If caching is disabled, or there is a cache miss, the authorization info will be looked up from the underlying data store via thedoGetAuthorizationInfo(org.apache.shiro.subject.PrincipalCollection)
method, which must be implemented by subclasses.Changed Data
If caching is enabled and if any authorization data for an account is changed at runtime, such as adding or removing roles and/or permissions, the subclass implementation should clear the cached AuthorizationInfo for that account via theclearCachedAuthorizationInfo
method. This ensures that the next call togetAuthorizationInfo(PrincipalCollection)
will acquire the account's fresh authorization data, where it will then be cached for efficient reuse. This ensures that stale authorization data will not be reused.- Parameters:
principals
- the corresponding Subject's identifying principals with which to look up the Subject'sAuthorizationInfo
.- Returns:
- the authorization information for the account associated with the specified
principals
, ornull
if no account could be found.
-
getAuthorizationCacheKey
protected Object getAuthorizationCacheKey(PrincipalCollection principals)
-
clearCachedAuthorizationInfo
protected void clearCachedAuthorizationInfo(PrincipalCollection principals)
Clears out the AuthorizationInfo cache entry for the specified account. This method is provided as a convenience to subclasses so they can invalidate a cache entry when they change an account's authorization data (add/remove roles or permissions) during runtime. Because an account's AuthorizationInfo can be cached, there needs to be a way to invalidate the cache for only that account so that subsequent authorization operations don't used the (old) cached value if account data changes. After this method is called, the next authorization check for that same account will result in a call togetAuthorizationInfo
, and the resulting return value will be cached before being returned so it can be reused for later authorization checks. If you wish to clear out all associated cached data (and not just authorization data), use theCachingRealm.clearCache(org.apache.shiro.subject.PrincipalCollection)
method instead (which will in turn call this method by default).- Parameters:
principals
- the principals of the account for which to clear the cached AuthorizationInfo.
-
doGetAuthorizationInfo
protected abstract AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals)
Retrieves the AuthorizationInfo for the given principals from the underlying data store. When returning an instance from this method, you might want to consider using an instance ofSimpleAuthorizationInfo
, as it is suitable in most cases.- Parameters:
principals
- the primary identifying principals of the AuthorizationInfo that should be retrieved.- Returns:
- the AuthorizationInfo associated with this principals.
- See Also:
SimpleAuthorizationInfo
-
getPermissions
protected Collection<Permission> getPermissions(AuthorizationInfo info)
-
isPermitted
public boolean isPermitted(PrincipalCollection principals, String permission)
Description copied from interface:Authorizer
Returns true if the corresponding subject/user is permitted to perform an action or access a resource summarized by the specified permission string.This is an overloaded method for the corresponding type-safe
Permission
variant. Please see the class-level JavaDoc for more information on these String-based permission methods.- Specified by:
isPermitted
in interfaceAuthorizer
- Parameters:
principals
- the application-specific subject/user identifier.permission
- the String representation of a Permission that is being checked.- Returns:
- true if the corresponding Subject/user is permitted, false otherwise.
- See Also:
Authorizer.isPermitted(PrincipalCollection principals,Permission permission)
-
isPermitted
public boolean isPermitted(PrincipalCollection principals, Permission permission)
Description copied from interface:Authorizer
Returns true if the corresponding subject/user is permitted to perform an action or access a resource summarized by the specified permission.More specifically, this method determines if any Permissions associated with the subject
imply
the specified permission.- Specified by:
isPermitted
in interfaceAuthorizer
- Parameters:
principals
- the application-specific subject/user identifier.permission
- the permission that is being checked.- Returns:
- true if the corresponding Subject/user is permitted, false otherwise.
-
isPermitted
protected boolean isPermitted(Permission permission, AuthorizationInfo info)
-
isPermitted
public boolean[] isPermitted(PrincipalCollection subjectIdentifier, String... permissions)
Description copied from interface:Authorizer
Checks if the corresponding Subject implies the given permission strings and returns a boolean array indicating which permissions are implied.This is an overloaded method for the corresponding type-safe
Permission
variant. Please see the class-level JavaDoc for more information on these String-based permission methods.- Specified by:
isPermitted
in interfaceAuthorizer
- Parameters:
subjectIdentifier
- the application-specific subject/user identifier.permissions
- the String representations of the Permissions that are being checked.- Returns:
- an array of booleans whose indices correspond to the index of the permissions in the given list. A true value at an index indicates the user is permitted for for the associated Permission string in the list. A false value at an index indicates otherwise.
-
isPermitted
public boolean[] isPermitted(PrincipalCollection principals, List<Permission> permissions)
Description copied from interface:Authorizer
Checks if the corresponding Subject/user implies the given Permissions and returns a boolean array indicating which permissions are implied.More specifically, this method should determine if each Permission in the array is
implied
by permissions already associated with the subject.This is primarily a performance-enhancing method to help reduce the number of
Authorizer.isPermitted(org.apache.shiro.subject.PrincipalCollection, java.lang.String)
invocations over the wire in client/server systems.- Specified by:
isPermitted
in interfaceAuthorizer
- Parameters:
principals
- the application-specific subject/user identifier.permissions
- the permissions that are being checked.- Returns:
- an array of booleans whose indices correspond to the index of the permissions in the given list. A true value at an index indicates the user is permitted for for the associated Permission object in the list. A false value at an index indicates otherwise.
-
isPermitted
protected boolean[] isPermitted(List<Permission> permissions, AuthorizationInfo info)
-
isPermittedAll
public boolean isPermittedAll(PrincipalCollection subjectIdentifier, String... permissions)
Description copied from interface:Authorizer
Returns true if the corresponding Subject/user implies all of the specified permission strings, false otherwise.This is an overloaded method for the corresponding type-safe
Permission
variant. Please see the class-level JavaDoc for more information on these String-based permission methods.- Specified by:
isPermittedAll
in interfaceAuthorizer
- Parameters:
subjectIdentifier
- the application-specific subject/user identifier.permissions
- the String representations of the Permissions that are being checked.- Returns:
- true if the user has all of the specified permissions, false otherwise.
- See Also:
Authorizer.isPermittedAll(PrincipalCollection,Collection)
-
isPermittedAll
public boolean isPermittedAll(PrincipalCollection principal, Collection<Permission> permissions)
Description copied from interface:Authorizer
Returns true if the corresponding Subject/user implies all of the specified permissions, false otherwise.More specifically, this method determines if all of the given Permissions are
implied by
permissions already associated with the subject.- Specified by:
isPermittedAll
in interfaceAuthorizer
- Parameters:
principal
- the application-specific subject/user identifier.permissions
- the permissions to check.- Returns:
- true if the user has all of the specified permissions, false otherwise.
-
isPermittedAll
protected boolean isPermittedAll(Collection<Permission> permissions, AuthorizationInfo info)
-
checkPermission
public void checkPermission(PrincipalCollection subjectIdentifier, String permission) throws AuthorizationException
Description copied from interface:Authorizer
Ensures the corresponding Subject/user implies the specified permission String.If the subject's existing associated permissions do not
Permission.implies(Permission)
imply} the given permission, anAuthorizationException
will be thrown.This is an overloaded method for the corresponding type-safe
Permission
variant. Please see the class-level JavaDoc for more information on these String-based permission methods.- Specified by:
checkPermission
in interfaceAuthorizer
- Parameters:
subjectIdentifier
- the application-specific subject/user identifier.permission
- the String representation of the Permission to check.- Throws:
AuthorizationException
- if the user does not have the permission.
-
checkPermission
public void checkPermission(PrincipalCollection principal, Permission permission) throws AuthorizationException
Description copied from interface:Authorizer
Ensures a subject/userPermission.implies(Permission)
implies} the specified Permission. If the subject's existing associated permissions do notPermission.implies(Permission)
imply} the given permission, anAuthorizationException
will be thrown.- Specified by:
checkPermission
in interfaceAuthorizer
- Parameters:
principal
- the application-specific subject/user identifier.permission
- the Permission to check.- Throws:
AuthorizationException
- if the user does not have the permission.
-
checkPermission
protected void checkPermission(Permission permission, AuthorizationInfo info)
-
checkPermissions
public void checkPermissions(PrincipalCollection subjectIdentifier, String... permissions) throws AuthorizationException
Description copied from interface:Authorizer
Ensures the corresponding Subject/userimplies
all of the specified permission strings. If the subject's existing associated permissions do notimply
all of the given permissions, anAuthorizationException
will be thrown.This is an overloaded method for the corresponding type-safe
Permission
variant. Please see the class-level JavaDoc for more information on these String-based permission methods.- Specified by:
checkPermissions
in interfaceAuthorizer
- Parameters:
subjectIdentifier
- the application-specific subject/user identifier.permissions
- the string representations of Permissions to check.- Throws:
AuthorizationException
- if the user does not have all of the given permissions.
-
checkPermissions
public void checkPermissions(PrincipalCollection principal, Collection<Permission> permissions) throws AuthorizationException
Description copied from interface:Authorizer
Ensures the corresponding Subject/userimplies
all of the specified permission strings. If the subject's existing associated permissions do notimply
all of the given permissions, anAuthorizationException
will be thrown.- Specified by:
checkPermissions
in interfaceAuthorizer
- Parameters:
principal
- the application-specific subject/user identifier.permissions
- the Permissions to check.- Throws:
AuthorizationException
- if the user does not have all of the given permissions.
-
checkPermissions
protected void checkPermissions(Collection<Permission> permissions, AuthorizationInfo info)
-
hasRole
public boolean hasRole(PrincipalCollection principal, String roleIdentifier)
Description copied from interface:Authorizer
Returns true if the corresponding Subject/user has the specified role, false otherwise.- Specified by:
hasRole
in interfaceAuthorizer
- Parameters:
principal
- the application-specific subject/user identifier.roleIdentifier
- the application-specific role identifier (usually a role id or role name).- Returns:
- true if the corresponding subject has the specified role, false otherwise.
-
hasRole
protected boolean hasRole(String roleIdentifier, AuthorizationInfo info)
-
hasRoles
public boolean[] hasRoles(PrincipalCollection principal, List<String> roleIdentifiers)
Description copied from interface:Authorizer
Checks if the corresponding Subject/user has the specified roles, returning a boolean array indicating which roles are associated with the given subject.This is primarily a performance-enhancing method to help reduce the number of
Authorizer.hasRole(org.apache.shiro.subject.PrincipalCollection, java.lang.String)
invocations over the wire in client/server systems.- Specified by:
hasRoles
in interfaceAuthorizer
- Parameters:
principal
- the application-specific subject/user identifier.roleIdentifiers
- the application-specific role identifiers to check (usually role ids or role names).- Returns:
- an array of booleans whose indices correspond to the index of the roles in the given identifiers. A true value indicates the user has the role at that index. False indicates the user does not have the role at that index.
-
hasRoles
protected boolean[] hasRoles(List<String> roleIdentifiers, AuthorizationInfo info)
-
hasAllRoles
public boolean hasAllRoles(PrincipalCollection principal, Collection<String> roleIdentifiers)
Description copied from interface:Authorizer
Returns true if the corresponding Subject/user has all of the specified roles, false otherwise.- Specified by:
hasAllRoles
in interfaceAuthorizer
- Parameters:
principal
- the application-specific subject/user identifier.roleIdentifiers
- the application-specific role identifiers to check (usually role ids or role names).- Returns:
- true if the user has all the roles, false otherwise.
-
checkRole
public void checkRole(PrincipalCollection principal, String role) throws AuthorizationException
Description copied from interface:Authorizer
Asserts the corresponding Subject/user has the specified role by returning quietly if they do or throwing anAuthorizationException
if they do not.- Specified by:
checkRole
in interfaceAuthorizer
- Parameters:
principal
- the application-specific subject/user identifier.role
- the application-specific role identifier (usually a role id or role name ).- Throws:
AuthorizationException
- if the user does not have the role.
-
checkRole
protected void checkRole(String role, AuthorizationInfo info)
-
checkRoles
public void checkRoles(PrincipalCollection principal, Collection<String> roles) throws AuthorizationException
Description copied from interface:Authorizer
Asserts the corresponding Subject/user has all of the specified roles by returning quietly if they do or throwing anAuthorizationException
if they do not.- Specified by:
checkRoles
in interfaceAuthorizer
- Parameters:
principal
- the application-specific subject/user identifier.roles
- the application-specific role identifiers to check (usually role ids or role names).- Throws:
AuthorizationException
- if the user does not have all of the specified roles.
-
checkRoles
public void checkRoles(PrincipalCollection principal, String... roles) throws AuthorizationException
Description copied from interface:Authorizer
Same ascheckRoles(PrincipalCollection subjectPrincipal, Collection<String> roleIdentifiers)
but doesn't require a collection as an argument. Asserts the corresponding Subject/user has all of the specified roles by returning quietly if they do or throwing anAuthorizationException
if they do not.- Specified by:
checkRoles
in interfaceAuthorizer
- Parameters:
principal
- the application-specific subject/user identifier.roles
- the application-specific role identifiers to check (usually role ids or role names).- Throws:
AuthorizationException
- if the user does not have all of the specified roles.
-
checkRoles
protected void checkRoles(Collection<String> roles, AuthorizationInfo info)
-
doClearCache
protected void doClearCache(PrincipalCollection principals)
Callssuper.doClearCache
to ensure any cached authentication data is removed and then callsclearCachedAuthorizationInfo(org.apache.shiro.subject.PrincipalCollection)
to remove any cached authorization data. If overriding in a subclass, be sure to callsuper.doClearCache
to ensure this behavior is maintained.- Overrides:
doClearCache
in classAuthenticatingRealm
- Parameters:
principals
- the principals of the account for which to clear any cached AuthorizationInfo- Since:
- 1.2
-
-