Skip to content

Commit ba78ea4

Browse files
committed
Fix issue: audit aspect sending wrong target
1 parent c7adb5f commit ba78ea4

File tree

7 files changed

+145
-108
lines changed

7 files changed

+145
-108
lines changed

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,12 @@
44
*.jar
55
*.war
66
*.ear
7+
.idea/
8+
*.iml
9+
*.audit
10+
*.yml
11+
.settings
12+
target
13+
.classpath
14+
.project
15+

pom.xml

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
<artifactId>audit4j-spring</artifactId>
66
<packaging>jar</packaging>
77
<name>Audit4j - Spring Integration</name>
8-
<version>1.0.0</version>
9-
<url>http://www.mechanizedspace.com/audit4j</url>
10-
<description>Audit4j - An open-source audit suit for enterprise java platform, Spring Integration</description>
8+
<version>2.3.1</version>
9+
<url>http://audit4j.org</url>
10+
<description>Audit4j - An open-source auditing framework for Java, Spring Integration</description>
1111
<organization>
1212
<name>Audit4j</name>
13-
<url>http://www.mechanizedspace.com/audit4j</url>
13+
<url>http://audit4j.org</url>
1414
</organization>
1515
<licenses>
1616
<license>
@@ -19,23 +19,28 @@
1919
<distribution>repo</distribution>
2020
</license>
2121
</licenses>
22+
<issueManagement>
23+
<system>mantis</system>
24+
<url>http://audit4j.org/bugs</url>
25+
</issueManagement>
2226
<scm>
23-
<connection>scm:git:[email protected]:audit4j/audit4j-core.git</connection>
24-
<developerConnection>scm:git:[email protected]:audit4j/audit4j-core.git</developerConnection>
25-
<url>scm:git:[email protected]:audit4j/audit4j-core.git</url>
26-
<tag>1.0.0</tag>
27+
<connection>scm:git:[email protected]:audit4j/audit4j-spring.git</connection>
28+
<developerConnection>scm:git:[email protected]:audit4j/audit4j-spring.git</developerConnection>
29+
<url>scm:git:[email protected]:audit4j/audit4j-spring.git</url>
30+
<tag>2.2.0</tag>
2731
</scm>
2832
<developers>
2933
<developer>
3034
<id>janith</id>
3135
<name>Janith Bandara</name>
3236
<organization>Audit4j</organization>
33-
<organizationUrl>http://www.mechanizedspace.com/audit4j</organizationUrl>
37+
<organizationUrl>http://audit4j.org</organizationUrl>
38+
<email>[email protected]</email>
3439
<roles>
3540
<role>owner</role>
3641
<role>developer</role>
3742
</roles>
38-
<timezone>0</timezone>
43+
<timezone>+05:30</timezone>
3944
</developer>
4045
</developers>
4146

@@ -46,37 +51,40 @@
4651
</parent>
4752

4853
<properties>
49-
<spring.version>3.0.5.RELEASE</spring.version>
50-
<aspectj.version>1.6.11</aspectj.version>
54+
<junit.version>4.11</junit.version>
55+
<audit4j.version>2.3.1</audit4j.version>
56+
<spring.version>4.1.4.RELEASE</spring.version>
5157
</properties>
5258

5359
<dependencies>
5460
<dependency>
5561
<groupId>junit</groupId>
5662
<artifactId>junit</artifactId>
57-
<version>4.11</version>
63+
<version>${junit.version}</version>
64+
<scope>test</scope>
5865
</dependency>
5966

67+
<!-- Audit4j Core -->
6068
<dependency>
6169
<groupId>org.audit4j</groupId>
6270
<artifactId>audit4j-core</artifactId>
63-
<version>1.0.0</version>
71+
<version>${audit4j.version}</version>
72+
<scope>provided</scope>
6473
</dependency>
65-
<!-- Spring AOP + AspectJ -->
74+
75+
<!-- Spring AOP -->
6676
<dependency>
6777
<groupId>org.springframework</groupId>
6878
<artifactId>spring-aop</artifactId>
6979
<version>${spring.version}</version>
80+
<scope>provided</scope>
7081
</dependency>
82+
83+
<!-- Aspect J -->
7184
<dependency>
7285
<groupId>org.aspectj</groupId>
7386
<artifactId>aspectjrt</artifactId>
74-
<version>${aspectj.version}</version>
75-
</dependency>
76-
<dependency>
77-
<groupId>org.aspectj</groupId>
78-
<artifactId>aspectjweaver</artifactId>
79-
<version>${aspectj.version}</version>
87+
<version>1.8.5</version>
8088
</dependency>
8189
</dependencies>
8290

