shiro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lhazlew...@apache.org
Subject svn commit: r965181 - in /incubator/shiro/trunk: core/src/main/java/org/apache/shiro/aop/ core/src/main/java/org/apache/shiro/authz/aop/ support/aspectj/src/main/aspect/org/apache/shiro/aspectj/ support/spring/ support/spring/src/main/java/org/apache/s...
Date Sun, 18 Jul 2010 09:12:20 GMT
Author: lhazlewood
Date: Sun Jul 18 09:12:19 2010
New Revision: 965181

URL: http://svn.apache.org/viewvc?rev=965181&view=rev
Log:
SHIRO-185: Implemented fix, using Spring's AnnotationUtils to correctly detect annotations on either the interface methods or the implementation methods.  Accompanied with both bean ProxyCreator spring config as well as Schema namespace <aop:config/> config tests.

Added:
    incubator/shiro/trunk/core/src/main/java/org/apache/shiro/aop/AnnotationResolver.java
    incubator/shiro/trunk/core/src/main/java/org/apache/shiro/aop/DefaultAnnotationResolver.java
    incubator/shiro/trunk/support/spring/src/main/java/org/apache/shiro/spring/aop/
    incubator/shiro/trunk/support/spring/src/main/java/org/apache/shiro/spring/aop/SpringAnnotationResolver.java
    incubator/shiro/trunk/support/spring/src/test/java/org/apache/shiro/spring/security/
    incubator/shiro/trunk/support/spring/src/test/java/org/apache/shiro/spring/security/interceptor/
    incubator/shiro/trunk/support/spring/src/test/java/org/apache/shiro/spring/security/interceptor/AbstractAuthorizationAnnotationTest.java
    incubator/shiro/trunk/support/spring/src/test/java/org/apache/shiro/spring/security/interceptor/DapcAuthorizationAnnotationTest.java
    incubator/shiro/trunk/support/spring/src/test/java/org/apache/shiro/spring/security/interceptor/DefaultTestService.java
    incubator/shiro/trunk/support/spring/src/test/java/org/apache/shiro/spring/security/interceptor/SchemaAuthorizationAnnotationTest.java
    incubator/shiro/trunk/support/spring/src/test/java/org/apache/shiro/spring/security/interceptor/TestService.java
    incubator/shiro/trunk/support/spring/src/test/resources/log4j.properties
    incubator/shiro/trunk/support/spring/src/test/resources/org/apache/shiro/spring/security/
    incubator/shiro/trunk/support/spring/src/test/resources/org/apache/shiro/spring/security/interceptor/
    incubator/shiro/trunk/support/spring/src/test/resources/org/apache/shiro/spring/security/interceptor/AbstractAuthorizationAnnotationTest-context.xml
    incubator/shiro/trunk/support/spring/src/test/resources/org/apache/shiro/spring/security/interceptor/DapcAuthorizationAnnotationTest-context.xml
    incubator/shiro/trunk/support/spring/src/test/resources/org/apache/shiro/spring/security/interceptor/SchemaAuthorizationAnnotationTest-context.xml
Modified:
    incubator/shiro/trunk/core/src/main/java/org/apache/shiro/aop/AnnotationMethodInterceptor.java
    incubator/shiro/trunk/core/src/main/java/org/apache/shiro/authz/aop/AuthenticatedAnnotationMethodInterceptor.java
    incubator/shiro/trunk/core/src/main/java/org/apache/shiro/authz/aop/AuthorizingAnnotationMethodInterceptor.java
    incubator/shiro/trunk/core/src/main/java/org/apache/shiro/authz/aop/GuestAnnotationMethodInterceptor.java
    incubator/shiro/trunk/core/src/main/java/org/apache/shiro/authz/aop/PermissionAnnotationMethodInterceptor.java
    incubator/shiro/trunk/core/src/main/java/org/apache/shiro/authz/aop/RoleAnnotationMethodInterceptor.java
    incubator/shiro/trunk/core/src/main/java/org/apache/shiro/authz/aop/UserAnnotationMethodInterceptor.java
    incubator/shiro/trunk/support/aspectj/src/main/aspect/org/apache/shiro/aspectj/ShiroAnnotationAuthorizingAspect.java
    incubator/shiro/trunk/support/spring/pom.xml
    incubator/shiro/trunk/support/spring/src/main/java/org/apache/shiro/spring/security/interceptor/AopAllianceAnnotationsAuthorizingMethodInterceptor.java
    incubator/shiro/trunk/support/spring/src/main/java/org/apache/shiro/spring/security/interceptor/AuthorizationAttributeSourceAdvisor.java

Modified: incubator/shiro/trunk/core/src/main/java/org/apache/shiro/aop/AnnotationMethodInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/shiro/trunk/core/src/main/java/org/apache/shiro/aop/AnnotationMethodInterceptor.java?rev=965181&r1=965180&r2=965181&view=diff
==============================================================================
--- incubator/shiro/trunk/core/src/main/java/org/apache/shiro/aop/AnnotationMethodInterceptor.java (original)
+++ incubator/shiro/trunk/core/src/main/java/org/apache/shiro/aop/AnnotationMethodInterceptor.java Sun Jul 18 09:12:19 2010
@@ -19,12 +19,14 @@
 package org.apache.shiro.aop;
 
 import java.lang.annotation.Annotation;
-import java.lang.reflect.Method;
-
 
 /**
  * MethodInterceptor that inspects a specific annotation on the method invocation before continuing
  * its execution.
+ * </p>
+ * The annotation is acquired from the {@link MethodInvocation MethodInvocation} via a
+ * {@link AnnotationResolver AnnotationResolver} instance that may be configured.  Unless
+ * overridden, the default {@code AnnotationResolver} is a
  *
  * @since 0.9
  */
@@ -33,25 +35,90 @@ public abstract class AnnotationMethodIn
     private AnnotationHandler handler;
 
     /**
+     * The resolver to use to find annotations on intercepted methods.
+     *
+     * @since 1.1
+     */
+    private AnnotationResolver resolver;
+
+    /**
      * Constructs an <code>AnnotationMethodInterceptor</code> with the
-     * {@link AnnotationHandler AnnotationHandler} that will be used to process annotations of a corresponding
-     * type.
+     * {@link AnnotationHandler AnnotationHandler} that will be used to process annotations of a
+     * corresponding type.
      *
      * @param handler the handler to delegate to for processing the annotation.
      */
     public AnnotationMethodInterceptor(AnnotationHandler handler) {
+        this(handler, new DefaultAnnotationResolver());
+    }
+
+    /**
+     * Constructs an <code>AnnotationMethodInterceptor</code> with the
+     * {@link AnnotationHandler AnnotationHandler} that will be used to process annotations of a
+     * corresponding type, using the specified {@code AnnotationResolver} to acquire annotations
+     * at runtime.
+     *
+     * @param handler  the handler to use to process any discovered annotation
+     * @param resolver the resolver to use to locate/acquire the annotation
+     * @since 1.1
+     */
+    public AnnotationMethodInterceptor(AnnotationHandler handler, AnnotationResolver resolver) {
+        if (handler == null) {
+            throw new IllegalArgumentException("AnnotationHandler argument cannot be null.");
+        }
         setHandler(handler);
+        setResolver(resolver != null ? resolver : new DefaultAnnotationResolver());
     }
 
