shiro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kao...@apache.org
Subject svn commit: r979513 - /incubator/shiro/trunk/support/spring/src/main/java/org/apache/shiro/spring/aop/SpringAnnotationResolver.java
Date Tue, 27 Jul 2010 03:42:56 GMT
Author: kaosko
Date: Tue Jul 27 03:42:55 2010
New Revision: 979513

URL: http://svn.apache.org/viewvc?rev=979513&view=rev
Log:
Incomplete - issue SHIRO-175: Improve Set of permission and role checks 
https://issues.apache.org/jira/browse/SHIRO-175
- Change SpringAnnotationResolver to consider classes as well, following the previous commit

Modified:
    incubator/shiro/trunk/support/spring/src/main/java/org/apache/shiro/spring/aop/SpringAnnotationResolver.java

Modified: incubator/shiro/trunk/support/spring/src/main/java/org/apache/shiro/spring/aop/SpringAnnotationResolver.java
URL: http://svn.apache.org/viewvc/incubator/shiro/trunk/support/spring/src/main/java/org/apache/shiro/spring/aop/SpringAnnotationResolver.java?rev=979513&r1=979512&r2=979513&view=diff
==============================================================================
--- incubator/shiro/trunk/support/spring/src/main/java/org/apache/shiro/spring/aop/SpringAnnotationResolver.java
(original)
+++ incubator/shiro/trunk/support/spring/src/main/java/org/apache/shiro/spring/aop/SpringAnnotationResolver.java
Tue Jul 27 03:42:55 2010
@@ -20,8 +20,6 @@ package org.apache.shiro.spring.aop;
 
 import org.apache.shiro.aop.AnnotationResolver;
 import org.apache.shiro.aop.MethodInvocation;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 import org.springframework.core.annotation.AnnotationUtils;
 import org.springframework.util.ClassUtils;
 
@@ -40,23 +38,20 @@ public class SpringAnnotationResolver im
 
     public Annotation getAnnotation(MethodInvocation mi, Class<? extends Annotation>
clazz) {
         Method m = mi.getMethod();
-        Object target = mi.getThis();
 
         Annotation a = AnnotationUtils.findAnnotation(m, clazz);
+        if (a != null) return a;
 
-        if (a == null) {
-            //The MethodInvocation's method object could be a method defined in an interface.
-            //However, if the annotation existed in the interface's implementation (and not
-            //the interface itself), it won't be on the above method object.  Instead, we
need to
-            //acquire the method representation from the targetClass and check directly on
the
-            //implementation itself:
-            if ( target != null) {
-                Class targetClass = target.getClass();
-                m = ClassUtils.getMostSpecificMethod(m, targetClass);
-                a = AnnotationUtils.findAnnotation(m, clazz);
-            }
-        }
-
-        return a;
+        //The MethodInvocation's method object could be a method defined in an interface.
+        //However, if the annotation existed in the interface's implementation (and not
+        //the interface itself), it won't be on the above method object.  Instead, we need
to
+        //acquire the method representation from the targetClass and check directly on the
+        //implementation itself:
+        Class<?> targetClass = mi.getThis().getClass();
+        m = ClassUtils.getMostSpecificMethod(m, targetClass);
+        a = AnnotationUtils.findAnnotation(m, clazz);
+        if (a != null) return a;
+        // See if the class has the same annotation
+        return AnnotationUtils.findAnnotation(mi.getThis().getClass(), clazz);
     }
 }



Mime
View raw message