Skip to content
This repository was archived by the owner on Dec 15, 2021. It is now read-only.

Commit 65ac173

Browse files
committed
Add repro projects for SPR-7664, SPR-8122, SPR-9183
1 parent 8bc6e56 commit 65ac173

File tree

20 files changed

+632
-0
lines changed

20 files changed

+632
-0
lines changed

SPR-7664/pom.xml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>org.springframework.issues</groupId>
5+
<artifactId>SPR-7664</artifactId>
6+
<version>0.0.1-SNAPSHOT</version>
7+
8+
<properties>
9+
<spring.version>3.0.4.RELEASE</spring.version>
10+
<aspectj.version>1.6.9</aspectj.version>
11+
</properties>
12+
<dependencies>
13+
<dependency>
14+
<groupId>org.springframework</groupId>
15+
<artifactId>spring-core</artifactId>
16+
<version>${spring.version}</version>
17+
</dependency>
18+
<dependency>
19+
<groupId>org.springframework</groupId>
20+
<artifactId>spring-context</artifactId>
21+
<version>${spring.version}</version>
22+
</dependency>
23+
<dependency>
24+
<groupId>org.springframework</groupId>
25+
<artifactId>spring-aop</artifactId>
26+
<version>${spring.version}</version>
27+
</dependency>
28+
<dependency>
29+
<groupId>org.aspectj</groupId>
30+
<artifactId>aspectjrt</artifactId>
31+
<version>${aspectj.version}</version>
32+
</dependency>
33+
<dependency>
34+
<groupId>org.aspectj</groupId>
35+
<artifactId>aspectjweaver</artifactId>
36+
<version>${aspectj.version}</version>
37+
</dependency>
38+
<dependency>
39+
<groupId>log4j</groupId>
40+
<artifactId>log4j</artifactId>
41+
<version>1.2.14</version>
42+
</dependency>
43+
44+
<dependency>
45+
<groupId>junit</groupId>
46+
<artifactId>junit</artifactId>
47+
<version>4.4</version>
48+
<scope>test</scope>
49+
</dependency>
50+
<dependency>
51+
<groupId>org.springframework</groupId>
52+
<artifactId>spring-test</artifactId>
53+
<version>2.5.6</version>
54+
<scope>test</scope>
55+
</dependency>
56+
</dependencies>
57+
<build>
58+
<plugins>
59+
<plugin>
60+
<artifactId>maven-compiler-plugin</artifactId>
61+
<configuration>
62+
<source>1.6</source>
63+
<target>1.6</target>
64+
</configuration>
65+
</plugin>
66+
</plugins>
67+
</build>
68+
69+
</project>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.xyz;
2+
3+
/**
4+
* @author borisb
5+
*/
6+
public abstract class DemoService {
7+
8+
@Secured("QWERTY")
9+
public abstract Object secureMethod(String firstName, String lastName);
10+
11+
public abstract Object unsecureMethod(String firstName, String lastName);
12+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.xyz;
2+
3+
/**
4+
* @author borisb
5+
*/
6+
public class DemoServiceImpl extends DemoService {
7+
8+
@Override
9+
public Object secureMethod(String firstName, String lastName) {
10+
return "result";
11+
}
12+
13+
@Override
14+
public Object unsecureMethod(String firstName, String lastName) {
15+
return "result2";
16+
}
17+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
package com.xyz;
16+
17+
import java.lang.annotation.*;
18+
19+
/**
20+
* Java 5 annotation for describing service layer security attributes.
21+
* <p/>
22+
* <p>The <code>Secured</code> annotation is used to define a list of security
23+
* configuration attributes for business methods. This annotation can be used
24+
* as a Java 5 alternative to XML configuration.
25+
* <p>For example:
26+
* <pre>
27+
* &#64;Secured ({"ROLE_USER"})
28+
* public void create(Contact contact);
29+
* <p/>
30+
* &#64;Secured ({"ROLE_USER", "ROLE_ADMIN"})
31+
* public void update(Contact contact);
32+
* <p/>
33+
* &#64;Secured ({"ROLE_ADMIN"})
34+
* public void delete(Contact contact);
35+
* </pre>
36+
*
37+
* @author Mark St.Godard
38+
* @version $Id: Secured.java 2217 2007-10-27 00:45:30Z luke_t $
39+
*/
40+
@Target({ElementType.METHOD, ElementType.TYPE})
41+
@Retention(RetentionPolicy.RUNTIME)
42+
@Inherited
43+
@Documented
44+
public @interface Secured {
45+
/**
46+
* Returns the list of security configuration attributes.
47+
* (i.e. ROLE_USER, ROLE_ADMIN etc.)
48+
*
49+
* @return String[] The secure method attributes
50+
*/
51+
public String[] value();
52+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package com.xyz;
2+
3+
import org.apache.log4j.Logger;
4+
import org.aspectj.lang.ProceedingJoinPoint;
5+
import org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint;
6+
import org.springframework.aop.framework.ReflectiveMethodInvocation;
7+
8+
import java.lang.annotation.Annotation;
9+
import java.lang.reflect.Field;
10+
import java.lang.reflect.Method;
11+
12+
/**
13+
* @author borisb
14+
*/
15+
public class TestAspect {
16+
17+
private static final Logger log = Logger.getLogger(TestAspect.class);
18+
19+
public Object invokeNew(ProceedingJoinPoint pjp) throws Throwable {
20+
log.info("aspect invoked");
21+
doWork();
22+
return pjp.proceed();
23+
}
24+
25+
public Object invokeOld(ProceedingJoinPoint pjp) throws Throwable {
26+
log.info("aspect invoked");
27+
Field methodInvocationField = MethodInvocationProceedingJoinPoint.class.getDeclaredField("methodInvocation");
28+
methodInvocationField.setAccessible(true);
29+
ReflectiveMethodInvocation methodInvocation = (ReflectiveMethodInvocation) methodInvocationField.get(pjp);
30+
31+
Field methodField = ReflectiveMethodInvocation.class.getDeclaredField("method");
32+
methodField.setAccessible(true);
33+
Method method = (Method) methodField.get(methodInvocation);
34+
35+
Annotation annotation = method.getAnnotation(Secured.class);
36+
if (annotation != null) {
37+
log.info("do the aspects work");
38+
doWork();
39+
}
40+
return pjp.proceed();
41+
}
42+
43+
private void doWork() throws Exception {
44+
// throw exception to easy check if aspect invoked
45+
throw new Exception("aspect invoked");
46+
}
47+
48+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xmlns:context="http://www.springframework.org/schema/context"
4+
xmlns:aop="http://www.springframework.org/schema/aop"
5+
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
6+
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
7+
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
8+
9+
10+
<bean id="demoService" class="com.xyz.DemoServiceImpl"/>
11+
12+
<bean id="testAspect" class="com.xyz.TestAspect"/>
13+
14+
<aop:aspectj-autoproxy/>
15+
16+
<aop:config>
17+
18+
<aop:aspect ref="testAspect">
19+
<!--<aop:around method="invokeOld" pointcut="execution(* com.xyz.DemoService+.*(..))"/>-->
20+
<!--<aop:around method="invokeNew" pointcut="@annotation(com.xyz.Secured)" />-->
21+
22+
<!--<aop:around method="invokeNew" pointcut="@annotation(com.xyz.Secured)"/>-->
23+
<!--<aop:around method="invokeNew" pointcut="execution(* com.xyz.DemoService+.*(..))"/>-->
24+
<!--<aop:around method="invokeNew"-->
25+
<!--pointcut="execution(* com.xyz.*Service+.*(..)) and @annotation(com.xyz.Secured)"/>-->
26+
27+
<!--<aop:around method="invokeNew"-->
28+
<!--pointcut="execution(@com.xyz.Secured * com.xyz.*Service+.*(..))"/>-->
29+
<aop:around method="invokeNew"
30+
pointcut="execution(@com.xyz.Secured * com.xyz.*Service+.*(..))"/>
31+
32+
</aop:aspect>
33+
</aop:config>
34+
35+
</beans>

SPR-7664/src/main/resources/log4j.xml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<!DOCTYPE log4j:configuration SYSTEM "dtd/log4j.dtd">
3+
<log4j:configuration debug="false" xmlns:log4j='http://jakarta.apache.org/log4j/'>
4+
5+
<appender name="ConsoleAppender" class="org.apache.log4j.ConsoleAppender">
6+
<layout class="org.apache.log4j.PatternLayout">
7+
<param name="ConversionPattern" value="%d{dd MMM yyyy HH:mm:ss:SSS} %p %c{1}:%L %m%n" />
8+
</layout>
9+
</appender>
10+
11+
<logger name="com.xyz" additivity="false">
12+
<level value="debug" />
13+
<appender-ref ref="ConsoleAppender" />
14+
</logger>
15+
<logger name="com.xyz.TestAspect" additivity="false">
16+
<level value="warn" />
17+
<appender-ref ref="ConsoleAppender" />
18+
</logger>
19+
20+
<logger name="org.springframework" additivity="false">
21+
<level value="warn" />
22+
<appender-ref ref="ConsoleAppender" />
23+
</logger>
24+
25+
<root>
26+
<level value="warn" />
27+
<appender-ref ref="ConsoleAppender" />
28+
</root>
29+
30+
</log4j:configuration>
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package com.xyz;
2+
3+
import org.apache.log4j.Logger;
4+
import org.junit.Assert;
5+
import org.junit.Test;
6+
import org.junit.runner.RunWith;
7+
import org.springframework.test.context.ContextConfiguration;
8+
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
9+
10+
import javax.annotation.Resource;
11+
12+
/**
13+
* @author borisb
14+
*/
15+
@ContextConfiguration(locations = {"/applicationContext.xml"})
16+
@RunWith(SpringJUnit4ClassRunner.class)
17+
public class TestClass {
18+
19+
private static final Logger log = Logger.getLogger(TestClass.class);
20+
21+
@Resource(name = "demoService")
22+
private DemoService demoService;
23+
24+
@Test
25+
public void testAspect() {
26+
log.info("@Secured annotated method");
27+
try {
28+
demoService.secureMethod("firstName", "lastName");
29+
Assert.fail("exception not thrown!");
30+
}
31+
catch (Exception e) {
32+
if (e.getCause().getMessage().equals("aspect invoked")) {
33+
log.info("@Secured annotated method invoked");
34+
} else {
35+
Assert.fail("wrong exception thrown!");
36+
}
37+
}
38+
39+
log.info("no annotated method");
40+
try {
41+
demoService.unsecureMethod("firstName", "lastName");
42+
}
43+
catch (Exception e) {
44+
Assert.fail("exception thrown!");
45+
}
46+
}
47+
48+
}

SPR-8122/pom.xml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>org.springframework.issues</groupId>
5+
<artifactId>SPR-8122</artifactId>
6+
<version>1.0-SNAPSHOT</version>
7+
<packaging>jar</packaging>
8+
<dependencies>
9+
<!-- <dependency> -->
10+
<!-- <groupId>org.springframework</groupId> -->
11+
<!-- <artifactId>spring-context</artifactId> -->
12+
<!-- <version>3.2.0.BUILD-SNAPSHOT</version> -->
13+
<!-- </dependency> -->
14+
<dependency>
15+
<groupId>log4j</groupId>
16+
<artifactId>log4j</artifactId>
17+
<version>1.2.16</version>
18+
</dependency>
19+
<dependency>
20+
<groupId>junit</groupId>
21+
<artifactId>junit</artifactId>
22+
<version>4.8</version>
23+
<scope>test</scope>
24+
</dependency>
25+
</dependencies>
26+
<repositories>
27+
<repository>
28+
<id>spring-maven-snapshot</id>
29+
<name>Springframework Maven Snapshot Repository</name>
30+
<url>http://repo.springsource.org/snapshot</url>
31+
<snapshots><enabled>true</enabled></snapshots>
32+
</repository>
33+
</repositories>
34+
<properties>
35+
<project.build.sourceEncoding>UTF8</project.build.sourceEncoding>
36+
</properties>
37+
<build>
38+
<plugins>
39+
<plugin>
40+
<artifactId>maven-compiler-plugin</artifactId>
41+
<version>2.3.2</version>
42+
<configuration>
43+
<source>1.6</source>
44+
<target>1.6</target>
45+
</configuration>
46+
</plugin>
47+
<plugin>
48+
<artifactId>maven-surefire-plugin</artifactId>
49+
<version>2.7.2</version>
50+
<configuration>
51+
<includes>
52+
<include>**/*Tests.java</include>
53+
</includes>
54+
<excludes>
55+
<exclude>**/*Abstract*.java</exclude>
56+
</excludes>
57+
</configuration>
58+
</plugin>
59+
</plugins>
60+
</build>
61+
</project>
62+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package org.springframework.issues;
2+
3+
public class Bar {
4+
5+
}

0 commit comments

Comments
 (0)