+    /**
+     * Returns the {@code AnnotationHandler} used to perform authorization behavior based on
+     * an annotation discovered at runtime.
+     *
+     * @return the {@code AnnotationHandler} used to perform authorization behavior based on
+     *         an annotation discovered at runtime.
+     */
     public AnnotationHandler getHandler() {
         return handler;
     }
 
+    /**
+     * Sets the {@code AnnotationHandler} used to perform authorization behavior based on
+     * an annotation discovered at runtime.
+     *
+     * @param handler the {@code AnnotationHandler} used to perform authorization behavior based on
+     *                an annotation discovered at runtime.
+     */
     public void setHandler(AnnotationHandler handler) {
         this.handler = handler;
     }
 
     /**
+     * Returns the {@code AnnotationResolver} to use to acquire annotations from intercepted
+     * methods at runtime.  The annotation is then used by the {@link #getHandler handler} to
+     * perform authorization logic.
+     *
+     * @return the {@code AnnotationResolver} to use to acquire annotations from intercepted
+     *         methods at runtime.
+     * @since 1.1
+     */
+    public AnnotationResolver getResolver() {
+        return resolver;
+    }
+
+    /**
+     * Returns the {@code AnnotationResolver} to use to acquire annotations from intercepted
+     * methods at runtime.  The annotation is then used by the {@link #getHandler handler} to
+     * perform authorization logic.
+     *
+     * @param resolver the {@code AnnotationResolver} to use to acquire annotations from intercepted
+     *                 methods at runtime.
+     * @since 1.1
+     */
+    public void setResolver(AnnotationResolver resolver) {
+        this.resolver = resolver;
+    }
+
+    /**
      * Returns <code>true</code> if this interceptor supports, that is, should inspect, the specified
      * <code>MethodInvocation</code>, <code>false</code> otherwise.
      * <p/>
@@ -70,27 +137,14 @@ public abstract class AnnotationMethodIn
     /**
      * Returns the Annotation that this interceptor will process for the specified method invocation.
      * <p/>
-     * The default implementation merely gets the underlying {@link Method Method} from the supplied
-     * <code>MethodInvocation</code> argument, and returns:
-     * <p/>
-     * <code>mi.{@link Method#getAnnotation(Class) getAnnotation}({@link org.apache.shiro.aop.AnnotationHandler#getAnnotationClass() handler.getAnnotationClass()});</code>
+     * The default implementation acquires the annotation using an annotation
+     * {@link #getResolver resolver} using the internal annotation {@link #getHandler handler}'s
+     * {@link org.apache.shiro.aop.AnnotationHandler#getAnnotationClass() annotationClass}.
      *
      * @param mi the MethodInvocation wrapping the Method from which the Annotation will be acquired.
      * @return the Annotation that this interceptor will process for the specified method invocation.
-     * @throws IllegalArgumentException if the supplied <code>MethodInvocation</code> argument is <code>null</code> or
-     *                                  its underlying <code>Method</code> is <code>null</code>.
      */
-    protected Annotation getAnnotation(MethodInvocation mi) throws IllegalArgumentException {
-        if (mi == null) {
-            throw new IllegalArgumentException("method argument cannot be null");
-        }
-        Method m = mi.getMethod();
-        if (m == null) {
-            String msg = MethodInvocation.class.getName() + " parameter incorrectly constructed.  getMethod() returned null";
-            throw new IllegalArgumentException(msg);
-
-        }
-        return m.getAnnotation(getHandler().getAnnotationClass());
+    protected Annotation getAnnotation(MethodInvocation mi) {
+        return getResolver().getAnnotation(mi, getHandler().getAnnotationClass());
     }
-
 }

Added: incubator/shiro/trunk/core/src/main/java/org/apache/shiro/aop/AnnotationResolver.java
URL: http://svn.apache.org/viewvc/incubator/shiro/trunk/core/src/main/java/org/apache/shiro/aop/AnnotationResolver.java?rev=965181&view=auto
==============================================================================
--- incubator/shiro/trunk/core/src/main/java/org/apache/shiro/aop/AnnotationResolver.java (added)
+++ incubator/shiro/trunk/core/src/main/java/org/apache/shiro/aop/AnnotationResolver.java Sun Jul 18 09:12:19 2010
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.shiro.aop;
+
+import java.lang.annotation.Annotation;
+
+/**
+ * Defines an AOP-framework-independent way of determining if an Annotation exists on a Method.
+ *
+ * @since 1.1
+ */
+public interface AnnotationResolver {
+
+    /**
+     * Returns an {@link Annotation} instance of the specified type based on the given
+     * {@link MethodInvocation MethodInvocation} argument, or {@code null} if no annotation
+     * of that type could be found.
+     *
+     * @param mi the intercepted method to be invoked.
+     * @param clazz the annotation class of the annotation to find.
+     * @return the method's annotation of the specified type or {@code null} if no annotation of
+     *         that type could be found.
+     */
+    Annotation getAnnotation(MethodInvocation mi, Class<? extends Annotation> clazz);
+}

Added: incubator/shiro/trunk/core/src/main/java/org/apache/shiro/aop/DefaultAnnotationResolver.java
URL: http://svn.apache.org/viewvc/incubator/shiro/trunk/core/src/main/java/org/apache/shiro/aop/DefaultAnnotationResolver.java?rev=965181&view=auto
==============================================================================
--- incubator/shiro/trunk/core/src/main/java/org/apache/shiro/aop/DefaultAnnotationResolver.java (added)
+++ incubator/shiro/trunk/core/src/main/java/org/apache/shiro/aop/DefaultAnnotationResolver.java Sun Jul 18 09:12:19 2010
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.shiro.aop;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
+
+/**
+ * Default {@code AnnotationResolver} implementation that merely inspects the
+ * {@link MethodInvocation MethodInvocation}'s {@link MethodInvocation#getMethod() target method},
+ * and returns {@code targetMethod}.{@link Method#getAnnotation(Class) getAnnotation(class)}.
+ * <p/>
+ * Unfortunately Java's default reflection API for Annotations is not very robust, and this logic
+ * may not be enough - if the incoming method invocation represents a method from an interface,
+ * this default logic would not discover the annotation if it existed on the method implementation
+ * directly (as opposed to being defined directly in the interface definition).
+ * <p/>
+ * More complex class hierarchy traversal logic is required to exhaust a method's target object's
+ * classes, parent classes, interfaces and parent interfaces.  That logic will likely be added
+ * to this implementation in due time, but for now, this implementation relies on the JDK's default
+ * {@link Method#getAnnotation(Class) Method.getAnnotation(class)} logic.
+ *
+ * @since 1.1
+ */
+public class DefaultAnnotationResolver implements AnnotationResolver {
+
+    /**
+     * Returns {@code methodInvocation.}{@link org.apache.shiro.aop.MethodInvocation#getMethod() getMethod()}.{@link Method#getAnnotation(Class) getAnnotation(clazz)}.
+     *
+     * @param mi    the intercepted method to be invoked.
+     * @param clazz the annotation class to use to find an annotation instance on the method.
+     * @return the discovered annotation or {@code null} if an annotation instance could not be
+     *         found.
+     */
+    public Annotation getAnnotation(MethodInvocation mi, Class<? extends Annotation> clazz) {
+        if (mi == null) {
+            throw new IllegalArgumentException("method argument cannot be null");
+        }
+        Method m = mi.getMethod();
+        if (m == null) {
+            String msg = MethodInvocation.class.getName() + " parameter incorrectly constructed.  getMethod() returned null";
+            throw new IllegalArgumentException(msg);
+
+        }
+        return m.getAnnotation(clazz);
+    }
+}

