You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@shiro.apache.org by ka...@apache.org on 2010/01/26 08:05:01 UTC

svn commit: r903104 - in /incubator/shiro/trunk/support/aspectj: ./ src/ src/main/ src/main/aspect/ src/main/aspect/org/ src/main/aspect/org/apache/ src/main/aspect/org/apache/shiro/ src/main/aspect/org/apache/shiro/aspectj/ src/main/java/ src/main/jav...

Author: kaosko
Date: Tue Jan 26 07:04:58 2010
New Revision: 903104

URL: http://svn.apache.org/viewvc?rev=903104&view=rev
Log:
SHIRO-129: Create new module shiro-aspectj based on the originally contributed code. Applied with minor changes and some clean up of the code, mavenized, re-organized directory structure and configured the aspectj plugin to weave in the aspects to the unit tests at runtime. Ignored build artifacts from svn. Module's not connected to the reactor build yet but unit tests succeed

Added:
    incubator/shiro/trunk/support/aspectj/   (with props)
    incubator/shiro/trunk/support/aspectj/pom.xml
    incubator/shiro/trunk/support/aspectj/src/
    incubator/shiro/trunk/support/aspectj/src/main/
    incubator/shiro/trunk/support/aspectj/src/main/aspect/
    incubator/shiro/trunk/support/aspectj/src/main/aspect/org/
    incubator/shiro/trunk/support/aspectj/src/main/aspect/org/apache/
    incubator/shiro/trunk/support/aspectj/src/main/aspect/org/apache/shiro/
    incubator/shiro/trunk/support/aspectj/src/main/aspect/org/apache/shiro/aspectj/
    incubator/shiro/trunk/support/aspectj/src/main/aspect/org/apache/shiro/aspectj/ShiroAnnotationAuthorizingAspect.java
    incubator/shiro/trunk/support/aspectj/src/main/java/
    incubator/shiro/trunk/support/aspectj/src/main/java/org/
    incubator/shiro/trunk/support/aspectj/src/main/java/org/apache/
    incubator/shiro/trunk/support/aspectj/src/main/java/org/apache/shiro/
    incubator/shiro/trunk/support/aspectj/src/main/java/org/apache/shiro/aspectj/
    incubator/shiro/trunk/support/aspectj/src/main/java/org/apache/shiro/aspectj/AspectjAnnotationsAuthorizingMethodInterceptor.java
    incubator/shiro/trunk/support/aspectj/src/main/java/org/apache/shiro/aspectj/BeforeAdviceMethodInvocationAdapter.java
    incubator/shiro/trunk/support/aspectj/src/main/java/org/apache/shiro/aspectj/package-info.java
    incubator/shiro/trunk/support/aspectj/src/test/
    incubator/shiro/trunk/support/aspectj/src/test/java/
    incubator/shiro/trunk/support/aspectj/src/test/java/org/
    incubator/shiro/trunk/support/aspectj/src/test/java/org/apache/
    incubator/shiro/trunk/support/aspectj/src/test/java/org/apache/shiro/
    incubator/shiro/trunk/support/aspectj/src/test/java/org/apache/shiro/aspectj/
    incubator/shiro/trunk/support/aspectj/src/test/java/org/apache/shiro/aspectj/DummyService.java
    incubator/shiro/trunk/support/aspectj/src/test/java/org/apache/shiro/aspectj/DummyServiceTest.java
    incubator/shiro/trunk/support/aspectj/src/test/java/org/apache/shiro/aspectj/RestrictedDummyService.java
    incubator/shiro/trunk/support/aspectj/src/test/java/org/apache/shiro/aspectj/SecuredDummyService.java
    incubator/shiro/trunk/support/aspectj/src/test/resources/
    incubator/shiro/trunk/support/aspectj/src/test/resources/META-INF/
    incubator/shiro/trunk/support/aspectj/src/test/resources/META-INF/aop.xml
    incubator/shiro/trunk/support/aspectj/src/test/resources/shiroDummyServiceTest.ini

Propchange: incubator/shiro/trunk/support/aspectj/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Tue Jan 26 07:04:58 2010
@@ -0,0 +1,4 @@
+.classpath
+.project
+.settings
+target