@@ -87,7 +95,6 @@
8795
<groupId>org.apache.maven.plugins</groupId>
8896
<artifactId>maven-compiler-plugin</artifactId>
8997
<configuration>
90-
<!-- or whatever version you use -->
9198
<source>1.7</source>
9299
<target>1.7</target>
93100
</configuration>

src/main/java/org/audit4j/integration/spring/AuditAdvice.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,8 @@
2828
* The Class AuditAdvice.
2929
*
3030
* <p>
31-
* </p>
3231
* Usage:
33-
*
32+
* </p>
3433
* <pre>
3534
* {@code
3635
* <bean id="auditAdvice" class="org.audit4j.integration.spring.AuditAdvice" />
@@ -64,8 +63,8 @@ public class AuditAdvice implements MethodBeforeAdvice {
6463
* , java.lang.Object[], java.lang.Object)
6564
*/
6665
@Override
67-
public void before(final Method method, final Object[] arg1, final Object arg2) throws Throwable {
66+
public void before(final Method method, final Object[] params, final Object arg2) throws Throwable {
6867
AuditManager manager = AuditManager.getInstance();
69-
manager.audit(method.getClass(), method, arg1);
68+
manager.audit(method.getClass(), method, params);
7069
}
7170
}
Lines changed: 36 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,62 @@
11
package org.audit4j.integration.spring;
22

3-
/*
4-
* Copyright (c) 2014-2015 Janith Bandara, This source is a part of
5-
* Audit4j - An open source auditing framework.
6-
* http://audit4j.org
7-
*
8-
* Licensed under the Apache License, Version 2.0 (the "License");
9-
* you may not use this file except in compliance with the License.
10-
* You may obtain a copy of the License at
11-
*
12-
* http://www.apache.org/licenses/LICENSE-2.0
13-
*
14-
* Unless required by applicable law or agreed to in writing, software
15-
* distributed under the License is distributed on an "AS IS" BASIS,
16-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17-
* See the License for the specific language governing permissions and
18-
* limitations under the License.
19-
*/
20-
213
import java.lang.reflect.Method;
224

235
import org.aspectj.lang.JoinPoint;
6+
import org.aspectj.lang.annotation.Aspect;
7+
import org.aspectj.lang.annotation.Before;
8+
import org.aspectj.lang.annotation.Pointcut;
249
import org.aspectj.lang.reflect.MethodSignature;
2510
import org.audit4j.core.AuditManager;
2611

2712
/**
2813
* The Class AuditAspect.
29-
* <p>
30-
* Configuration:
31-
* </p>
3214
*
3315
* <pre>
3416
* {@code
35-
* <aop:config>
36-
* <aop:aspect id="audit" ref="auditAspect">
37-
* <aop:pointcut id="packages"
38-
* expression="execution(* com.xyz.myapp.service.*.*(..))" />
39-
* <aop:before pointcut-ref="packages" method="audit" />
40-
* </aop:aspect>
41-
* </aop:config>
17+
*
18+
* <aop:aspectj-autoproxy>
19+
* ...
20+
* <aop:include name="auditAspect"/>
21+
* </aop:aspectj-autoproxy>
22+
*
23+
* <bean id="auditAspect" class="org.audit4j.integration.spring.AuditAspect" />
4224
*
43-
* <bean id="auditAspect" class="org.audit4j.integration.spring.AuditAspect"/>
4425
* }
4526
* </pre>
4627
*
4728
* @author <a href="mailto:[email protected]">Janith Bandara</a>
4829
*/
30+
@Aspect
4931
public class AuditAspect {
5032

5133
/**
52-
* Audit.
53-
*
54-
* @param jointPoint the pjp
55-
* @return the object
56-
* @throws Throwable the throwable
34+
* Execute public method.
35+
*/
36+
@Pointcut("execution(@org.audit4j.core.annotation.Audit * *(..))")
37+
public void executeAuditMethod() {
38+
}
39+
40+
/**
41+
* Execute audit class.
42+
*/
43+
@Pointcut("within(@org.audit4j.core.annotation.Audit *)")
44+
public void executeAuditClass() {
45+
}
46+
47+
/**
48+
* Audit Aspect
49+
*
50+
* @param pjp
51+
* the pjp
52+
*
53+
* @throws Throwable
54+
* the throwable
5755
*/
58-
public void audit (final JoinPoint jointPoint) throws Throwable {
59-
AuditManager manager = AuditManager.getInstance();
60-
Class<?> clazz = jointPoint.getClass();
61-
MethodSignature methodSignature = (MethodSignature) jointPoint.getSignature();
56+
@Before("executeAuditMethod() || executeAuditClass()")
57+
public void audit(final JoinPoint pjp) throws Throwable {
58+
MethodSignature methodSignature = (MethodSignature) pjp.getSignature();
6259
Method method = methodSignature.getMethod();
63-
manager.audit(clazz, method, jointPoint.getArgs());
60+
AuditManager.getInstance().audit(pjp.getTarget().getClass(), method, pjp.getArgs());
6461
}
6562
}

src/main/java/org/audit4j/integration/spring/AuditAspect2.java

Lines changed: 0 additions & 41 deletions
This file was deleted.
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package org.audit4j.integration.spring;
2+
3+
/*
4+
* Copyright (c) 2014-2015 Janith Bandara, This source is a part of
5+
* Audit4j - An open source auditing framework.
6+
* http://audit4j.org
7+
*
8+
* Licensed under the Apache License, Version 2.0 (the "License");
9+
* you may not use this file except in compliance with the License.
10+
* You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing, software
15+
* distributed under the License is distributed on an "AS IS" BASIS,
16+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
* See the License for the specific language governing permissions and
18+
* limitations under the License.
19+
*/
20+
21+
import java.lang.reflect.Method;
22+
23+
import org.aspectj.lang.JoinPoint;
24+
import org.aspectj.lang.reflect.MethodSignature;
25+
import org.audit4j.core.AuditManager;
26+
27+
/**
28+
* The Class AuditAspect.
29+
* <p>
30+
* Configuration:
31+
* </p>
32+
*
33+
* <pre>
34+
* {@code
35+
* <aop:config>
36+
* <aop:aspect id="audit" ref="auditAspect">
37+
* <aop:pointcut id="packages"
38+
* expression="execution(* com.xyz.myapp.service.*.*(..))" />
39+
* <aop:before pointcut-ref="packages" method="audit" />
40+
* </aop:aspect>
41+
* </aop:config>
42+
*
43+
* <bean id="auditAspect" class="org.audit4j.integration.spring.AuditAspect"/>
44+
* }
45+
* </pre>
46+
*
47+
* @author <a href="mailto:[email protected]">Janith Bandara</a>
48+
*
49+
* @deprecated
50+
*/
51+
@Deprecated
52+
public class AuditAspectOld {
53+
54+
/**
55+
* Audit.
56+
*
57+
* @param jointPoint the pjp
58+
*
59+
* @throws Throwable the throwable
60+
*/
61+
public void audit (final JoinPoint jointPoint) throws Throwable {
62+
MethodSignature methodSignature = (MethodSignature) jointPoint.getSignature();
63+
Method method = methodSignature.getMethod();
64+
AuditManager.getInstance().audit(jointPoint.getTarget().getClass(), method, jointPoint.getArgs());
65+
}
66+
}

src/main/java/org/audit4j/integration/spring/SpringAudit4jConfig.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@ public class SpringAudit4jConfig implements InitializingBean, DisposableBean {
5656
*/
5757
@Override
5858
public void afterPropertiesSet() throws Exception {
59-
Configuration configuration = new Configuration();
59+
Configuration configuration = Configuration.INSTANCE;
6060
configuration.setLayout(layout);
6161
configuration.setHandlers(handlers);
6262
configuration.setMetaData(metaData);
6363
configuration.setFilters(filters);
6464
configuration.setOptions(options);
65-
AuditManager.getConfigurationInstance(configuration);
65+
AuditManager.startWithConfiguration(configuration);
6666
}
6767

6868
/* (non-Javadoc)

0 commit comments

Comments
 (0)