Class ModularRealmAuthorizer
java.lang.Object
org.apache.shiro.authz.ModularRealmAuthorizer
- All Implemented Interfaces:
Authorizer,PermissionResolverAware,RolePermissionResolverAware
public class ModularRealmAuthorizer
extends Object
implements Authorizer, PermissionResolverAware, RolePermissionResolverAware
A ModularRealmAuthorizer is an Authorizer implementation that consults one or more configured
Realms during an authorization operation.- Since:
- 0.2
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected PermissionResolverA PermissionResolver to be used by all configured realms.protected Collection<Realm> The realms to consult during any authorization check.protected RolePermissionResolverA RolePermissionResolver to be used by all configured realms. -
Constructor Summary
ConstructorsConstructorDescriptionDefault no-argument constructor, does nothing.ModularRealmAuthorizer(Collection<Realm> realms) Constructor that accepts theRealms to consult during an authorization check. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidSets the internalgetPermissionResolver()on any internal configuredRealmsthat implement thePermissionResolverAwareinterface.protected voidSets the internalgetRolePermissionResolver()on any internal configuredRealmsthat implement theRolePermissionResolverAwareinterface.protected voidUsed by theAuthorizerimplementation methods to ensure that therealmshas been set.voidcheckPermission(PrincipalCollection principals, String permission) If !isPermitted(permission), throws anUnauthorizedExceptionotherwise returns quietly.voidcheckPermission(PrincipalCollection principals, Permission permission) If !isPermitted(permission), throws anUnauthorizedExceptionotherwise returns quietly.voidcheckPermissions(PrincipalCollection principals, String... permissions) If !isPermitted(permission), throws anUnauthorizedExceptionotherwise returns quietly.voidcheckPermissions(PrincipalCollection principals, Collection<Permission> permissions) If !isPermitted(permission)for all the given Permissions, throws anUnauthorizedExceptionotherwise returns quietly.voidcheckRole(PrincipalCollection principals, String role) If !hasRole(role), throws anUnauthorizedExceptionotherwise returns quietly.voidcheckRoles(PrincipalCollection principals, String... roles) CallscheckRolefor each role specified.voidcheckRoles(PrincipalCollection principals, Collection<String> roles) Returns the PermissionResolver to be used on all configured realms, ornullinvalid input: '<'/code (the default) if all realm instances will each configure their own permission resolver.Returns the realms wrapped by thisAuthorizerwhich are consulted during an authorization check.Returns the RolePermissionResolver to be used on all configured realms, ornullinvalid input: '<'/code (the default) if all realm instances will each configure their own permission resolver.booleanhasAllRoles(PrincipalCollection principals, Collection<String> roleIdentifiers) Returnstrueiff any of the configured realms'hasRole(org.apache.shiro.subject.PrincipalCollection, String)call returnstruefor all roles specified,falseotherwise.booleanhasRole(PrincipalCollection principals, String roleIdentifier) Returnstrueif any of the configured realms'hasRole(org.apache.shiro.subject.PrincipalCollection, String)call returnstrue,falseotherwise.boolean[]hasRoles(PrincipalCollection principals, List<String> roleIdentifiers) CallshasRole(org.apache.shiro.subject.PrincipalCollection, String)for each role name in the specified collection and places the return value from each call at the respective location in the returned array.booleanisPermitted(PrincipalCollection principals, String permission) Returnstrueif any of the configured realms'isPermitted(org.apache.shiro.subject.PrincipalCollection, String)returnstrue,falseotherwise.boolean[]isPermitted(PrincipalCollection principals, String... permissions) Returnstrueif any of the configured realms'isPermittedAll(org.apache.shiro.subject.PrincipalCollection, String...)call returnstrue,falseotherwise.boolean[]isPermitted(PrincipalCollection principals, List<Permission> permissions) Returnstrueif any of the configured realms'isPermitted(org.apache.shiro.subject.PrincipalCollection, List)call returnstrue,falseotherwise.booleanisPermitted(PrincipalCollection principals, Permission permission) Returnstrueif any of the configured realms'isPermitted(org.apache.shiro.subject.PrincipalCollection, Permission)call returnstrue,falseotherwise.booleanisPermittedAll(PrincipalCollection principals, String... permissions) Returnstrueif any of the configured realms'isPermitted(org.apache.shiro.subject.PrincipalCollection, String)call returnstruefor all of the specified string permissions,falseotherwise.booleanisPermittedAll(PrincipalCollection principals, Collection<Permission> permissions) Returnstrueif any of the configured realms'isPermitted(org.apache.shiro.subject.PrincipalCollection, Permission)call returnstruefor all of the specified Permissions,falseotherwise.voidsetPermissionResolver(PermissionResolver permissionResolver) Sets the specifiedPermissionResolveron all of the wrapped realms that implement thePermissionResolverAwareinterface.voidsetRealms(Collection<Realm> realms) Sets the realms wrapped by thisAuthorizerwhich are consulted during an authorization check.voidsetRolePermissionResolver(RolePermissionResolver rolePermissionResolver) Sets the specifiedRolePermissionResolveron all of the wrapped realms that implement thePermissionResolverAwareinterface.
-
Field Details
-
realms
The realms to consult during any authorization check. -
permissionResolver
A PermissionResolver to be used by all configured realms. Leavenullif you wish to configure different resolvers for different realms. -
rolePermissionResolver
A RolePermissionResolver to be used by all configured realms. Leavenullif you wish to configure different resolvers for different realms.
-
-
Constructor Details
-
ModularRealmAuthorizer
public ModularRealmAuthorizer()Default no-argument constructor, does nothing. -
ModularRealmAuthorizer
Constructor that accepts theRealms to consult during an authorization check. Immediately callssetRealms(realms).- Parameters:
realms- the realms to consult during an authorization check.
-
-
Method Details
-
getRealms
Returns the realms wrapped by thisAuthorizerwhich are consulted during an authorization check.- Returns:
- the realms wrapped by this
Authorizerwhich are consulted during an authorization check.
-
setRealms
Sets the realms wrapped by thisAuthorizerwhich are consulted during an authorization check.- Parameters:
realms- the realms wrapped by thisAuthorizerwhich are consulted during an authorization check.
-
getPermissionResolver
Returns the PermissionResolver to be used on all configured realms, ornullinvalid input: '<'/code (the default) if all realm instances will each configure their own permission resolver.- Returns:
- the PermissionResolver to be used on all configured realms, or
nullinvalid input: '<'/code (the default) if realm instances will each configure their own permission resolver. - Since:
- 1.0
-
setPermissionResolver
Sets the specifiedPermissionResolveron all of the wrapped realms that implement thePermissionResolverAwareinterface. Only call this method if you want the permission resolver to be passed to all realms that implement thePermissionResolverinterface. If you do not want this to occur, the realms must configure themselves individually (or be configured individually).- Specified by:
setPermissionResolverin interfacePermissionResolverAware- Parameters:
permissionResolver- the permissionResolver to set on all the wrapped realms that implement thePermissionResolverAwareinterface.
-
applyPermissionResolverToRealms
Sets the internalgetPermissionResolver()on any internal configuredRealmsthat implement thePermissionResolverAwareinterface. This method is called after setting a permissionResolver on this ModularRealmAuthorizer via thesetPermissionResolvermethod. It is also called after setting one or more realms via thesetRealmsmethod to allow these newly available realms to be given thePermissionResolveralready in use.- Since:
- 1.0
-
getRolePermissionResolver
Returns the RolePermissionResolver to be used on all configured realms, ornullinvalid input: '<'/code (the default) if all realm instances will each configure their own permission resolver.- Returns:
- the RolePermissionResolver to be used on all configured realms, or
nullinvalid input: '<'/code (the default) if realm instances will each configure their own role permission resolver. - Since:
- 1.0
-
setRolePermissionResolver
Sets the specifiedRolePermissionResolveron all of the wrapped realms that implement thePermissionResolverAwareinterface. Only call this method if you want the permission resolver to be passed to all realms that implement theRolePermissionResolverinterface. If you do not want this to occur, the realms must configure themselves individually (or be configured individually).- Specified by:
setRolePermissionResolverin interfaceRolePermissionResolverAware- Parameters:
rolePermissionResolver- the rolePermissionResolver to set on all the wrapped realms that implement theRolePermissionResolverAwareinterface.
-
applyRolePermissionResolverToRealms
Sets the internalgetRolePermissionResolver()on any internal configuredRealmsthat implement theRolePermissionResolverAwareinterface. This method is called after setting a rolePermissionResolver on this ModularRealmAuthorizer via thesetRolePermissionResolvermethod. It is also called after setting one or more realms via thesetRealmsmethod to allow these newly available realms to be given theRolePermissionResolveralready in use.- Since:
- 1.0
-
assertRealmsConfigured
Used by theAuthorizerimplementation methods to ensure that therealmshas been set. The default implementation ensures the property is not null and not empty.- Throws:
IllegalStateException- if the realms property is configured incorrectly.
-
isPermitted
Returnstrueif any of the configured realms'isPermitted(org.apache.shiro.subject.PrincipalCollection, String)returnstrue,falseotherwise.- Specified by:
isPermittedin 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:
-
isPermitted
Returnstrueif any of the configured realms'isPermitted(org.apache.shiro.subject.PrincipalCollection, Permission)call returnstrue,falseotherwise.- Specified by:
isPermittedin 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
Returnstrueif any of the configured realms'isPermittedAll(org.apache.shiro.subject.PrincipalCollection, String...)call returnstrue,falseotherwise.- Specified by:
isPermittedin interfaceAuthorizer- 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
Returnstrueif any of the configured realms'isPermitted(org.apache.shiro.subject.PrincipalCollection, List)call returnstrue,falseotherwise.- Specified by:
isPermittedin 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.
-
isPermittedAll
Returnstrueif any of the configured realms'isPermitted(org.apache.shiro.subject.PrincipalCollection, String)call returnstruefor all of the specified string permissions,falseotherwise.- Specified by:
isPermittedAllin interfaceAuthorizer- 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
Returnstrueif any of the configured realms'isPermitted(org.apache.shiro.subject.PrincipalCollection, Permission)call returnstruefor all of the specified Permissions,falseotherwise.- Specified by:
isPermittedAllin interfaceAuthorizer- 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 If !isPermitted(permission), throws anUnauthorizedExceptionotherwise returns quietly.- Specified by:
checkPermissionin interfaceAuthorizer- 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 If !isPermitted(permission), throws anUnauthorizedExceptionotherwise returns quietly.- Specified by:
checkPermissionin interfaceAuthorizer- 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 If !isPermitted(permission), throws anUnauthorizedExceptionotherwise returns quietly.- Specified by:
checkPermissionsin interfaceAuthorizer- 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 If !isPermitted(permission)for all the given Permissions, throws anUnauthorizedExceptionotherwise returns quietly.- Specified by:
checkPermissionsin interfaceAuthorizer- 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
Returnstrueif any of the configured realms'hasRole(org.apache.shiro.subject.PrincipalCollection, String)call returnstrue,falseotherwise.- Specified by:
hasRolein interfaceAuthorizer- 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
CallshasRole(org.apache.shiro.subject.PrincipalCollection, String)for each role name in the specified collection and places the return value from each call at the respective location in the returned array.- Specified by:
hasRolesin interfaceAuthorizer- 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
Returnstrueiff any of the configured realms'hasRole(org.apache.shiro.subject.PrincipalCollection, String)call returnstruefor all roles specified,falseotherwise.- Specified by:
hasAllRolesin interfaceAuthorizer- 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
If !hasRole(role), throws anUnauthorizedExceptionotherwise returns quietly.- Specified by:
checkRolein interfaceAuthorizer- 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 - Specified by:
checkRolesin interfaceAuthorizer- 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 CallscheckRolefor each role specified.- Specified by:
checkRolesin interfaceAuthorizer- 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.
-