Added: incubator/shiro/trunk/support/aspectj/pom.xml
URL: http://svn.apache.org/viewvc/incubator/shiro/trunk/support/aspectj/pom.xml?rev=903104&view=auto
==============================================================================
--- incubator/shiro/trunk/support/aspectj/pom.xml (added)
+++ incubator/shiro/trunk/support/aspectj/pom.xml Tue Jan 26 07:04:58 2010
@@ -0,0 +1,88 @@
+<?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.
+  -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+    <parent>
+        <groupId>org.apache.shiro</groupId>
+        <artifactId>shiro-root</artifactId>
+        <version>1.0-incubating-SNAPSHOT</version>
+    </parent>
+
+    <modelVersion>4.0.0</modelVersion>
+    <artifactId>shiro-aspectj</artifactId>
+    <name>Apache Shiro :: Support :: AspectJ</name>
+    <packaging>jar</packaging>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.shiro</groupId>
+            <artifactId>shiro-core</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.aspectj</groupId>
+            <artifactId>aspectjrt</artifactId>
+            <version>1.6.7</version>
+        </dependency>
+        <dependency>
+            <groupId>org.aspectj</groupId>
+            <artifactId>aspectjweaver</artifactId>
+            <version>1.6.8</version>
+        </dependency>
+        <!-- Test dependencies -->
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>jcl-over-slf4j</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-log4j12</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>log4j</groupId>
+            <artifactId>log4j</artifactId>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.codehaus.mojo</groupId>
+                <artifactId>aspectj-maven-plugin</artifactId>
+                <version>1.3</version>
+                <configuration>
+                    <source>1.6</source>
+                    <target>1.6</target>
+                    <showWeaveInfo>true</showWeaveInfo>
+                </configuration>
+                <executions>
+                    <execution>
+                        <id>aspectj-compile</id>
+                        <goals>
+                            <goal>compile</goal>
+                            <goal>test-compile</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
+
+</project>

Added: 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=903104&view=auto
==============================================================================
--- incubator/shiro/trunk/support/aspectj/src/main/aspect/org/apache/shiro/aspectj/ShiroAnnotationAuthorizingAspect.java (added)
+++ incubator/shiro/trunk/support/aspectj/src/main/aspect/org/apache/shiro/aspectj/ShiroAnnotationAuthorizingAspect.java Tue Jan 26 07:04:58 2010
@@ -0,0 +1,34 @@
+package org.apache.shiro.aspectj;
+
+import org.aspectj.lang.JoinPoint;
+import org.aspectj.lang.annotation.Aspect;
+import org.aspectj.lang.annotation.Before;
+import org.aspectj.lang.annotation.Pointcut;
+
+/**
+ * Aspect that adds a before advice for each invocation of an annotated method.
+ * 
+ * @author J-C Desrochers
+ */
+@Aspect()
+public class ShiroAnnotationAuthorizingAspect {
+
+  private static final String pointCupExpression =
+          "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 * *(..))";
+  
+  @Pointcut(pointCupExpression)
+  void anyShiroAnnotatedMethodCall(JoinPoint thisJoinPoint) {
+  }
+  
+  private AspectjAnnotationsAuthorizingMethodInterceptor interceptor =
+          new AspectjAnnotationsAuthorizingMethodInterceptor();
+
+  @Before("anyShiroAnnotatedMethodCall(thisJoinPoint)")
+  public void executeAnnotatedMethod(JoinPoint thisJoinPoint) throws Throwable {
+    interceptor.performBeforeInterception(thisJoinPoint);
+  }
+}

