Package org.apache.shiro.authz.aop
Class AnnotationsAuthorizingMethodInterceptor
- java.lang.Object
-
- org.apache.shiro.aop.MethodInterceptorSupport
-
- org.apache.shiro.authz.aop.AuthorizingMethodInterceptor
-
- org.apache.shiro.authz.aop.AnnotationsAuthorizingMethodInterceptor
-
- All Implemented Interfaces:
MethodInterceptor
public abstract class AnnotationsAuthorizingMethodInterceptor extends AuthorizingMethodInterceptor
An AnnotationsAuthorizingMethodInterceptor is a MethodInterceptor that asserts a given method is authorized to execute based on one or more configured AuthorizingAnnotationMethodInterceptors.This allows multiple annotations on a method to be processed before the method executes, and if any of the AuthorizingAnnotationMethodInterceptors indicate that the method should not be executed, an AuthorizationException will be thrown, otherwise the method will be invoked as expected.
It is essentially a convenience mechanism to allow multiple annotations to be processed in a single method interceptor.
- Since:
- 0.2
-
-
Field Summary
Fields Modifier and Type Field Description protected Collection<AuthorizingAnnotationMethodInterceptor>methodInterceptorsThe method interceptors to execute for the annotated method.
-
Constructor Summary
Constructors Constructor Description AnnotationsAuthorizingMethodInterceptor()Default no-argument constructor that defaults themethodInterceptorsattribute to contain two interceptors by default - theRoleAnnotationMethodInterceptorand thePermissionAnnotationMethodInterceptorto support role and permission annotations.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidassertAuthorized(MethodInvocation methodInvocation)Iterates over the internalmethodInterceptorscollection, and for each one, ensures that if the interceptorsupportsthe invocation, that the interceptorassertsthat the invocation is authorized to proceed.Collection<AuthorizingAnnotationMethodInterceptor>getMethodInterceptors()Returns the method interceptors to execute for the annotated method.voidsetMethodInterceptors(Collection<AuthorizingAnnotationMethodInterceptor> methodInterceptors)Sets the method interceptors to execute for the annotated method.-
Methods inherited from class org.apache.shiro.authz.aop.AuthorizingMethodInterceptor
invoke
-
Methods inherited from class org.apache.shiro.aop.MethodInterceptorSupport
getSubject
-
-
-
-
Field Detail
-
methodInterceptors
protected Collection<AuthorizingAnnotationMethodInterceptor> methodInterceptors
The method interceptors to execute for the annotated method.
-
-
Constructor Detail
-
AnnotationsAuthorizingMethodInterceptor
public AnnotationsAuthorizingMethodInterceptor()
Default no-argument constructor that defaults themethodInterceptorsattribute to contain two interceptors by default - theRoleAnnotationMethodInterceptorand thePermissionAnnotationMethodInterceptorto support role and permission annotations.
-
-
Method Detail
-
getMethodInterceptors
public Collection<AuthorizingAnnotationMethodInterceptor> getMethodInterceptors()
Returns the method interceptors to execute for the annotated method. Unless overridden by thesetMethodInterceptors(java.util.Collection)method, the default collection contains aRoleAnnotationMethodInterceptorand aPermissionAnnotationMethodInterceptorto support role and permission annotations automatically.- Returns:
- the method interceptors to execute for the annotated method.
-
setMethodInterceptors
public void setMethodInterceptors(Collection<AuthorizingAnnotationMethodInterceptor> methodInterceptors)
Sets the method interceptors to execute for the annotated method.- Parameters:
methodInterceptors- the method interceptors to execute for the annotated method.- See Also:
getMethodInterceptors()
-
assertAuthorized
protected void assertAuthorized(MethodInvocation methodInvocation) throws AuthorizationException
Iterates over the internalmethodInterceptorscollection, and for each one, ensures that if the interceptorsupportsthe invocation, that the interceptorassertsthat the invocation is authorized to proceed.- Specified by:
assertAuthorizedin classAuthorizingMethodInterceptor- Parameters:
methodInvocation- theMethodInvocationto invoke.- Throws:
AuthorizationException- if themethodInvocationshould not be allowed to continue/execute.
-
-