Modified: incubator/shiro/trunk/core/src/main/java/org/apache/shiro/authz/aop/AuthenticatedAnnotationMethodInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/shiro/trunk/core/src/main/java/org/apache/shiro/authz/aop/AuthenticatedAnnotationMethodInterceptor.java?rev=965181&r1=965180&r2=965181&view=diff
==============================================================================
--- incubator/shiro/trunk/core/src/main/java/org/apache/shiro/authz/aop/AuthenticatedAnnotationMethodInterceptor.java (original)
+++ incubator/shiro/trunk/core/src/main/java/org/apache/shiro/authz/aop/AuthenticatedAnnotationMethodInterceptor.java Sun Jul 18 09:12:19 2010
@@ -18,6 +18,8 @@
  */
 package org.apache.shiro.authz.aop;
 
+import org.apache.shiro.aop.AnnotationResolver;
+
 /**
  * Checks to see if a @{@link org.apache.shiro.authz.annotation.RequiresAuthentication RequiresAuthenticated} annotation
  * is declared, and if so, ensures the calling
@@ -34,6 +36,14 @@ public class AuthenticatedAnnotationMeth
      * declaration.
      */
     public AuthenticatedAnnotationMethodInterceptor() {
-        super( new AuthenticatedAnnotationHandler() );
+        super(new AuthenticatedAnnotationHandler());
+    }
+
+    /**
+     * @param resolver
+     * @since 1.1
+     */
+    public AuthenticatedAnnotationMethodInterceptor(AnnotationResolver resolver) {
+        super(new AuthenticatedAnnotationHandler(), resolver);
     }
 }

Modified: incubator/shiro/trunk/core/src/main/java/org/apache/shiro/authz/aop/AuthorizingAnnotationMethodInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/shiro/trunk/core/src/main/java/org/apache/shiro/authz/aop/AuthorizingAnnotationMethodInterceptor.java?rev=965181&r1=965180&r2=965181&view=diff
==============================================================================
--- incubator/shiro/trunk/core/src/main/java/org/apache/shiro/authz/aop/AuthorizingAnnotationMethodInterceptor.java (original)
+++ incubator/shiro/trunk/core/src/main/java/org/apache/shiro/authz/aop/AuthorizingAnnotationMethodInterceptor.java Sun Jul 18 09:12:19 2010
@@ -18,7 +18,9 @@
  */
 package org.apache.shiro.authz.aop;
 
+import org.apache.shiro.aop.AnnotationHandler;
 import org.apache.shiro.aop.AnnotationMethodInterceptor;
+import org.apache.shiro.aop.AnnotationResolver;
 import org.apache.shiro.aop.MethodInvocation;
 import org.apache.shiro.authz.AuthorizationException;
 
@@ -43,6 +45,17 @@ public abstract class AuthorizingAnnotat
     }
 
     /**
+     *
+     * @param handler
+     * @param resolver
+     * @since 1.1
+     */
+    public AuthorizingAnnotationMethodInterceptor( AuthorizingAnnotationHandler handler,
+                                                   AnnotationResolver resolver) {
+        super(handler, resolver);
+    }
+
+    /**
      * Ensures the <code>methodInvocation</code> is allowed to execute first before proceeding by calling the
      * {@link #assertAuthorized(org.apache.shiro.aop.MethodInvocation) assertAuthorized} method first.
      *

Modified: incubator/shiro/trunk/core/src/main/java/org/apache/shiro/authz/aop/GuestAnnotationMethodInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/shiro/trunk/core/src/main/java/org/apache/shiro/authz/aop/GuestAnnotationMethodInterceptor.java?rev=965181&r1=965180&r2=965181&view=diff
==============================================================================
--- incubator/shiro/trunk/core/src/main/java/org/apache/shiro/authz/aop/GuestAnnotationMethodInterceptor.java (original)
+++ incubator/shiro/trunk/core/src/main/java/org/apache/shiro/authz/aop/GuestAnnotationMethodInterceptor.java Sun Jul 18 09:12:19 2010
@@ -18,6 +18,8 @@
  */
 package org.apache.shiro.authz.aop;
 
+import org.apache.shiro.aop.AnnotationResolver;
+
 /**
  * Checks to see if a @{@link org.apache.shiro.authz.annotation.RequiresGuest RequiresGuest} annotation
  * is declared, and if so, ensures the calling <code>Subject</code> does <em>not</em>
@@ -37,4 +39,13 @@ public class GuestAnnotationMethodInterc
     public GuestAnnotationMethodInterceptor() {
         super(new GuestAnnotationHandler());
     }
+
+    /**
+     * @param resolver
+     * @since 1.1
+     */
+    public GuestAnnotationMethodInterceptor(AnnotationResolver resolver) {
+        super(new GuestAnnotationHandler(), resolver);
+    }
+
 }

Modified: incubator/shiro/trunk/core/src/main/java/org/apache/shiro/authz/aop/PermissionAnnotationMethodInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/shiro/trunk/core/src/main/java/org/apache/shiro/authz/aop/PermissionAnnotationMethodInterceptor.java?rev=965181&r1=965180&r2=965181&view=diff
==============================================================================
--- incubator/shiro/trunk/core/src/main/java/org/apache/shiro/authz/aop/PermissionAnnotationMethodInterceptor.java (original)
+++ incubator/shiro/trunk/core/src/main/java/org/apache/shiro/authz/aop/PermissionAnnotationMethodInterceptor.java Sun Jul 18 09:12:19 2010
@@ -18,6 +18,8 @@
  */
 package org.apache.shiro.authz.aop;
 
