Package org.apache.shiro.aop
Class AnnotationMethodInterceptor
- java.lang.Object
-
- org.apache.shiro.aop.MethodInterceptorSupport
-
- org.apache.shiro.aop.AnnotationMethodInterceptor
-
- All Implemented Interfaces:
MethodInterceptor
- Direct Known Subclasses:
AuthorizingAnnotationMethodInterceptor
public abstract class AnnotationMethodInterceptor extends MethodInterceptorSupport
MethodInterceptor that inspects a specific annotation on the method invocation before continuing its execution. The annotation is acquired from theMethodInvocation
via aAnnotationResolver
instance that may be configured. Unless overridden, the defaultAnnotationResolver
is a- Since:
- 0.9
-
-
Constructor Summary
Constructors Constructor Description AnnotationMethodInterceptor(AnnotationHandler handler)
Constructs anAnnotationMethodInterceptor
with theAnnotationHandler
that will be used to process annotations of a corresponding type.AnnotationMethodInterceptor(AnnotationHandler handler, AnnotationResolver resolver)
Constructs anAnnotationMethodInterceptor
with theAnnotationHandler
that will be used to process annotations of a corresponding type, using the specifiedAnnotationResolver
to acquire annotations at runtime.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Annotation
getAnnotation(MethodInvocation mi)
Returns the Annotation that this interceptor will process for the specified method invocation.AnnotationHandler
getHandler()
Returns theAnnotationHandler
used to perform authorization behavior based on an annotation discovered at runtime.AnnotationResolver
getResolver()
Returns theAnnotationResolver
to use to acquire annotations from intercepted methods at runtime.void
setHandler(AnnotationHandler handler)
Sets theAnnotationHandler
used to perform authorization behavior based on an annotation discovered at runtime.void
setResolver(AnnotationResolver resolver)
Returns theAnnotationResolver
to use to acquire annotations from intercepted methods at runtime.boolean
supports(MethodInvocation mi)
Returnstrue
if this interceptor supports, that is, should inspect, the specifiedMethodInvocation
,false
otherwise.-
Methods inherited from class org.apache.shiro.aop.MethodInterceptorSupport
getSubject
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.shiro.aop.MethodInterceptor
invoke
-
-
-
-
Constructor Detail
-
AnnotationMethodInterceptor
public AnnotationMethodInterceptor(AnnotationHandler handler)
Constructs anAnnotationMethodInterceptor
with theAnnotationHandler
that will be used to process annotations of a corresponding type.- Parameters:
handler
- the handler to delegate to for processing the annotation.
-
AnnotationMethodInterceptor
public AnnotationMethodInterceptor(AnnotationHandler handler, AnnotationResolver resolver)
Constructs anAnnotationMethodInterceptor
with theAnnotationHandler
that will be used to process annotations of a corresponding type, using the specifiedAnnotationResolver
to acquire annotations at runtime.- Parameters:
handler
- the handler to use to process any discovered annotationresolver
- the resolver to use to locate/acquire the annotation- Since:
- 1.1
-
-
Method Detail
-
getHandler
public AnnotationHandler getHandler()
Returns theAnnotationHandler
used to perform authorization behavior based on an annotation discovered at runtime.- Returns:
- the
AnnotationHandler
used to perform authorization behavior based on an annotation discovered at runtime.
-
setHandler
public void setHandler(AnnotationHandler handler)
Sets theAnnotationHandler
used to perform authorization behavior based on an annotation discovered at runtime.- Parameters:
handler
- theAnnotationHandler
used to perform authorization behavior based on an annotation discovered at runtime.
-
getResolver
public AnnotationResolver getResolver()
Returns theAnnotationResolver
to use to acquire annotations from intercepted methods at runtime. The annotation is then used by thehandler
to perform authorization logic.- Returns:
- the
AnnotationResolver
to use to acquire annotations from intercepted methods at runtime. - Since:
- 1.1
-
setResolver
public void setResolver(AnnotationResolver resolver)
Returns theAnnotationResolver
to use to acquire annotations from intercepted methods at runtime. The annotation is then used by thehandler
to perform authorization logic.- Parameters:
resolver
- theAnnotationResolver
to use to acquire annotations from intercepted methods at runtime.- Since:
- 1.1
-
supports
public boolean supports(MethodInvocation mi)
Returnstrue
if this interceptor supports, that is, should inspect, the specifiedMethodInvocation
,false
otherwise. The default implementation simply does the following:return
getAnnotation(mi)
!= null- Parameters:
mi
- theMethodInvocation
for the method being invoked.- Returns:
true
if this interceptor supports, that is, should inspect, the specifiedMethodInvocation
,false
otherwise.
-
getAnnotation
protected Annotation getAnnotation(MethodInvocation mi)
Returns the Annotation that this interceptor will process for the specified method invocation. The default implementation acquires the annotation using an annotationresolver
using the internal annotationhandler
'sannotationClass
.- Parameters:
mi
- the MethodInvocation wrapping the Method from which the Annotation will be acquired.- Returns:
- the Annotation that this interceptor will process for the specified method invocation.
-
-