Added: incubator/shiro/trunk/support/aspectj/src/main/java/org/apache/shiro/aspectj/AspectjAnnotationsAuthorizingMethodInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/shiro/trunk/support/aspectj/src/main/java/org/apache/shiro/aspectj/AspectjAnnotationsAuthorizingMethodInterceptor.java?rev=903104&view=auto
==============================================================================
--- incubator/shiro/trunk/support/aspectj/src/main/java/org/apache/shiro/aspectj/AspectjAnnotationsAuthorizingMethodInterceptor.java (added)
+++ incubator/shiro/trunk/support/aspectj/src/main/java/org/apache/shiro/aspectj/AspectjAnnotationsAuthorizingMethodInterceptor.java Tue Jan 26 07:04:58 2010
@@ -0,0 +1,47 @@
+package org.apache.shiro.aspectj;
+
+import java.util.Arrays;
+
+import org.apache.shiro.aop.MethodInvocation;
+import org.apache.shiro.authz.aop.AnnotationsAuthorizingMethodInterceptor;
+import org.aspectj.lang.JoinPoint;
+import org.aspectj.lang.reflect.MethodSignature;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Extends the annotations authorizing method interceptor class hierarchie to adapt
+ * an aspectj {@link JoinPoint} into a {@link MethodInvocation} amd to perform the
+ * authorization of method invocations.
+ * 
+ * @author J-C Desrochers
+ * @author Kalle Korhonen
+ * @since 1.0.0
+ */
+public class AspectjAnnotationsAuthorizingMethodInterceptor extends AnnotationsAuthorizingMethodInterceptor {
+  /**
+   * This class's private log instance.
+   */
+  private static final Logger log = LoggerFactory.getLogger(AspectjAnnotationsAuthorizingMethodInterceptor.class);
+
+  /**
+   * Performs the method interception of the before advice at the specified joint point.
+   * 
+   * @param aJoinPoint The joint point to intercept.
+   * @throws Throwable If an error occurs berforming the method invocation.
+   */
+  protected void performBeforeInterception(JoinPoint aJoinPoint) throws Throwable {
+    if (log.isTraceEnabled()) log.trace( "#### Invoking a method decorated with a Shiro annotation" +
+	            "\n\tkind       : " + aJoinPoint.getKind() +
+	            "\n\tjoinPoint  : " + aJoinPoint +
+	            "\n\tannotations: " + Arrays.toString(((MethodSignature) aJoinPoint.getSignature()).getMethod().getAnnotations()) +
+	            "\n\ttarget     : " + aJoinPoint.getTarget()
+	            );
+    
+    // 1. Adapt the join point into a method invocation
+    BeforeAdviceMethodInvocationAdapter mi = BeforeAdviceMethodInvocationAdapter.createFrom(aJoinPoint);
+
+    // 2. Delegate the authorization of the method call to the super class
+    super.invoke(mi);
+  }
+}