+import org.apache.shiro.aop.AnnotationResolver;
+
 /**
  * Checks to see if a @{@link org.apache.shiro.authz.annotation.RequiresPermissions RequiresPermissions} annotation is declared, and if so, performs
  * a permission check to see if the calling <code>Subject</code> is allowed to call the method.
@@ -38,6 +40,14 @@ public class PermissionAnnotationMethodI
         super( new PermissionAnnotationHandler() );
     }
 
+    /**
+     * @param resolver
+     * @since 1.1
+     */
+    public PermissionAnnotationMethodInterceptor(AnnotationResolver resolver) {
+        super( new PermissionAnnotationHandler(), resolver);
+    }
+
     /*
      * Infers the permission from the specified name path in the annotation.
      * @param methodArgs the <code>MethodInvocation</code> method arguments.

Modified: incubator/shiro/trunk/core/src/main/java/org/apache/shiro/authz/aop/RoleAnnotationMethodInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/shiro/trunk/core/src/main/java/org/apache/shiro/authz/aop/RoleAnnotationMethodInterceptor.java?rev=965181&r1=965180&r2=965181&view=diff
==============================================================================
--- incubator/shiro/trunk/core/src/main/java/org/apache/shiro/authz/aop/RoleAnnotationMethodInterceptor.java (original)
+++ incubator/shiro/trunk/core/src/main/java/org/apache/shiro/authz/aop/RoleAnnotationMethodInterceptor.java Sun Jul 18 09:12:19 2010
@@ -18,6 +18,7 @@
  */
 package org.apache.shiro.authz.aop;
 
+import org.apache.shiro.aop.AnnotationResolver;
 import org.apache.shiro.authz.annotation.RequiresRoles;
 
 
@@ -36,4 +37,12 @@ public class RoleAnnotationMethodInterce
     public RoleAnnotationMethodInterceptor() {
         super( new RoleAnnotationHandler() );
     }
+
+    /**
+     * @param resolver
+     * @since 1.1
+     */
+    public RoleAnnotationMethodInterceptor(AnnotationResolver resolver) {
+        super(new RoleAnnotationHandler(), resolver);
+    }
 }

Modified: incubator/shiro/trunk/core/src/main/java/org/apache/shiro/authz/aop/UserAnnotationMethodInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/shiro/trunk/core/src/main/java/org/apache/shiro/authz/aop/UserAnnotationMethodInterceptor.java?rev=965181&r1=965180&r2=965181&view=diff
==============================================================================
--- incubator/shiro/trunk/core/src/main/java/org/apache/shiro/authz/aop/UserAnnotationMethodInterceptor.java (original)
+++ incubator/shiro/trunk/core/src/main/java/org/apache/shiro/authz/aop/UserAnnotationMethodInterceptor.java Sun Jul 18 09:12:19 2010
@@ -18,6 +18,8 @@
  */
 package org.apache.shiro.authz.aop;
 
+import org.apache.shiro.aop.AnnotationResolver;
+
 /**
  * Checks to see if a @{@link org.apache.shiro.authz.annotation.RequiresUser RequiresUser} annotation
  * is declared, and if so, ensures the calling <code>Subject</code> is <em>either</em>
@@ -40,4 +42,13 @@ public class UserAnnotationMethodInterce
         super( new UserAnnotationHandler() );
     }
 
+    /**
+     *
+     * @param resolver
+     * @since 1.1
+     */
+    public UserAnnotationMethodInterceptor(AnnotationResolver resolver) {
+        super(new UserAnnotationHandler(), resolver);
+    }
+
 }

Modified: incubator/shiro/trunk/support/aspectj/src/main/aspect/org/apache/shiro/aspectj/ShiroAnnotationAuthorizingAspect.java
URL: http://svn.apache.org/viewvc/incubator/shiro/trunk/support/aspectj/src/main/aspect/org/apache/shiro/aspectj/ShiroAnnotationAuthorizingAspect.java?rev=965181&r1=965180&r2=965181&view=diff
==============================================================================
--- incubator/shiro/trunk/support/aspectj/src/main/aspect/org/apache/shiro/aspectj/ShiroAnnotationAuthorizingAspect.java (original)
+++ incubator/shiro/trunk/support/aspectj/src/main/aspect/org/apache/shiro/aspectj/ShiroAnnotationAuthorizingAspect.java Sun Jul 18 09:12:19 2010
@@ -38,6 +38,9 @@ public class ShiroAnnotationAuthorizingA
                     "execution(@org.apache.shiro.authz.annotation.RequiresUser * *(..))";
 
     @Pointcut(pointCupExpression)
+    public void anyShiroAnnotatedMethod(){}
+
+    @Pointcut(pointCupExpression)
     void anyShiroAnnotatedMethodCall(JoinPoint thisJoinPoint) {
     }
 

Modified: incubator/shiro/trunk/support/spring/pom.xml
URL: http://svn.apache.org/viewvc/incubator/shiro/trunk/support/spring/pom.xml?rev=965181&r1=965180&r2=965181&view=diff
==============================================================================
--- incubator/shiro/trunk/support/spring/pom.xml (original)
+++ incubator/shiro/trunk/support/spring/pom.xml Sun Jul 18 09:12:19 2010
@@ -71,6 +71,11 @@
             <artifactId>spring-test</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.apache.shiro</groupId>
+            <artifactId>shiro-aspectj</artifactId>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 
 </project>

Added: 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=965181&view=auto
==============================================================================
--- incubator/shiro/trunk/support/spring/src/main/java/org/apache/shiro/spring/aop/SpringAnnotationResolver.java (added)
+++ incubator/shiro/trunk/support/spring/src/main/java/org/apache/shiro/spring/aop/SpringAnnotationResolver.java Sun Jul 18 09:12:19 2010
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+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;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
+
+/**
+ * {@code AnnotationResolver} implementation that uses Spring's more robust
+ * {@link AnnotationUtils AnnotationUtils} to find method annotations instead of the JDKs simpler
+ * (and rather lacking) {@link Method}.{@link Method#getAnnotation(Class) getAnnotation(class)}
+ * implementation.
+ *
+ * @since 1.1
+ */
+public class SpringAnnotationResolver implements AnnotationResolver {
+
+    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) {
+            //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;
+    }
+}

Modified: incubator/shiro/trunk/support/spring/src/main/java/org/apache/shiro/spring/security/interceptor/AopAllianceAnnotationsAuthorizingMethodInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/shiro/trunk/support/spring/src/main/java/org/apache/shiro/spring/security/interceptor/AopAllianceAnnotationsAuthorizingMethodInterceptor.java?rev=965181&r1=965180&r2=965181&view=diff
==============================================================================
--- incubator/shiro/trunk/support/spring/src/main/java/org/apache/shiro/spring/security/interceptor/AopAllianceAnnotationsAuthorizingMethodInterceptor.java (original)
+++ incubator/shiro/trunk/support/spring/src/main/java/org/apache/shiro/spring/security/interceptor/AopAllianceAnnotationsAuthorizingMethodInterceptor.java Sun Jul 18 09:12:19 2010
@@ -20,9 +20,13 @@ package org.apache.shiro.spring.security
 
 import org.aopalliance.intercept.MethodInterceptor;
 import org.aopalliance.intercept.MethodInvocation;
