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>
methodInterceptors
The method interceptors to execute for the annotated method.
-
Constructor Summary
Constructors Constructor Description AnnotationsAuthorizingMethodInterceptor()
Default no-argument constructor that defaults themethodInterceptors
attribute to contain two interceptors by default - theRoleAnnotationMethodInterceptor
and thePermissionAnnotationMethodInterceptor
to support role and permission annotations.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
assertAuthorized(MethodInvocation methodInvocation)
Iterates over the internalmethodInterceptors
collection, and for each one, ensures that if the interceptorsupports
the invocation, that the interceptorasserts
that the invocation is authorized to proceed.Collection<AuthorizingAnnotationMethodInterceptor>
getMethodInterceptors()
Returns the method interceptors to execute for the annotated method.void
setMethodInterceptors(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 themethodInterceptors
attribute to contain two interceptors by default - theRoleAnnotationMethodInterceptor
and thePermissionAnnotationMethodInterceptor
to 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 aRoleAnnotationMethodInterceptor
and aPermissionAnnotationMethodInterceptor
to 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 internalmethodInterceptors
collection, and for each one, ensures that if the interceptorsupports
the invocation, that the interceptorasserts
that the invocation is authorized to proceed.- Specified by:
assertAuthorized
in classAuthorizingMethodInterceptor
- Parameters:
methodInvocation
- theMethodInvocation
to invoke.- Throws:
AuthorizationException
- if themethodInvocation
should not be allowed to continue/execute.
-
-