Added: incubator/shiro/trunk/support/aspectj/src/main/java/org/apache/shiro/aspectj/BeforeAdviceMethodInvocationAdapter.java
URL: http://svn.apache.org/viewvc/incubator/shiro/trunk/support/aspectj/src/main/java/org/apache/shiro/aspectj/BeforeAdviceMethodInvocationAdapter.java?rev=903104&view=auto
==============================================================================
--- incubator/shiro/trunk/support/aspectj/src/main/java/org/apache/shiro/aspectj/BeforeAdviceMethodInvocationAdapter.java (added)
+++ incubator/shiro/trunk/support/aspectj/src/main/java/org/apache/shiro/aspectj/BeforeAdviceMethodInvocationAdapter.java Tue Jan 26 07:04:58 2010
@@ -0,0 +1,78 @@
+package org.apache.shiro.aspectj;
+
+import java.lang.reflect.Method;
+
+import org.apache.shiro.aop.MethodInvocation;
+import org.aspectj.lang.JoinPoint;
+import org.aspectj.lang.reflect.AdviceSignature;
+import org.aspectj.lang.reflect.MethodSignature;
+
+/**
+ * Helper class that adapts and aspectj {@link JoinPoint}.
+ * 
+ * @author J-C Desrochers
+ * @since 1.0.0
+ */
+public class BeforeAdviceMethodInvocationAdapter implements MethodInvocation {
+
+  private Method _method;
+  private Object[] _arguments;
+
+  /**
+   * Factory method that creates a new {@link BeforeAdviceMethodInvocationAdapter} instance
+   * using the AspectJ {@link JoinPoint} provided. The the joint point passed in is not
+   * a method joint point, this method throws an {@link IllegalArgumentException}.
+   * 
+   * @param aJoinPoint The AspectJ {@link JoinPoint} to use to adapt the advice.
+   * @return The created instance.
+   * @throws IllegalArgumentException If the join point passed in does not involve a method call.
+   */
+  public static BeforeAdviceMethodInvocationAdapter createFrom(JoinPoint aJoinPoint) {
+    if (aJoinPoint.getSignature() instanceof MethodSignature) {
+      return new BeforeAdviceMethodInvocationAdapter(
+              ((MethodSignature) aJoinPoint.getSignature()).getMethod(),
+              aJoinPoint.getArgs());
+      
+    } else if (aJoinPoint.getSignature() instanceof AdviceSignature) {
+      return new BeforeAdviceMethodInvocationAdapter(
+              ((AdviceSignature) aJoinPoint.getSignature()).getAdvice(),
+              aJoinPoint.getArgs());
+      
+    } else {
+      throw new IllegalArgumentException("The joint point signature is invalid: expected a MethodSignature or an AdviceSignature but was " + aJoinPoint.getSignature());
+    }
+  }
+  
+  /**
+   * Creates a new {@link BeforeAdviceMethodInvocationAdapter} instance.
+   *
+   * @param aMethod The method to invoke.
+   * @param someArguments The arguments of the method invocation.
+   */
+  public BeforeAdviceMethodInvocationAdapter(Method aMethod, Object[] someArguments) {
+    _method = aMethod;
+    _arguments = someArguments;
+  }
+  
+  /* (non-Javadoc)
+   * @see org.apache.shiro.aop.MethodInvocation#getArguments()
+   */
+  public Object[] getArguments() {
+    return _arguments;
+  }
+
+  /* (non-Javadoc)
+   * @see org.apache.shiro.aop.MethodInvocation#getMethod()
+   */
+  public Method getMethod() {
+    return _method;
+  }
+
+  /* (non-Javadoc)
+   * @see org.apache.shiro.aop.MethodInvocation#proceed()
+   */
+  public Object proceed() throws Throwable {
+    // Do nothing since this adapts a before advice
+    return null;
+  }
+}

Added: incubator/shiro/trunk/support/aspectj/src/main/java/org/apache/shiro/aspectj/package-info.java
URL: http://svn.apache.org/viewvc/incubator/shiro/trunk/support/aspectj/src/main/java/org/apache/shiro/aspectj/package-info.java?rev=903104&view=auto
==============================================================================
--- incubator/shiro/trunk/support/aspectj/src/main/java/org/apache/shiro/aspectj/package-info.java (added)
+++ incubator/shiro/trunk/support/aspectj/src/main/java/org/apache/shiro/aspectj/package-info.java Tue Jan 26 07:04:58 2010
@@ -0,0 +1,23 @@
+package org.apache.shiro.aspectj;
+/*
+ * 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.
+ */
+/**
+ * <a href="http://www.eclipse.org/aspectj/">AspectJ</a> support for enabling
+ * dynamic authorization using Shiro's annotations.
+ */

Added: incubator/shiro/trunk/support/aspectj/src/test/java/org/apache/shiro/aspectj/DummyService.java
URL: http://svn.apache.org/viewvc/incubator/shiro/trunk/support/aspectj/src/test/java/org/apache/shiro/aspectj/DummyService.java?rev=903104&view=auto
==============================================================================
--- incubator/shiro/trunk/support/aspectj/src/test/java/org/apache/shiro/aspectj/DummyService.java (added)
+++ incubator/shiro/trunk/support/aspectj/src/test/java/org/apache/shiro/aspectj/DummyService.java Tue Jan 26 07:04:58 2010
@@ -0,0 +1,22 @@
+package org.apache.shiro.aspectj;
+
+
+/**
+ * Basic service for test purposes.
+ * 
+ * @author J-C Desrochers
+ */
+public interface DummyService {
+
+  public void log(String aMessage);
+  
+  public void anonymous();
+
+  public void guest();
+  
+  public void peek();
+  
+  public void retrieve();
+  
+  public void change();
+}