-import org.apache.shiro.authz.aop.AnnotationsAuthorizingMethodInterceptor;
+import org.apache.shiro.aop.AnnotationResolver;
+import org.apache.shiro.authz.aop.*;
+import org.apache.shiro.spring.aop.SpringAnnotationResolver;
 
 import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.List;
 
 /**
  * Allows Shiro Annotations to work in any <a href="http://aopalliance.sourceforge.net/">AOP Alliance</a>
@@ -33,6 +37,22 @@ import java.lang.reflect.Method;
 public class AopAllianceAnnotationsAuthorizingMethodInterceptor
         extends AnnotationsAuthorizingMethodInterceptor implements MethodInterceptor {
 
+    public AopAllianceAnnotationsAuthorizingMethodInterceptor() {
+        List<AuthorizingAnnotationMethodInterceptor> interceptors =
+                new ArrayList<AuthorizingAnnotationMethodInterceptor>(5);
+
+        //use a Spring-specific Annotation resolver - Spring's AnnotationUtils is nicer than the
+        //raw JDK resolution process.
+        AnnotationResolver resolver = new SpringAnnotationResolver();
+        //we can re-use the same resolver instance - it does not retain state:
+        interceptors.add(new RoleAnnotationMethodInterceptor(resolver));
+        interceptors.add(new PermissionAnnotationMethodInterceptor(resolver));
+        interceptors.add(new AuthenticatedAnnotationMethodInterceptor(resolver));
+        interceptors.add(new UserAnnotationMethodInterceptor(resolver));
+        interceptors.add(new GuestAnnotationMethodInterceptor(resolver));
+
+        setMethodInterceptors(interceptors);
+    }
     /**
      * Creates a {@link MethodInvocation MethodInvocation} that wraps an
      * {@link org.aopalliance.intercept.MethodInvocation org.aopalliance.intercept.MethodInvocation} instance,

Modified: incubator/shiro/trunk/support/spring/src/main/java/org/apache/shiro/spring/security/interceptor/AuthorizationAttributeSourceAdvisor.java
URL: http://svn.apache.org/viewvc/incubator/shiro/trunk/support/spring/src/main/java/org/apache/shiro/spring/security/interceptor/AuthorizationAttributeSourceAdvisor.java?rev=965181&r1=965180&r2=965181&view=diff
==============================================================================
--- incubator/shiro/trunk/support/spring/src/main/java/org/apache/shiro/spring/security/interceptor/AuthorizationAttributeSourceAdvisor.java (original)
+++ incubator/shiro/trunk/support/spring/src/main/java/org/apache/shiro/spring/security/interceptor/AuthorizationAttributeSourceAdvisor.java Sun Jul 18 09:12:19 2010
@@ -18,37 +18,40 @@
  */
 package org.apache.shiro.spring.security.interceptor;
 
-import java.lang.reflect.Method;
-
-import org.springframework.aop.support.StaticMethodMatcherPointcutAdvisor;
-import org.springframework.beans.factory.InitializingBean;
-
+import org.apache.shiro.authz.annotation.*;
+import org.apache.shiro.mgt.SecurityManager;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.aop.support.StaticMethodMatcherPointcutAdvisor;
+import org.springframework.core.annotation.AnnotationUtils;
 
-import org.apache.shiro.authz.annotation.RequiresAuthentication;
-import org.apache.shiro.authz.annotation.RequiresGuest;
-import org.apache.shiro.authz.annotation.RequiresPermissions;
-import org.apache.shiro.authz.annotation.RequiresRoles;
-import org.apache.shiro.authz.annotation.RequiresUser;
-import org.apache.shiro.mgt.SecurityManager;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
 
 
 /**
  * TODO - complete JavaDoc
+ *
  * @since 0.1
  */
