Class AuthzRealm
- All Implemented Interfaces:
org.apache.shiro.authc.LogoutAware,org.apache.shiro.authz.Authorizer,org.apache.shiro.authz.permission.PermissionResolverAware,org.apache.shiro.authz.permission.RolePermissionResolverAware,org.apache.shiro.cache.CacheManagerAware,org.apache.shiro.realm.Realm,org.apache.shiro.util.Initializable,org.apache.shiro.util.Nameable
AbstractAuthorizingRealm provides the ability
to check permissions without making calls out to an external PDP. Permission objects are
checked against each other to ensure that the subject permissions imply the resource permissions.- Author:
- tustisos
-
Field Summary
Fields inherited from class ddf.security.service.impl.AbstractAuthorizingRealm
metacardExpansionServices, userExpansionServices -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddPolicyExtension(ddf.security.policy.extension.PolicyExtension policyExtension) protected org.apache.shiro.authc.AuthenticationInfodoGetAuthenticationInfo(org.apache.shiro.authc.AuthenticationToken token) org.apache.shiro.authz.AuthorizationInfogetAuthorizationInfo(org.apache.shiro.subject.PrincipalCollection principals) Returns an account's authorization-specific information for the specifiedprincipals, ornullif no account could be found.protected Collection<org.apache.shiro.authz.Permission>getPermissions(org.apache.shiro.authz.AuthorizationInfo authorizationInfo) Returns a collection ofPermissionobjects that theAuthorizationInfoobject of aSubjectis asserting.boolean[]isPermitted(org.apache.shiro.subject.PrincipalCollection subjectPrincipal, List<org.apache.shiro.authz.Permission> permissions) Checks if the corresponding Subject/user implies the given Permissions and returns a boolean array indicating which permissions are implied.booleanisPermitted(org.apache.shiro.subject.PrincipalCollection subjectPrincipal, org.apache.shiro.authz.Permission permission) Returns true if the corresponding subject/user is permitted to perform an action or access a resource summarized by the specified permission.voidremovePolicyExtension(ddf.security.policy.extension.PolicyExtension policyExtension) voidsetEnvironmentAttributes(List<String> environmentAttributes) voidsetMatchAllMappings(List<String> list) Sets the mappings used by the "match all" evaluation to determine if this user should be authorized to access requested data.voidsetMatchOneMappings(List<String> list) Sets the mappings used by the "match one" evaluation to determine if this user should be authorized to access requested data.voidsetPolicyExtensions(List<ddf.security.policy.extension.PolicyExtension> policyExtensions) Sets list of policy extension objectsvoidsetSecurityLogger(ddf.security.audit.SecurityLogger securityLogger) Methods inherited from class ddf.security.service.impl.AbstractAuthorizingRealm
addMetacardExpansion, addMetacardExpansion, addUserExpansion, addUserExpansion, doGetAuthorizationInfo, expandPermissions, removeMetacardExpansion, removeUserExpansionMethods inherited from class org.apache.shiro.realm.AuthorizingRealm
afterCacheManagerSet, checkPermission, checkPermission, checkPermission, checkPermissions, checkPermissions, checkPermissions, checkRole, checkRole, checkRoles, checkRoles, checkRoles, clearCachedAuthorizationInfo, doClearCache, getAuthorizationCache, getAuthorizationCacheKey, getAuthorizationCacheName, getPermissionResolver, getRolePermissionResolver, hasAllRoles, hasRole, hasRole, hasRoles, hasRoles, isAuthorizationCachingEnabled, isPermitted, isPermitted, isPermitted, isPermitted, isPermittedAll, isPermittedAll, isPermittedAll, onInit, setAuthorizationCache, setAuthorizationCacheName, setAuthorizationCachingEnabled, setName, setPermissionResolver, setRolePermissionResolverMethods inherited from class org.apache.shiro.realm.AuthenticatingRealm
assertCredentialsMatch, clearCachedAuthenticationInfo, getAuthenticationCache, getAuthenticationCacheKey, getAuthenticationCacheKey, getAuthenticationCacheName, getAuthenticationInfo, getAuthenticationTokenClass, getCredentialsMatcher, init, isAuthenticationCachingEnabled, isAuthenticationCachingEnabled, setAuthenticationCache, setAuthenticationCacheName, setAuthenticationCachingEnabled, setAuthenticationTokenClass, setCredentialsMatcher, supportsMethods inherited from class org.apache.shiro.realm.CachingRealm
clearCache, getAvailablePrincipal, getCacheManager, getName, isCachingEnabled, onLogout, setCacheManager, setCachingEnabledMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.shiro.util.Initializable
init
-
Constructor Details
-
AuthzRealm
- Throws:
PdpException
-
-
Method Details
-
doGetAuthenticationInfo
protected org.apache.shiro.authc.AuthenticationInfo doGetAuthenticationInfo(org.apache.shiro.authc.AuthenticationToken token) throws org.apache.shiro.authc.AuthenticationException - Specified by:
doGetAuthenticationInfoin classorg.apache.shiro.realm.AuthenticatingRealm- Throws:
org.apache.shiro.authc.AuthenticationException
-
getAuthorizationInfo
public org.apache.shiro.authz.AuthorizationInfo getAuthorizationInfo(org.apache.shiro.subject.PrincipalCollection principals) Returns an account's authorization-specific information for the specifiedprincipals, ornullif no account could be found. The resultingAuthorizationInfoobject is used by the other method implementations in this class to automatically perform access control checks for the correspondingSubject.This implementation obtains the actual
AuthorizationInfoobject 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 acquiring
authenticationInfo, 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
TheAuthorizationInfovalues returned from this method are cached for efficient reuse if caching is enabled. Caching is enabled automatically when anauthorizationCacheinstance has been explicitly configured, or if acacheManagerhas been configured, which will be used to lazily create theauthorizationCacheas needed.If caching is enabled, the authorization cache will be checked first and if found, will return the cached
AuthorizationInfoimmediately. If caching is disabled, or there is a cache miss, the authorization info will be looked up from the underlying data store via theAbstractAuthorizingRealm.doGetAuthorizationInfo(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 theclearCachedAuthorizationInfomethod. 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.- Overrides:
getAuthorizationInfoin classorg.apache.shiro.realm.AuthorizingRealm- 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, ornullif no account could be found.
-
isPermitted
public boolean isPermitted(org.apache.shiro.subject.PrincipalCollection subjectPrincipal, org.apache.shiro.authz.Permission permission) 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
implythe specified permission.- Specified by:
isPermittedin interfaceorg.apache.shiro.authz.Authorizer- Overrides:
isPermittedin classorg.apache.shiro.realm.AuthorizingRealm- Parameters:
subjectPrincipal- 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
public boolean[] isPermitted(org.apache.shiro.subject.PrincipalCollection subjectPrincipal, List<org.apache.shiro.authz.Permission> permissions) 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
impliedby permissions already associated with the subject.This is primarily a performance-enhancing method to help reduce the number of
isPermitted(org.apache.shiro.subject.PrincipalCollection, org.apache.shiro.authz.Permission)invocations over the wire in client/server systems.- Specified by:
isPermittedin interfaceorg.apache.shiro.authz.Authorizer- Overrides:
isPermittedin classorg.apache.shiro.realm.AuthorizingRealm- Parameters:
subjectPrincipal- 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.
-
getPermissions
protected Collection<org.apache.shiro.authz.Permission> getPermissions(org.apache.shiro.authz.AuthorizationInfo authorizationInfo) Returns a collection ofPermissionobjects that theAuthorizationInfoobject of aSubjectis asserting.- Overrides:
getPermissionsin classorg.apache.shiro.realm.AuthorizingRealm- Parameters:
authorizationInfo- the application-specific subject/user identifier.- Returns:
- collection of Permissions.
-
setPolicyExtensions
public void setPolicyExtensions(List<ddf.security.policy.extension.PolicyExtension> policyExtensions) Sets list of policy extension objects- Parameters:
policyExtensions-
-
addPolicyExtension
public void addPolicyExtension(ddf.security.policy.extension.PolicyExtension policyExtension) -
removePolicyExtension
public void removePolicyExtension(ddf.security.policy.extension.PolicyExtension policyExtension) -
setMatchAllMappings
Sets the mappings used by the "match all" evaluation to determine if this user should be authorized to access requested data.Each string is of the format:
subjectAttrName=metacardAttrName
wheremetacardAttrNameis the name of an attribute in the metacard andsubjectAttrNameis the name of the corresponding attribute in the user credentials.
It is the values corresponding to each of these attributes that will be evaluated against each other when determining if authorization should be allowed.- Parameters:
list- List of Strings that define mappings between metadata attributes and user attributes
-
setMatchOneMappings
Sets the mappings used by the "match one" evaluation to determine if this user should be authorized to access requested data.Each string is of the format:
subjectAttrName=metacardAttrName
wheremetacardAttrNameis the name of an attribute in the metacard andsubjectAttrNameis the name of the corresponding attribute in the user credentials.
It is the values corresponding to each of these attributes that will be evaluated against each other when determining if authorization should be allowed.- Parameters:
list- List of Strings that define mappings between metadata attributes and user attributes
-
setEnvironmentAttributes
-
setSecurityLogger
public void setSecurityLogger(ddf.security.audit.SecurityLogger securityLogger)
-