Added: incubator/shiro/trunk/support/aspectj/src/test/java/org/apache/shiro/aspectj/DummyServiceTest.java
URL: http://svn.apache.org/viewvc/incubator/shiro/trunk/support/aspectj/src/test/java/org/apache/shiro/aspectj/DummyServiceTest.java?rev=903104&view=auto
==============================================================================
--- incubator/shiro/trunk/support/aspectj/src/test/java/org/apache/shiro/aspectj/DummyServiceTest.java (added)
+++ incubator/shiro/trunk/support/aspectj/src/test/java/org/apache/shiro/aspectj/DummyServiceTest.java Tue Jan 26 07:04:58 2010
@@ -0,0 +1,226 @@
+package org.apache.shiro.aspectj;
+
+import org.apache.log4j.ConsoleAppender;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.apache.log4j.SimpleLayout;
+import org.apache.shiro.SecurityUtils;
+import org.apache.shiro.authc.UsernamePasswordToken;
+import org.apache.shiro.authz.UnauthenticatedException;
+import org.apache.shiro.authz.UnauthorizedException;
+import org.apache.shiro.config.IniSecurityManagerFactory;
+import org.apache.shiro.mgt.SecurityManager;
+import org.apache.shiro.subject.Subject;
+import org.apache.shiro.util.Factory;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * 
+ * @author J-C Desrochers
+ * @author Kalle Korhonen
+ */
+public class DummyServiceTest {
+
+  private static DummyService SECURED_SERVICE;
+  private static DummyService RESTRICTED_SERVICE;
+  
+  @BeforeClass
+  public static void setUpClass() throws Exception {
+    Logger log = Logger.getLogger(AspectjAnnotationsAuthorizingMethodInterceptor.class);
+    log.addAppender(new ConsoleAppender(new SimpleLayout(), ConsoleAppender.SYSTEM_OUT));
+    log.setLevel(Level.TRACE);
+      
+    Factory<SecurityManager> factory = new IniSecurityManagerFactory("classpath:shiroDummyServiceTest.ini");
+    SecurityManager securityManager = factory.getInstance();
+    SecurityUtils.setSecurityManager(securityManager);
+    
+    SECURED_SERVICE = new SecuredDummyService();
+    RESTRICTED_SERVICE = new RestrictedDummyService();
+  }
+  
+  private Subject subject;
+  
+  @Before
+  public void setUp() throws Exception {
+    subject = SecurityUtils.getSubject();
+  }
+  
+  @After
+  public void tearDown() throws Exception {
+    subject.logout();
+  }
+  
+  
+  
+  private void loginAsGuest() {
+    subject.login(new UsernamePasswordToken("john", "doe"));
+  }
+  
+  private void loginAsUser() {
+    subject.login(new UsernamePasswordToken("joe", "bob"));
+  }
+  
+  private void loginAsAdmin() {
+    subject.login(new UsernamePasswordToken("root", "secret"));
+  }
+  
+  
+  // TEST ANONYMOUS
+  
+  @Test
+  public void testAnonymous_asAnonymous() throws Exception {
+    SECURED_SERVICE.anonymous();
+  }
+  
+  @Test
+  public void testAnonymous_asGuest() throws Exception {
+    loginAsGuest();
+    SECURED_SERVICE.anonymous();
+  }
+  
+  @Test
+  public void testAnonymous_asUser() throws Exception {
+    loginAsUser();
+    SECURED_SERVICE.anonymous();
+  }
+  
+  @Test
+  public void testAnonymous_asAdmin() throws Exception {
+    loginAsAdmin();
+    SECURED_SERVICE.anonymous();
+  }
+
+  
+  // TEST GUEST
+  
+  @Test(expected=UnauthenticatedException.class)
+  public void testGuest_asAnonymous() throws Exception {
+    SECURED_SERVICE.guest();
+  }
+  
+  @Test
+  public void testGuest_asGuest() throws Exception {
+    loginAsGuest();
+    SECURED_SERVICE.guest();
+  }
+  
+  @Test
+  public void testGuest_asUser() throws Exception {
+    loginAsUser();
+    SECURED_SERVICE.guest();
+  }
+  
+  @Test
+  public void testGuest_asAdmin() throws Exception {
+    loginAsAdmin();
+    SECURED_SERVICE.guest();
+  }
+
+  
+  // TEST PEEK
+  
+  @Test(expected=UnauthenticatedException.class)
+  public void testPeek_asAnonymous() throws Exception {
+    SECURED_SERVICE.peek();
+  }
+  
+  @Test
+  public void testPeek_asGuest() throws Exception {
+    loginAsGuest();
+    SECURED_SERVICE.peek();
+  }
+  
+  @Test
+  public void testPeek_asUser() throws Exception {
+    loginAsUser();
+    SECURED_SERVICE.peek();
+  }
+  
+  @Test
+  public void testPeek_asAdmin() throws Exception {
+    loginAsAdmin();
+    SECURED_SERVICE.peek();
+  }
+  
+  
+  // TEST RETRIEVE
+  
+  @Test(expected=UnauthorizedException.class)
+  public void testRetrieve_asAnonymous() throws Exception {
+    SECURED_SERVICE.retrieve();
+  }
+
+  @Test(expected=UnauthorizedException.class)
+  public void testRetrieve_asGuest() throws Exception {
+    loginAsGuest();
+    SECURED_SERVICE.retrieve();
+  }
+
+  @Test
+  public void testRetrieve_asUser() throws Exception {
+    loginAsUser();
+    SECURED_SERVICE.retrieve();
+  }
+
+  @Test
+  public void testRetrieve_asAdmin() throws Exception {
+    loginAsAdmin();
+    SECURED_SERVICE.retrieve();
+  }
+
+  
+  // TEST CHANGE
+  
+  @Test(expected=UnauthorizedException.class)
+  public void testChange_asAnonymous() throws Exception {
+    SECURED_SERVICE.change();
+  }
+  
+  @Test(expected=UnauthorizedException.class)
+  public void testChange_asGuest() throws Exception {
+    loginAsGuest();
+    SECURED_SERVICE.change();
+  }
+  
+  @Test(expected=UnauthorizedException.class)
+  public void testChange_asUser() throws Exception {
+    loginAsUser();
+    SECURED_SERVICE.change();
+  }
+  
+  @Test
+  public void testChange_asAdmin() throws Exception {
+    loginAsAdmin();
+    SECURED_SERVICE.change();
+  }
+  
+  
+  // TEST RETRIEVE RESTRICTED
+  
+  @Test(expected=UnauthorizedException.class)
+  public void testRetrieveRestricted_asAnonymous() throws Exception {
+    RESTRICTED_SERVICE.retrieve();
+  }
+
+  @Test(expected=UnauthorizedException.class)
+  public void testRetrieveRestricted_asGuest() throws Exception {
+    loginAsGuest();
+    RESTRICTED_SERVICE.retrieve();
+  }
+
+  @Test(expected=UnauthorizedException.class)
+  public void testRetrieveRestricted_asUser() throws Exception {
+    loginAsUser();
+    RESTRICTED_SERVICE.retrieve();
+  }
+
+  @Test
+  public void testRetrieveRestricted_asAdmin() throws Exception {
+    loginAsAdmin();
+    RESTRICTED_SERVICE.retrieve();
+  }
+  
+}

