Class AuthorizingSecurityManager
- All Implemented Interfaces:
Authenticator,Authorizer,org.apache.shiro.cache.CacheManagerAware,org.apache.shiro.event.EventBusAware,org.apache.shiro.lang.util.Destroyable,SecurityManager,SessionManager
- Direct Known Subclasses:
SessionsSecurityManager
SecurityManager class hierarchy that delegates all
authorization (access control) operations to a wrapped Authorizer instance. That is,
this class implements all the Authorizer methods in the SecurityManager
interface, but in reality, those methods are merely passthrough calls to the underlying 'real'
Authorizer instance.
All remaining SecurityManager methods not covered by this class or its parents (mostly Session support) are left to be implemented by subclasses.
In keeping with the other classes in this hierarchy and Shiro's desire to minimize configuration whenever possible, suitable default instances for all dependencies will be created upon instantiation.
- Since:
- 0.9
-
Constructor Summary
ConstructorsConstructorDescriptionDefault no-arg constructor that initializes an internal defaultModularRealmAuthorizer. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidFirst callssuper.afterRealmsSet()and then sets these sameRealmobjects on this instance's wrappedAuthorizer.voidcheckPermission(PrincipalCollection principals, String permission) Ensures the corresponding Subject/user implies the specified permission String.voidcheckPermission(PrincipalCollection principals, Permission permission) Ensures a subject/userPermission.implies(Permission)implies} the specified Permission.voidcheckPermissions(PrincipalCollection principals, String... permissions) Ensures the corresponding Subject/userimpliesall of the specified permission strings.voidcheckPermissions(PrincipalCollection principals, Collection<Permission> permissions) Ensures the corresponding Subject/userimpliesall of the specified permission strings.voidcheckRole(PrincipalCollection principals, String role) Asserts the corresponding Subject/user has the specified role by returning quietly if they do or throwing anAuthorizationExceptionif they do not.voidcheckRoles(PrincipalCollection principals, String... roles) Same ascheckRoles(PrincipalCollection subjectPrincipal, Collection<String> roleIdentifiers)but doesn't require a collection as an argument.voidcheckRoles(PrincipalCollection principals, Collection<String> roles) Asserts the corresponding Subject/user has all of the specified roles by returning quietly if they do or throwing anAuthorizationExceptionif they do not.voiddestroy()Destroys thecacheManagerviaLifecycleUtils.destroy.Returns the underlying wrapped Authorizer instance to which this SecurityManager implementation delegates all of its authorization calls.booleanhasAllRoles(PrincipalCollection principals, Collection<String> roleIdentifiers) Returns true if the corresponding Subject/user has all of the specified roles, false otherwise.booleanhasRole(PrincipalCollection principals, String roleIdentifier) Returns true if the corresponding Subject/user has the specified role, false otherwise.boolean[]hasRoles(PrincipalCollection principals, 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.booleanisPermitted(PrincipalCollection principals, String permissionString) 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 principals, 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.booleanisPermitted(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.booleanisPermittedAll(PrincipalCollection principals, String... permissions) Returns true if the corresponding Subject/user implies all of the specified permission strings, false otherwise.booleanisPermittedAll(PrincipalCollection principals, Collection<Permission> permissions) Returns true if the corresponding Subject/user implies all of the specified permissions, false otherwise.voidsetAuthorizer(Authorizer authorizer) Sets the underlying Authorizer instance to which this SecurityManager implementation will delegate all of its authorization calls.Methods inherited from class org.apache.shiro.mgt.AuthenticatingSecurityManager
authenticate, getAuthenticator, setAuthenticatorMethods inherited from class org.apache.shiro.mgt.RealmSecurityManager
afterCacheManagerSet, afterEventBusSet, applyCacheManagerToRealms, applyEventBusToRealms, getRealms, setRealm, setRealmsMethods inherited from class org.apache.shiro.mgt.CachingSecurityManager
applyEventBusToCacheManager, getCacheManager, getEventBus, setCacheManager, setEventBusMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.shiro.mgt.SecurityManager
createSubject, login, logoutMethods inherited from interface org.apache.shiro.session.mgt.SessionManager
getSession, start
-
Constructor Details
-
AuthorizingSecurityManager
public AuthorizingSecurityManager()Default no-arg constructor that initializes an internal defaultModularRealmAuthorizer.
-
-
Method Details
-
getAuthorizer
Returns the underlying wrapped Authorizer instance to which this SecurityManager implementation delegates all of its authorization calls.- Returns:
- the wrapped Authorizer used by this SecurityManager implementation.
-
setAuthorizer
Sets the underlying Authorizer instance to which this SecurityManager implementation will delegate all of its authorization calls.- Parameters:
authorizer- the Authorizer this SecurityManager should wrap and delegate all of its authorization calls to.
-
afterRealmsSet
First callssuper.afterRealmsSet()and then sets these sameRealmobjects on this instance's wrappedAuthorizer. The setting of realms the Authorizer will only occur if it is an instance ofModularRealmAuthorizer, that is:if ( this.authorizer instanceof ModularRealmAuthorizer ) { ((ModularRealmAuthorizer)this.authorizer).setRealms(realms); }- Overrides:
afterRealmsSetin classAuthenticatingSecurityManager
-
destroy
Description copied from class:CachingSecurityManagerDestroys thecacheManagerviaLifecycleUtils.destroy.- Specified by:
destroyin interfaceorg.apache.shiro.lang.util.Destroyable- Overrides:
destroyin classAuthenticatingSecurityManager
-
isPermitted
Description copied from interface:AuthorizerReturns 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
Permissionvariant. Please see the class-level JavaDoc for more information on these String-based permission methods.- Parameters:
principals- the application-specific subject/user identifier.permissionString- the String representation of a Permission that is being checked.- Returns:
- true if the corresponding Subject/user is permitted, false otherwise.
- See Also:
-
isPermitted
Description copied from interface:AuthorizerReturns 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.- 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
Description copied from interface:AuthorizerChecks 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
Permissionvariant. Please see the class-level JavaDoc for more information on these String-based permission methods.- Parameters:
principals- 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
Description copied from interface:AuthorizerChecks 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
Authorizer.isPermitted(org.apache.shiro.subject.PrincipalCollection, java.lang.String)invocations over the wire in client/server systems.- 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.
-
isPermittedAll
Description copied from interface:AuthorizerReturns 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
Permissionvariant. Please see the class-level JavaDoc for more information on these String-based permission methods.- Parameters:
principals- 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:
-
isPermittedAll
Description copied from interface:AuthorizerReturns 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 bypermissions already associated with the subject.- Parameters:
principals- the application-specific subject/user identifier.permissions- the permissions to check.- Returns:
- true if the user has all of the specified permissions, false otherwise.
-
checkPermission
public void checkPermission(PrincipalCollection principals, String permission) throws AuthorizationException Description copied from interface:AuthorizerEnsures 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, anAuthorizationExceptionwill be thrown.This is an overloaded method for the corresponding type-safe
Permissionvariant. Please see the class-level JavaDoc for more information on these String-based permission methods.- Parameters:
principals- 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 principals, Permission permission) throws AuthorizationException Description copied from interface:AuthorizerEnsures a subject/userPermission.implies(Permission)implies} the specified Permission. If the subject's existing associated permissions do notPermission.implies(Permission)imply} the given permission, anAuthorizationExceptionwill be thrown.- Parameters:
principals- the application-specific subject/user identifier.permission- the Permission to check.- Throws:
AuthorizationException- if the user does not have the permission.
-
checkPermissions
public void checkPermissions(PrincipalCollection principals, String... permissions) throws AuthorizationException Description copied from interface:AuthorizerEnsures the corresponding Subject/userimpliesall of the specified permission strings.If the subject's existing associated permissions do not
implyall of the given permissions, anAuthorizationExceptionwill be thrown.This is an overloaded method for the corresponding type-safe
Permissionvariant. Please see the class-level JavaDoc for more information on these String-based permission methods.- Parameters:
principals- 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 principals, Collection<Permission> permissions) throws AuthorizationException Description copied from interface:AuthorizerEnsures the corresponding Subject/userimpliesall of the specified permission strings.If the subject's existing associated permissions do not
implyall of the given permissions, anAuthorizationExceptionwill be thrown.- Parameters:
principals- the application-specific subject/user identifier.permissions- the Permissions to check.- Throws:
AuthorizationException- if the user does not have all of the given permissions.
-
hasRole
Description copied from interface:AuthorizerReturns true if the corresponding Subject/user has the specified role, false otherwise.- Parameters:
principals- 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.
-
hasRoles
Description copied from interface:AuthorizerChecks 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.- Parameters:
principals- 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.
-
hasAllRoles
Description copied from interface:AuthorizerReturns true if the corresponding Subject/user has all of the specified roles, false otherwise.- Parameters:
principals- 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
Description copied from interface:AuthorizerAsserts the corresponding Subject/user has the specified role by returning quietly if they do or throwing anAuthorizationExceptionif they do not.- Parameters:
principals- 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.
-
checkRoles
public void checkRoles(PrincipalCollection principals, Collection<String> roles) throws AuthorizationException Description copied from interface:AuthorizerAsserts the corresponding Subject/user has all of the specified roles by returning quietly if they do or throwing anAuthorizationExceptionif they do not.- Parameters:
principals- 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 principals, String... roles) throws AuthorizationException Description copied from interface:AuthorizerSame ascheckRoles(PrincipalCollection subjectPrincipal, Collection<String> roleIdentifiers)but doesn't require a collection as an argument. Asserts the corresponding Subject/user has all the specified roles by returning quietly if they do or throwing anAuthorizationExceptionif they do not.- Parameters:
principals- 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 the specified roles.
-