-public class AuthorizationAttributeSourceAdvisor extends StaticMethodMatcherPointcutAdvisor
-        implements InitializingBean {
+@SuppressWarnings({"unchecked"})
+public class AuthorizationAttributeSourceAdvisor extends StaticMethodMatcherPointcutAdvisor {
 
     private static final Logger log = LoggerFactory.getLogger(AuthorizationAttributeSourceAdvisor.class);
 
+    private static final Class<? extends Annotation>[] AUTHZ_ANNOTATION_CLASSES =
+            new Class[] {
+                    RequiresPermissions.class, RequiresRoles.class,
+                    RequiresUser.class, RequiresGuest.class, RequiresAuthentication.class
+            };
+
     protected SecurityManager securityManager = null;
 
     /**
      * Create a new AuthorizationAttributeSourceAdvisor.
      */
     public AuthorizationAttributeSourceAdvisor() {
+        setAdvice(new AopAllianceAnnotationsAuthorizingMethodInterceptor());
     }
 
     public SecurityManager getSecurityManager() {
@@ -76,24 +79,37 @@ public class AuthorizationAttributeSourc
      * @see org.springframework.aop.MethodMatcher#matches(java.lang.reflect.Method, Class)
      */
     public boolean matches(Method method, Class targetClass) {
-        return ((method.getAnnotation(RequiresPermissions.class) != null) ||
-                (method.getAnnotation(RequiresRoles.class) != null) ||
-                (method.getAnnotation(RequiresUser.class) != null) ||
-                (method.getAnnotation(RequiresGuest.class) != null ) ||
-                (method.getAnnotation(RequiresAuthentication.class) != null ));
+        Method m = method;
+
+        if ( isAuthzAnnotationPresent(m) ) {
+            return true;
+        }
+
+        //The 'method' parameter could be from an interface that doesn't have the annotation.
+        //Check to see if the implementation has it.
+        if ( targetClass != null) {
+            try {
+                m = targetClass.getMethod(m.getName(), m.getParameterTypes());
+                if ( isAuthzAnnotationPresent(m) ) {
+                    return true;
+                }
+            } catch (NoSuchMethodException ignored) {
+                //default return value is false.  If we can't find the method, then obviously
+                //there is no annotation, so just use the default return value.
+            }
+        }
+
+        return false;
     }
 
-    public void afterPropertiesSet() throws Exception {
-        if (getAdvice() == null) {
-            if (log.isTraceEnabled()) {
-                log.trace("No authorization advice explicitly configured via the 'advice' " +
-                        "property.  Attempting to set " +
-                        "default instance of type [" +
-                        AopAllianceAnnotationsAuthorizingMethodInterceptor.class.getName() + "]");
+    private boolean isAuthzAnnotationPresent(Method method) {
+        for( Class<? extends Annotation> annClass : AUTHZ_ANNOTATION_CLASSES ) {
+            Annotation a = AnnotationUtils.findAnnotation(method, annClass);
+            if ( a != null ) {
+                return true;
             }
-            AopAllianceAnnotationsAuthorizingMethodInterceptor interceptor =
-                    new AopAllianceAnnotationsAuthorizingMethodInterceptor();
-            setAdvice(interceptor);
         }
+        return false;
     }
+
 }

Added: incubator/shiro/trunk/support/spring/src/test/java/org/apache/shiro/spring/security/interceptor/AbstractAuthorizationAnnotationTest.java
URL: http://svn.apache.org/viewvc/incubator/shiro/trunk/support/spring/src/test/java/org/apache/shiro/spring/security/interceptor/AbstractAuthorizationAnnotationTest.java?rev=965181&view=auto
==============================================================================
--- incubator/shiro/trunk/support/spring/src/test/java/org/apache/shiro/spring/security/interceptor/AbstractAuthorizationAnnotationTest.java (added)
+++ incubator/shiro/trunk/support/spring/src/test/java/org/apache/shiro/spring/security/interceptor/AbstractAuthorizationAnnotationTest.java Sun Jul 18 09:12:19 2010
@@ -0,0 +1,156 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.shiro.spring.security.interceptor;
+
+import org.apache.shiro.authz.UnauthenticatedException;
+import org.apache.shiro.realm.Realm;
+import org.apache.shiro.subject.PrincipalCollection;
+import org.apache.shiro.subject.SimplePrincipalCollection;
+import org.apache.shiro.subject.Subject;
+import org.apache.shiro.subject.support.SubjectThreadState;
+import org.apache.shiro.util.ThreadState;
+import org.junit.After;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+/**
+ * Common method tests across implementations.  In actuality, the methods don't change across
+ * subclasses - only the mechanism that enables AOP pointcuts and applies advice.  Those differences
+ * are in spring configuration only.
+ *
+ * @since 1.1
+ */
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration
+public abstract class AbstractAuthorizationAnnotationTest {
+
+    @Autowired
+    protected TestService testService;
+    @Autowired
+    private org.apache.shiro.mgt.SecurityManager securityManager;
+    @Autowired
+    private Realm realm;
+
+    private ThreadState threadState;
+
+    protected void bind(Subject subject) {
+        clearSubject();
+        this.threadState = new SubjectThreadState(subject);
+        this.threadState.bind();
+    }
+
+    @After
+    public void clearSubject() {
+        if (threadState != null) {
+            threadState.clear();
+        }
+    }
+
+    protected void bindGuest() {
+        bind(new Subject.Builder(securityManager).buildSubject());
+    }
+
+    protected void bindUser() {
+        PrincipalCollection principals = new SimplePrincipalCollection("test", realm.getName());
+        bind(new Subject.Builder(securityManager).principals(principals).buildSubject());
+    }
+
+    protected void bindAuthenticatedUser() {
+        PrincipalCollection principals = new SimplePrincipalCollection("test", realm.getName());
+        bind(new Subject.Builder(securityManager).
+                principals(principals).authenticated(true).buildSubject());
+    }
+
+    // GUEST OPERATIONS:
+
+    @Test
+    public void testGuestImplementation() {
+        bindGuest();
+        testService.guestImplementation();
+    }
+
+    @Test(expected = UnauthenticatedException.class)
+    public void testGuestImplementationFailure() {
+        bindUser();
+        testService.guestImplementation();
+    }
+
+    @Test
+    public void testGuestInterface() {
+        bindGuest();
+        testService.guestInterface();
+    }
+    //testGuestInterfaceFailure() cannot be in this class - the SchemaAuthorizationAnnotationTest
+    //subclass does not support annotations on interfaces (Spring AspectJ pointcut expressions
+    //do not support annotations on interface methods).  It is instead in the
+    //DapcAuthorizationAnnotationTest subclass
+
+
+    // USER OPERATIONS
+
+    @Test
+    public void testUserImplementation() {
+        bindUser();
+        testService.userImplementation();
+    }
+
+    @Test(expected = UnauthenticatedException.class)
+    public void testUserImplementationFailure() {
+        bindGuest();
+        testService.userImplementation();
+    }
+
+    @Test
+    public void testUserInterface() {
+        bindUser();
+        testService.userInterface();
+    }
+    //testUserInterfaceFailure() cannot be in this class - the SchemaAuthorizationAnnotationTest
+    //subclass does not support annotations on interfaces (Spring AspectJ pointcut expressions
+    //do not support annotations on interface methods).  It is instead in the
+    //DapcAuthorizationAnnotationTest subclass
+
+
+    // AUTHENTICATED USER OPERATIONS
+
+    @Test
+    public void testAuthenticatedImplementation() {
+        bindAuthenticatedUser();
+        testService.authenticatedImplementation();
+    }
+
+    @Test(expected = UnauthenticatedException.class)
+    public void testAuthenticatedImplementationFailure() {
+        bindUser();
+        testService.authenticatedImplementation();
+    }
+
+    @Test
+    public void testAuthenticatedInterface() {
+        bindAuthenticatedUser();
+        testService.authenticatedInterface();
+    }
+    //testAuthenticatedInterfaceFailure() cannot be in this class - the SchemaAuthorizationAnnotationTest
+    //subclass does not support annotations on interfaces (Spring AspectJ pointcut expressions
+    //do not support annotations on interface methods).  It is instead in the
+    //DapcAuthorizationAnnotationTest subclass
+}

Added: incubator/shiro/trunk/support/spring/src/test/java/org/apache/shiro/spring/security/interceptor/DapcAuthorizationAnnotationTest.java
URL: http://svn.apache.org/viewvc/incubator/shiro/trunk/support/spring/src/test/java/org/apache/shiro/spring/security/interceptor/DapcAuthorizationAnnotationTest.java?rev=965181&view=auto
==============================================================================
--- incubator/shiro/trunk/support/spring/src/test/java/org/apache/shiro/spring/security/interceptor/DapcAuthorizationAnnotationTest.java (added)
+++ incubator/shiro/trunk/support/spring/src/test/java/org/apache/shiro/spring/security/interceptor/DapcAuthorizationAnnotationTest.java Sun Jul 18 09:12:19 2010
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.shiro.spring.security.interceptor;
+
+import org.apache.shiro.authz.UnauthenticatedException;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+/**
+ * All the tests in the parent class are run.  This class only exists to ensure that a
+ * DefaultAutoProxyCreator Spring AOP environment exists and enables annotations correctly as
+ * documented in the Spring reference manual: 
+ * <a href="http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/aop-api.html#aop-autoproxy">
+ * Using the &quot;autoproxy&quot; facility</a>.
+ *
+ * @since 1.1
+ */
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration
+public class DapcAuthorizationAnnotationTest extends AbstractAuthorizationAnnotationTest {
+
+    @Test(expected = UnauthenticatedException.class)
+    public void testGuestInterfaceFailure() {
+        bindUser();
+        testService.guestInterface();
+    }
+
+    @Test(expected = UnauthenticatedException.class)
+    public void testUserInterfaceFailure() {
+        bindGuest();
+        testService.userInterface();
+    }
+
+    @Test(expected = UnauthenticatedException.class)
+    public void testAuthenticatedInterfaceFailure() {
+        bindGuest();
+        testService.authenticatedInterface();
+    }
+}

Added: incubator/shiro/trunk/support/spring/src/test/java/org/apache/shiro/spring/security/interceptor/DefaultTestService.java
URL: http://svn.apache.org/viewvc/incubator/shiro/trunk/support/spring/src/test/java/org/apache/shiro/spring/security/interceptor/DefaultTestService.java?rev=965181&view=auto
==============================================================================
--- incubator/shiro/trunk/support/spring/src/test/java/org/apache/shiro/spring/security/interceptor/DefaultTestService.java (added)
+++ incubator/shiro/trunk/support/spring/src/test/java/org/apache/shiro/spring/security/interceptor/DefaultTestService.java Sun Jul 18 09:12:19 2010
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.shiro.spring.security.interceptor;
+
+import org.apache.shiro.authz.annotation.*;
+
+/**
+ * @since 1.1
+ */
+public class DefaultTestService implements TestService {
+
+    @RequiresGuest
+    public void guestImplementation() {
+    }
+    public void guestInterface() {
+    }
+
+    @RequiresUser
+    public void userImplementation() {
+    }
+    public void userInterface() {
+    }
+
+    @RequiresAuthentication
+    public void authenticatedImplementation() {
+    }
+    public void authenticatedInterface() {
+    }
+
+    @RequiresRoles("test")
+    public void roleImplementation() {
+    }
+    public void roleInterface() {
+    }
+
+    @RequiresPermissions("test:execute")
+    public void permissionImplementation() {
+    }
+    public void permissionInterface() {
+    }
+}

Added: incubator/shiro/trunk/support/spring/src/test/java/org/apache/shiro/spring/security/interceptor/SchemaAuthorizationAnnotationTest.java
URL: http://svn.apache.org/viewvc/incubator/shiro/trunk/support/spring/src/test/java/org/apache/shiro/spring/security/interceptor/SchemaAuthorizationAnnotationTest.java?rev=965181&view=auto
==============================================================================
--- incubator/shiro/trunk/support/spring/src/test/java/org/apache/shiro/spring/security/interceptor/SchemaAuthorizationAnnotationTest.java (added)
+++ incubator/shiro/trunk/support/spring/src/test/java/org/apache/shiro/spring/security/interceptor/SchemaAuthorizationAnnotationTest.java Sun Jul 18 09:12:19 2010
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.shiro.spring.security.interceptor;
+
+import org.junit.runner.RunWith;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+/**
+ * All the tests in the parent class are run.  This class exists to ensure that Shiro
+ * annotations function correctly in Spring applications configured via Spring's AOP namespace
+ * &lt;aop:config&gt; style of configuration, as defined in the Spring reference manual:
+ * <a href="http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/aop.html#aop-schema">
+ * Schema-based AOP support</a>.
+ *
+ * @since 1.1
+ */
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration
+public class SchemaAuthorizationAnnotationTest extends AbstractAuthorizationAnnotationTest {
+}

Added: incubator/shiro/trunk/support/spring/src/test/java/org/apache/shiro/spring/security/interceptor/TestService.java
URL: http://svn.apache.org/viewvc/incubator/shiro/trunk/support/spring/src/test/java/org/apache/shiro/spring/security/interceptor/TestService.java?rev=965181&view=auto
==============================================================================
--- incubator/shiro/trunk/support/spring/src/test/java/org/apache/shiro/spring/security/interceptor/TestService.java (added)
+++ incubator/shiro/trunk/support/spring/src/test/java/org/apache/shiro/spring/security/interceptor/TestService.java Sun Jul 18 09:12:19 2010
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.shiro.spring.security.interceptor;
+
+import org.apache.shiro.authz.annotation.*;
+
+/**
+ * @since 1.1
+ */
+public interface TestService {
+
+    // Guest operations
+    void guestImplementation();
+    @RequiresGuest
+    void guestInterface();
+
+    // User operations
+    void userImplementation();
+    @RequiresUser
+    void userInterface();
+
+    // Authenticated User operations
+    void authenticatedImplementation();
+    @RequiresAuthentication
+    void authenticatedInterface();
+
+    // Role operations
+    void roleImplementation();
+    @RequiresRoles("test")
+    void roleInterface();
+
+    // Permission operations
+    void permissionImplementation();
+    @RequiresPermissions("test:execute")
+    void permissionInterface();
+}

Added: incubator/shiro/trunk/support/spring/src/test/resources/log4j.properties
URL: http://svn.apache.org/viewvc/incubator/shiro/trunk/support/spring/src/test/resources/log4j.properties?rev=965181&view=auto
==============================================================================
--- incubator/shiro/trunk/support/spring/src/test/resources/log4j.properties (added)
+++ incubator/shiro/trunk/support/spring/src/test/resources/log4j.properties Sun Jul 18 09:12:19 2010
@@ -0,0 +1,38 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+log4j.rootLogger=TRACE, stdout
+
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - %m %n
+
+# Pattern to output: date priority [category] - message
+log4j.appender.logfile.layout=org.apache.log4j.PatternLayout
+log4j.appender.logfile.layout.ConversionPattern=%d %p [%c] - %m%n
+
+# Spring logging level is WARN
+log4j.logger.org.springframework=WARN
+
+# General Apache libraries is WARN
+log4j.logger.org.apache=WARN
+
+log4j.logger.net.sf.ehcache=WARN
+
+log4j.logger.org.apache.shiro=INFO
+log4j.logger.org.apache.shiro.util.ThreadContext=WARN
\ No newline at end of file

Added: incubator/shiro/trunk/support/spring/src/test/resources/org/apache/shiro/spring/security/interceptor/AbstractAuthorizationAnnotationTest-context.xml
URL: http://svn.apache.org/viewvc/incubator/shiro/trunk/support/spring/src/test/resources/org/apache/shiro/spring/security/interceptor/AbstractAuthorizationAnnotationTest-context.xml?rev=965181&view=auto
==============================================================================
--- incubator/shiro/trunk/support/spring/src/test/resources/org/apache/shiro/spring/security/interceptor/AbstractAuthorizationAnnotationTest-context.xml (added)
+++ incubator/shiro/trunk/support/spring/src/test/resources/org/apache/shiro/spring/security/interceptor/AbstractAuthorizationAnnotationTest-context.xml Sun Jul 18 09:12:19 2010
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ Licensed to the Apache Software Foundation (ASF) under one
+  ~ or more contributor license agreements.  See the NOTICE file
+  ~ distributed with this work for additional information
+  ~ regarding copyright ownership.  The ASF licenses this file
+  ~ to you under the Apache License, Version 2.0 (the
+  ~ "License"); you may not use this file except in compliance
+  ~ with the License.  You may obtain a copy of the License at
+  ~
+  ~     http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing,
+  ~ software distributed under the License is distributed on an
+  ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  ~ KIND, either express or implied.  See the License for the
+  ~ specific language governing permissions and limitations
+  ~ under the License.
+  -->
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="
+       http://www.springframework.org/schema/beans
+       http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
+
+    <!-- This file defines the common/shared beans used across the concrete
+       AuthorizationAnnotationTest implementations.  Each Test implementation
+       will provide another Spring file in addition to this one that will
+       turn on a different way of enabling Spring AOP.  (i.e. one will use
+       a DefaultAutoProxyCreator, another will use the <aop:config/> mechanism,
+       etc). -->
+
+    <bean id="iniRealm" class="org.apache.shiro.realm.text.IniRealm">
+        <property name="userDefinitions">
+            <value>
+                test = test, test
+            </value>
+        </property>
+    </bean>
+
+    <bean id="securityManager" class="org.apache.shiro.mgt.DefaultSecurityManager">
+        <!-- Single realm app.  If you have multiple realms, use the 'realms' property instead. -->
+        <property name="realm" ref="iniRealm"/>
+    </bean>
+
+    <bean id="testService" class="org.apache.shiro.spring.security.interceptor.DefaultTestService"/>
+
+</beans>

Added: incubator/shiro/trunk/support/spring/src/test/resources/org/apache/shiro/spring/security/interceptor/DapcAuthorizationAnnotationTest-context.xml
URL: http://svn.apache.org/viewvc/incubator/shiro/trunk/support/spring/src/test/resources/org/apache/shiro/spring/security/interceptor/DapcAuthorizationAnnotationTest-context.xml?rev=965181&view=auto
==============================================================================
--- incubator/shiro/trunk/support/spring/src/test/resources/org/apache/shiro/spring/security/interceptor/DapcAuthorizationAnnotationTest-context.xml (added)
+++ incubator/shiro/trunk/support/spring/src/test/resources/org/apache/shiro/spring/security/interceptor/DapcAuthorizationAnnotationTest-context.xml Sun Jul 18 09:12:19 2010
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ Licensed to the Apache Software Foundation (ASF) under one
+  ~ or more contributor license agreements.  See the NOTICE file
+  ~ distributed with this work for additional information
+  ~ regarding copyright ownership.  The ASF licenses this file
+  ~ to you under the Apache License, Version 2.0 (the
+  ~ "License"); you may not use this file except in compliance
+  ~ with the License.  You may obtain a copy of the License at
+  ~
+  ~     http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing,
+  ~ software distributed under the License is distributed on an
+  ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  ~ KIND, either express or implied.  See the License for the
+  ~ specific language governing permissions and limitations
+  ~ under the License.
+  -->
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="
+       http://www.springframework.org/schema/beans
+       http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
+
+    <!-- This file exists to test enabling Shiro annotations in Spring using
+         the DefaultAutoProxyCreator AOP mechanism.  It shares common beans
+         defined in AbstractAuthorizationAnnotationTest-context.xml -->
+
+    <bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator"/>
+    <bean class="org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor">
+        <property name="securityManager" ref="securityManager"/>
+    </bean>
+
+</beans>

Added: incubator/shiro/trunk/support/spring/src/test/resources/org/apache/shiro/spring/security/interceptor/SchemaAuthorizationAnnotationTest-context.xml
URL: http://svn.apache.org/viewvc/incubator/shiro/trunk/support/spring/src/test/resources/org/apache/shiro/spring/security/interceptor/SchemaAuthorizationAnnotationTest-context.xml?rev=965181&view=auto
==============================================================================
--- incubator/shiro/trunk/support/spring/src/test/resources/org/apache/shiro/spring/security/interceptor/SchemaAuthorizationAnnotationTest-context.xml (added)
+++ incubator/shiro/trunk/support/spring/src/test/resources/org/apache/shiro/spring/security/interceptor/SchemaAuthorizationAnnotationTest-context.xml Sun Jul 18 09:12:19 2010
@@ -0,0 +1,51 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ Licensed to the Apache Software Foundation (ASF) under one
+  ~ or more contributor license agreements.  See the NOTICE file
+  ~ distributed with this work for additional information
+  ~ regarding copyright ownership.  The ASF licenses this file
+  ~ to you under the Apache License, Version 2.0 (the
+  ~ "License"); you may not use this file except in compliance
+  ~ with the License.  You may obtain a copy of the License at
+  ~
+  ~     http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing,
+  ~ software distributed under the License is distributed on an
+  ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  ~ KIND, either express or implied.  See the License for the
+  ~ specific language governing permissions and limitations
+  ~ under the License.
+  -->
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xmlns:aop="http://www.springframework.org/schema/aop"
+       xsi:schemaLocation="
+       http://www.springframework.org/schema/beans
+       http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
+       http://www.springframework.org/schema/aop
+       http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
+
+    <!-- This file exists to test enabling Shiro annotations in Spring using
+         the <aop:config/> schema-based AOP configuration.  It shares common beans
+         defined in AbstractAuthorizationAnnotationTest-context.xml -->
+
+    <!-- NOTE:  When using AspectJ-style pointcut definitions, you CAN NOT put the annotations
+                on an interface method.  They MUST be on implementation methods directly.  Spring's
+                AspectJ-style support does not support annotations on interface methods.  If you
+                want annotations on interface methods, you must use either Spring's bean
+                ProxyCreator mechanisms or AspectJ compile-time or load-time weaving. -->
+    <aop:config>
+        <aop:pointcut id="shiroAnnotatedMethod" expression="
+                      execution(@org.apache.shiro.authz.annotation.RequiresAuthentication * *(..)) ||
+                      execution(@org.apache.shiro.authz.annotation.RequiresGuest * *(..)) ||
+                      execution(@org.apache.shiro.authz.annotation.RequiresPermissions * *(..)) ||
+                      execution(@org.apache.shiro.authz.annotation.RequiresRoles * *(..)) ||
+                      execution(@org.apache.shiro.authz.annotation.RequiresUser * *(..))"/>
+        <aop:advisor pointcut-ref="shiroAnnotatedMethod"
+                     advice-ref="shiroAuthorizationAnnotationsAdvice"/>
+    </aop:config>
+    <bean id="shiroAuthorizationAnnotationsAdvice"
+          class="org.apache.shiro.spring.security.interceptor.AopAllianceAnnotationsAuthorizingMethodInterceptor"/>
+
+</beans>
\ No newline at end of file



Mime
View raw message