Added: incubator/shiro/trunk/support/aspectj/src/test/java/org/apache/shiro/aspectj/RestrictedDummyService.java
URL: http://svn.apache.org/viewvc/incubator/shiro/trunk/support/aspectj/src/test/java/org/apache/shiro/aspectj/RestrictedDummyService.java?rev=903104&view=auto
==============================================================================
--- incubator/shiro/trunk/support/aspectj/src/test/java/org/apache/shiro/aspectj/RestrictedDummyService.java (added)
+++ incubator/shiro/trunk/support/aspectj/src/test/java/org/apache/shiro/aspectj/RestrictedDummyService.java Tue Jan 26 07:04:58 2010
@@ -0,0 +1,19 @@
+package org.apache.shiro.aspectj;
+
+import org.apache.shiro.authz.annotation.RequiresPermissions;
+
+/**
+ * Extends the secure dummy service and makes it some access more restrictive.
+ * 
+ * @author J-C Desrochers
+ */
+public class RestrictedDummyService extends SecuredDummyService {
+
+  @RequiresPermissions("dummy:admin")
+  public void retrieve() {
+    log("retrieve *RESTRICTED*");
+    super.retrieve();
+  }
+
+  
+}

Added: incubator/shiro/trunk/support/aspectj/src/test/java/org/apache/shiro/aspectj/SecuredDummyService.java
URL: http://svn.apache.org/viewvc/incubator/shiro/trunk/support/aspectj/src/test/java/org/apache/shiro/aspectj/SecuredDummyService.java?rev=903104&view=auto
==============================================================================
--- incubator/shiro/trunk/support/aspectj/src/test/java/org/apache/shiro/aspectj/SecuredDummyService.java (added)
+++ incubator/shiro/trunk/support/aspectj/src/test/java/org/apache/shiro/aspectj/SecuredDummyService.java Tue Jan 26 07:04:58 2010
@@ -0,0 +1,51 @@
+package org.apache.shiro.aspectj;
+
+import java.sql.Timestamp;
+
+import org.apache.shiro.authz.annotation.RequiresAuthentication;
+import org.apache.shiro.authz.annotation.RequiresPermissions;
+import org.apache.shiro.authz.annotation.RequiresUser;
+
+/**
+ * Secured implementation of te dummy service that requires some permissions to execute.
+ * 
+ * @author J-C Desrochers
+ */
+public class SecuredDummyService implements DummyService {
+
+  @RequiresAuthentication
+  @RequiresPermissions("dummy:admin")
+  public void change() {
+    retrieve();
+    log("change");
+    peek();
+  }
+
+  public void anonymous() {
+    log("anonymous");
+  }
+
+  @RequiresAuthentication
+  public void guest() {
+    log("guest");
+  }
+  
+  @RequiresUser
+  public void peek() {
+    log("peek");
+  }
+
+  @RequiresPermissions("dummy:user")
+  public void retrieve() {
+    log("retrieve");
+  }
+  
+  public void log(String aMessage) {
+    if (aMessage != null) {
+      System.out.println(new Timestamp(System.currentTimeMillis()).toString() + " [" + Thread.currentThread() + "] * LOG * " + aMessage);
+    } else {
+      System.out.println("\n\n");
+    }
+  }
+
+}

