Permalink
Browse files

Add repro projects for SPR-7664, SPR-8122, SPR-9183

  • Loading branch information...
1 parent 8bc6e56 commit 65ac173b29825aa460bda47c5b751515138b5a4c @cbeams cbeams committed Dec 19, 2012
View
@@ -0,0 +1,69 @@
+<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">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.springframework.issues</groupId>
+ <artifactId>SPR-7664</artifactId>
+ <version>0.0.1-SNAPSHOT</version>
+
+ <properties>
+ <spring.version>3.0.4.RELEASE</spring.version>
+ <aspectj.version>1.6.9</aspectj.version>
+ </properties>
+ <dependencies>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-core</artifactId>
+ <version>${spring.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-context</artifactId>
+ <version>${spring.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-aop</artifactId>
+ <version>${spring.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.aspectj</groupId>
+ <artifactId>aspectjrt</artifactId>
+ <version>${aspectj.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.aspectj</groupId>
+ <artifactId>aspectjweaver</artifactId>
+ <version>${aspectj.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <version>1.2.14</version>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.4</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-test</artifactId>
+ <version>2.5.6</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.6</source>
+ <target>1.6</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
@@ -0,0 +1,12 @@
+package com.xyz;
+
+/**
+ * @author borisb
+ */
+public abstract class DemoService {
+
+ @Secured("QWERTY")
+ public abstract Object secureMethod(String firstName, String lastName);
+
+ public abstract Object unsecureMethod(String firstName, String lastName);
+}
@@ -0,0 +1,17 @@
+package com.xyz;
+
+/**
+ * @author borisb
+ */
+public class DemoServiceImpl extends DemoService {
+
+ @Override
+ public Object secureMethod(String firstName, String lastName) {
+ return "result";
+ }
+
+ @Override
+ public Object unsecureMethod(String firstName, String lastName) {
+ return "result2";
+ }
+}
@@ -0,0 +1,52 @@
+/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
+*
+* Licensed 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 com.xyz;
+
+import java.lang.annotation.*;
+
+/**
+ * Java 5 annotation for describing service layer security attributes.
+ * <p/>
+ * <p>The <code>Secured</code> annotation is used to define a list of security
+ * configuration attributes for business methods. This annotation can be used
+ * as a Java 5 alternative to XML configuration.
+ * <p>For example:
+ * <pre>
+ * &#64;Secured ({"ROLE_USER"})
+ * public void create(Contact contact);
+ * <p/>
+ * &#64;Secured ({"ROLE_USER", "ROLE_ADMIN"})
+ * public void update(Contact contact);
+ * <p/>
+ * &#64;Secured ({"ROLE_ADMIN"})
+ * public void delete(Contact contact);
+ * </pre>
+ *
+ * @author Mark St.Godard
+ * @version $Id: Secured.java 2217 2007-10-27 00:45:30Z luke_t $
+ */
+@Target({ElementType.METHOD, ElementType.TYPE})
+@Retention(RetentionPolicy.RUNTIME)
+@Inherited
+@Documented
+public @interface Secured {
+ /**
+ * Returns the list of security configuration attributes.
+ * (i.e. ROLE_USER, ROLE_ADMIN etc.)
+ *
+ * @return String[] The secure method attributes
+ */
+ public String[] value();
+}
@@ -0,0 +1,48 @@
+package com.xyz;
+
+import org.apache.log4j.Logger;
+import org.aspectj.lang.ProceedingJoinPoint;
+import org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint;
+import org.springframework.aop.framework.ReflectiveMethodInvocation;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+/**
+ * @author borisb
+ */
+public class TestAspect {
+
+ private static final Logger log = Logger.getLogger(TestAspect.class);
+
+ public Object invokeNew(ProceedingJoinPoint pjp) throws Throwable {
+ log.info("aspect invoked");
+ doWork();
+ return pjp.proceed();
+ }
+
+ public Object invokeOld(ProceedingJoinPoint pjp) throws Throwable {
+ log.info("aspect invoked");
+ Field methodInvocationField = MethodInvocationProceedingJoinPoint.class.getDeclaredField("methodInvocation");
+ methodInvocationField.setAccessible(true);
+ ReflectiveMethodInvocation methodInvocation = (ReflectiveMethodInvocation) methodInvocationField.get(pjp);
+
+ Field methodField = ReflectiveMethodInvocation.class.getDeclaredField("method");
+ methodField.setAccessible(true);
+ Method method = (Method) methodField.get(methodInvocation);
+
+ Annotation annotation = method.getAnnotation(Secured.class);
+ if (annotation != null) {
+ log.info("do the aspects work");
+ doWork();
+ }
+ return pjp.proceed();
+ }
+
+ private void doWork() throws Exception {
+ // throw exception to easy check if aspect invoked
+ throw new Exception("aspect invoked");
+ }
+
+}
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:context="http://www.springframework.org/schema/context"
+ 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/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
+ http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
+
+
+ <bean id="demoService" class="com.xyz.DemoServiceImpl"/>
+
+ <bean id="testAspect" class="com.xyz.TestAspect"/>
+
+ <aop:aspectj-autoproxy/>
+
+ <aop:config>
+
+ <aop:aspect ref="testAspect">
+ <!--<aop:around method="invokeOld" pointcut="execution(* com.xyz.DemoService+.*(..))"/>-->
+ <!--<aop:around method="invokeNew" pointcut="@annotation(com.xyz.Secured)" />-->
+
+ <!--<aop:around method="invokeNew" pointcut="@annotation(com.xyz.Secured)"/>-->
+ <!--<aop:around method="invokeNew" pointcut="execution(* com.xyz.DemoService+.*(..))"/>-->
+ <!--<aop:around method="invokeNew"-->
+ <!--pointcut="execution(* com.xyz.*Service+.*(..)) and @annotation(com.xyz.Secured)"/>-->
+
+ <!--<aop:around method="invokeNew"-->
+ <!--pointcut="execution(@com.xyz.Secured * com.xyz.*Service+.*(..))"/>-->
+ <aop:around method="invokeNew"
+ pointcut="execution(@com.xyz.Secured * com.xyz.*Service+.*(..))"/>
+
+ </aop:aspect>
+ </aop:config>
+
+</beans>
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE log4j:configuration SYSTEM "dtd/log4j.dtd">
+<log4j:configuration debug="false" xmlns:log4j='http://jakarta.apache.org/log4j/'>
+
+ <appender name="ConsoleAppender" class="org.apache.log4j.ConsoleAppender">
+ <layout class="org.apache.log4j.PatternLayout">
+ <param name="ConversionPattern" value="%d{dd MMM yyyy HH:mm:ss:SSS} %p %c{1}:%L %m%n" />
+ </layout>
+ </appender>
+
+ <logger name="com.xyz" additivity="false">
+ <level value="debug" />
+ <appender-ref ref="ConsoleAppender" />
+ </logger>
+ <logger name="com.xyz.TestAspect" additivity="false">
+ <level value="warn" />
+ <appender-ref ref="ConsoleAppender" />
+ </logger>
+
+ <logger name="org.springframework" additivity="false">
+ <level value="warn" />
+ <appender-ref ref="ConsoleAppender" />
+ </logger>
+
+ <root>
+ <level value="warn" />
+ <appender-ref ref="ConsoleAppender" />
+ </root>
+
+</log4j:configuration>
@@ -0,0 +1,48 @@
+package com.xyz;
+
+import org.apache.log4j.Logger;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+import javax.annotation.Resource;
+
+/**
+ * @author borisb
+ */
+@ContextConfiguration(locations = {"/applicationContext.xml"})
+@RunWith(SpringJUnit4ClassRunner.class)
+public class TestClass {
+
+ private static final Logger log = Logger.getLogger(TestClass.class);
+
+ @Resource(name = "demoService")
+ private DemoService demoService;
+
+ @Test
+ public void testAspect() {
+ log.info("@Secured annotated method");
+ try {
+ demoService.secureMethod("firstName", "lastName");
+ Assert.fail("exception not thrown!");
+ }
+ catch (Exception e) {
+ if (e.getCause().getMessage().equals("aspect invoked")) {
+ log.info("@Secured annotated method invoked");
+ } else {
+ Assert.fail("wrong exception thrown!");
+ }
+ }
+
+ log.info("no annotated method");
+ try {
+ demoService.unsecureMethod("firstName", "lastName");
+ }
+ catch (Exception e) {
+ Assert.fail("exception thrown!");
+ }
+ }
+
+}
View
@@ -0,0 +1,62 @@
+<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">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.springframework.issues</groupId>
+ <artifactId>SPR-8122</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <packaging>jar</packaging>
+ <dependencies>
+<!-- <dependency> -->
+<!-- <groupId>org.springframework</groupId> -->
+<!-- <artifactId>spring-context</artifactId> -->
+<!-- <version>3.2.0.BUILD-SNAPSHOT</version> -->
+<!-- </dependency> -->
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <version>1.2.16</version>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.8</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ <repositories>
+ <repository>
+ <id>spring-maven-snapshot</id>
+ <name>Springframework Maven Snapshot Repository</name>
+ <url>http://repo.springsource.org/snapshot</url>
+ <snapshots><enabled>true</enabled></snapshots>
+ </repository>
+ </repositories>
+ <properties>
+ <project.build.sourceEncoding>UTF8</project.build.sourceEncoding>
+ </properties>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.3.2</version>
+ <configuration>
+ <source>1.6</source>
+ <target>1.6</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <version>2.7.2</version>
+ <configuration>
+ <includes>
+ <include>**/*Tests.java</include>
+ </includes>
+ <excludes>
+ <exclude>**/*Abstract*.java</exclude>
+ </excludes>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
+
@@ -0,0 +1,5 @@
+package org.springframework.issues;
+
+public class Bar {
+
+}
Oops, something went wrong.

0 comments on commit 65ac173

Please sign in to comment.