Added: incubator/shiro/trunk/support/aspectj/src/test/resources/META-INF/aop.xml
URL: http://svn.apache.org/viewvc/incubator/shiro/trunk/support/aspectj/src/test/resources/META-INF/aop.xml?rev=903104&view=auto
==============================================================================
--- incubator/shiro/trunk/support/aspectj/src/test/resources/META-INF/aop.xml (added)
+++ incubator/shiro/trunk/support/aspectj/src/test/resources/META-INF/aop.xml Tue Jan 26 07:04:58 2010
@@ -0,0 +1,10 @@
+<aspectj>
+   <aspects>
+    <aspect name="org.apache.shiro.aspectj.ShiroAnnotationAuthorizingAspect"/>
+  </aspects>
+
+  <weaver options="-verbose">
+    <include within="org.apache.shiro.aspectj.*"/>
+  </weaver>
+
+</aspectj>

Added: incubator/shiro/trunk/support/aspectj/src/test/resources/shiroDummyServiceTest.ini
URL: http://svn.apache.org/viewvc/incubator/shiro/trunk/support/aspectj/src/test/resources/shiroDummyServiceTest.ini?rev=903104&view=auto
==============================================================================
--- incubator/shiro/trunk/support/aspectj/src/test/resources/shiroDummyServiceTest.ini (added)
+++ incubator/shiro/trunk/support/aspectj/src/test/resources/shiroDummyServiceTest.ini Tue Jan 26 07:04:58 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.
+#
+
+
+# -----------------------------------------------------------------------------
+# Users and their assigned roles
+#
+# Each line conforms to the format defined in the
+# org.apache.shiro.realm.text.TextConfigurationRealm#setUserDefinitions JavaDoc
+# -----------------------------------------------------------------------------
+[users]
+root = secret, admin
+joe = bob, user
+john = doe
+
+
+# -----------------------------------------------------------------------------
+# Roles with assigned permissions
+# 
+# Each line conforms to the format defined in the
+# org.apache.shiro.realm.text.TextConfigurationRealm#setRoleDefinitions JavaDoc
+# -----------------------------------------------------------------------------
+[roles]
+admin = dummy:*
+user = dummy:user