├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── pom.xml └── src └── main └── java └── org └── audit4j └── integration └── spring ├── AuditAdvice.java ├── AuditAspect.java ├── AuditAspectOld.java ├── SpringAudit4jConfig.java ├── SpringSecurityWebAuditMetaData.java ├── SpringWebAuditMetadata.java └── WebSessionAuditMetaData.java /.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | 3 | # Package Files # 4 | *.jar 5 | *.war 6 | *.ear 7 | .idea/ 8 | *.iml 9 | *.audit 10 | *.yml 11 | .settings 12 | target 13 | .classpath 14 | .project 15 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # Audit4j build and test via Travis-CI 2 | 3 | language: java 4 | 5 | jdk: 6 | - oraclejdk8 7 | - openjdk7 8 | 9 | script: mvn clean install -DskipTests=true -Dgpg.skip=true 10 | 11 | notifications: 12 | email: 13 | recipients: 14 | - janith@audit4j.org 15 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | audit4j-spring 2 | ============== 3 | Audit4j is an open source auditing framework for Java, Scala and groovy. 4 | 5 | For more information please visit: http://audit4j.org 6 | 7 | For usage, api-guide and development please visit: http://audit4j.org/documentation 8 | 9 | http://audit4j.org/integration-spring 10 | 11 | For contribute, please visit: http://audit4j.org/development 12 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 21 | 4.0.0 22 | org.audit4j 23 | audit4j-spring 24 | jar 25 | Audit4j - Spring Integration 26 | 2.7.0 27 | http://audit4j.org 28 | Audit4j - An open-source auditing framework for Java, Spring Integration 29 | 30 | 31 | Audit4j 32 | http://audit4j.org 33 | 34 | 35 | 36 | 37 | janithb 38 | Janith Bandara 39 | Audit4j 40 | http://audit4j.org 41 | janith@audit4j.org 42 | 43 | Project Administrator 44 | Developer 45 | 46 | +05:30 47 | 48 | 49 | 50 | 51 | 52 | The Apache Software License, Version 2.0 53 | http://www.apache.org/licenses/LICENSE-2.0.txt 54 | repo 55 | 56 | 57 | 58 | 59 | scm:git:git@github.com:audit4j/audit4j-spring.git 60 | scm:git:git@github.com:audit4j/audit4j-spring.git 61 | scm:git:git@github.com:audit4j/audit4j-spring.git 62 | 2.4.0 63 | 64 | 65 | 66 | github 67 | https://github.com/audit4j/audit4j-core/issues 68 | 69 | 70 | 71 | travis-ci 72 | https://travis-ci.org/audit4j/audit4j-spring 73 | 74 | 75 | 76 | 4.11 77 | 2.7.0 78 | 4.2.2.RELEASE 79 | 5.2.10.RELEASE 80 | 1.8.7 81 | 82 | 83 | 84 | 85 | junit 86 | junit 87 | ${junit.version} 88 | test 89 | 90 | 91 | 92 | javax.interceptor 93 | javax.interceptor-api 94 | 1.2 95 | 96 | 97 | 98 | 99 | org.audit4j 100 | audit4j-core 101 | ${audit4j.version} 102 | provided 103 | 104 | 105 | 106 | 107 | org.springframework 108 | spring-aop 109 | ${spring.version} 110 | provided 111 | 112 | 113 | 114 | 115 | org.springframework 116 | spring-web 117 | ${spring.version} 118 | provided 119 | 120 | 121 | 122 | 123 | org.springframework.security 124 | spring-security-web 125 | ${spring.security.version} 126 | provided 127 | 128 | 129 | 130 | 131 | org.aspectj 132 | aspectjrt 133 | ${aspectj.version} 134 | provided 135 | 136 | 137 | 138 | javax.servlet 139 | servlet-api 140 | 2.5 141 | 142 | 143 | 144 | 145 | 146 | 147 | oss.sonatype.org 148 | https://oss.sonatype.org/service/local/staging/deploy/maven2/ 149 | 150 | 151 | oss.sonatype.org 152 | https://oss.sonatype.org/content/repositories/snapshots 153 | 154 | 155 | 156 | 157 | 158 | 159 | org.apache.maven.plugins 160 | maven-compiler-plugin 161 | 162 | 1.8 163 | 1.8 164 | 166 | 167 | -Xlint:varargs 168 | 169 | 170 | 171 | 172 | org.apache.maven.plugins 173 | maven-source-plugin 174 | 2.4 175 | 176 | 177 | attach-sources 178 | 179 | jar 180 | 181 | 182 | 183 | 184 | 185 | org.apache.maven.plugins 186 | maven-javadoc-plugin 187 | 2.10.3 188 | 189 | ${file_encoding} 190 | ${file_encoding} 191 | 192 | 193 | 194 | attach-javadocs 195 | 196 | jar 197 | 198 | 199 | 200 | 201 | 202 | org.apache.maven.plugins 203 | maven-jar-plugin 204 | 205 | 206 | 207 | true 208 | true 209 | 210 | 211 | 212 | 213 | 214 | org.codehaus.mojo 215 | versions-maven-plugin 216 | 2.2 217 | 218 | false 219 | 220 | 221 | 222 | maven-deploy-plugin 223 | 2.8.2 224 | 225 | true 226 | 227 | 228 | 229 | org.sonatype.plugins 230 | nexus-staging-maven-plugin 231 | 1.6.5 232 | true 233 | 234 | oss.sonatype.org 235 | https://oss.sonatype.org/ 236 | ${project.version} 237 | 238 | 239 | 240 | deploy-to-sonatype 241 | deploy 242 | 243 | deploy 244 | release 245 | 246 | 247 | 248 | 249 | 250 | org.apache.maven.plugins 251 | maven-release-plugin 252 | 2.3.2 253 | 254 | @{project.version} 255 | 256 | 257 | 258 | org.apache.maven.plugins 259 | maven-eclipse-plugin 260 | 261 | true 262 | true 263 | 264 | 265 | 266 | org.apache.maven.plugins 267 | maven-surefire-plugin 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | release-sign-artifacts 277 | 278 | 279 | performRelease 280 | true 281 | 282 | 283 | 284 | 285 | 286 | org.apache.maven.plugins 287 | maven-gpg-plugin 288 | 1.6 289 | 290 | 291 | sign-artifacts 292 | verify 293 | 294 | sign 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | org.codehaus.mojo 308 | cobertura-maven-plugin 309 | 2.6 310 | 311 | 312 | org.codehaus.mojo 313 | findbugs-maven-plugin 314 | 3.0.0 315 | 316 | 317 | org.apache.maven.plugins 318 | maven-pmd-plugin 319 | 3.4 320 | 321 | true 322 | utf-8 323 | 100 324 | 1.5 325 | 326 | 327 | 328 | org.apache.maven.plugins 329 | maven-project-info-reports-plugin 330 | 2.6 331 | 332 | 333 | 334 | index 335 | 336 | 337 | 338 | 339 | 340 | org.apache.maven.plugins 341 | maven-javadoc-plugin 342 | 2.9 343 | 344 | 345 | 346 | javadoc 347 | test-javadoc 348 | 349 | 350 | 351 | aggregate 352 | false 353 | 354 | aggregate 355 | 356 | 357 | 358 | 359 | 360 | 361 | -------------------------------------------------------------------------------- /src/main/java/org/audit4j/integration/spring/AuditAdvice.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2016 Janith Bandara, This source is a part of 3 | * Audit4j - An open source auditing framework. 4 | * http://audit4j.org 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.audit4j.integration.spring; 20 | 21 | import java.lang.reflect.Method; 22 | 23 | import org.audit4j.core.AuditManager; 24 | import org.springframework.aop.MethodBeforeAdvice; 25 | 26 | /** 27 | * The Class AuditAdvice. 28 | * 29 | *

30 | * Usage: 31 | *

32 | *
33 |  * {@code
34 |  * 
35 |  * 
36 |  * 
37 |  *      
38 |  * 
39 |  * 
40 |  * 
42 |  *         
43 |  *  
44 |  *         
45 |  *             
46 |  *                 auditAdvice
47 |  *             
48 |  *         
49 |  *   
50 |  * }
51 |  * 
52 | * 53 | * @author Janith Bandara 54 | */ 55 | public class AuditAdvice implements MethodBeforeAdvice { 56 | 57 | 58 | /** 59 | * {@inheritDoc} 60 | * 61 | * @see org.springframework.aop.MethodBeforeAdvice#before(java.lang.reflect.Method, java.lang.Object[], java.lang.Object) 62 | * 63 | */ 64 | @Override 65 | public void before(final Method method, final Object[] params, final Object arg2) throws Throwable { 66 | AuditManager.getInstance().audit(method.getClass(), method, params); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/main/java/org/audit4j/integration/spring/AuditAspect.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2016 Janith Bandara, This source is a part of 3 | * Audit4j - An open source auditing framework. 4 | * http://audit4j.org 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.audit4j.integration.spring; 20 | 21 | import java.lang.reflect.Method; 22 | 23 | import org.aspectj.lang.JoinPoint; 24 | import org.aspectj.lang.annotation.Aspect; 25 | import org.aspectj.lang.annotation.Before; 26 | import org.aspectj.lang.reflect.MethodSignature; 27 | import org.audit4j.core.AuditManager; 28 | import org.audit4j.core.exception.Audit4jRuntimeException; 29 | 30 | /** 31 | * The Class AuditAspect. 32 | * 33 | *
34 |  * {@code
35 |  *  
36 |  *     
37 |  *         ...
38 |  *         
39 |  *     
40 |  *     
41 |  *     
42 |  * 
43 |  * }
44 |  * 
45 | * 46 | * @author Janith Bandara 47 | */ 48 | @Aspect 49 | public class AuditAspect { 50 | 51 | /** 52 | * Audit Aspect. 53 | * 54 | * @param jointPoint 55 | * the joint point 56 | * @throws Throwable 57 | * the throwable 58 | */ 59 | @Before("@within(org.audit4j.core.annotation.Audit) || @annotation(org.audit4j.core.annotation.Audit)") 60 | public void audit(final JoinPoint jointPoint) throws Throwable { 61 | 62 | MethodSignature methodSignature = (MethodSignature) jointPoint.getSignature(); 63 | Method method = methodSignature.getMethod(); 64 | 65 | if (method.getDeclaringClass().isInterface()) { 66 | try { 67 | method = jointPoint.getTarget().getClass() 68 | .getDeclaredMethod(jointPoint.getSignature().getName(), method.getParameterTypes()); 69 | } catch (final SecurityException exception) { 70 | throw new Audit4jRuntimeException( 71 | "Exception occured while proceding Audit Aspect in Audit4j Spring Integration", exception); 72 | } catch (final NoSuchMethodException exception) { 73 | throw new Audit4jRuntimeException( 74 | "Exception occured while proceding Audit Aspect in Audit4j Spring Integration", exception); 75 | } 76 | } 77 | 78 | AuditManager.getInstance().audit(jointPoint.getTarget().getClass(), method, jointPoint.getArgs()); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/main/java/org/audit4j/integration/spring/AuditAspectOld.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2016 Janith Bandara, This source is a part of 3 | * Audit4j - An open source auditing framework. 4 | * http://audit4j.org 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.audit4j.integration.spring; 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 | *

30 | * Configuration: 31 | *

32 | * 33 | *
34 |  * {@code
35 |  * 
36 |  *     
37 |  *         
39 |  *         
40 |  *     
41 |  * 
42 |  * 
43 |  * 
44 |  * }
45 |  * 
46 | * 47 | * @author Janith Bandara 48 | * 49 | * @deprecated 50 | */ 51 | @Deprecated 52 | public class AuditAspectOld { 53 | 54 | /** 55 | * Audit. 56 | * 57 | * @param jointPoint 58 | * the pjp 59 | * 60 | * @throws Throwable 61 | * the throwable 62 | */ 63 | public void audit(final JoinPoint jointPoint) throws Throwable { 64 | MethodSignature methodSignature = (MethodSignature) jointPoint.getSignature(); 65 | Method method = methodSignature.getMethod(); 66 | AuditManager.getInstance().audit(jointPoint.getTarget().getClass(), method, jointPoint.getArgs()); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/main/java/org/audit4j/integration/spring/SpringAudit4jConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2016 Janith Bandara, This source is a part of 3 | * Audit4j - An open source auditing framework. 4 | * http://audit4j.org 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.audit4j.integration.spring; 20 | 21 | import java.util.List; 22 | import java.util.Map; 23 | 24 | import org.audit4j.core.AnnotationTransformer; 25 | import org.audit4j.core.AuditManager; 26 | import org.audit4j.core.Configuration; 27 | import org.audit4j.core.MetaData; 28 | import org.audit4j.core.filter.AuditEventFilter; 29 | import org.audit4j.core.handler.Handler; 30 | import org.audit4j.core.jmx.JMXConfig; 31 | import org.audit4j.core.layout.Layout; 32 | 33 | import org.springframework.beans.factory.DisposableBean; 34 | import org.springframework.beans.factory.InitializingBean; 35 | 36 | /** 37 | * The Class SpringAudit4jConfig. 38 | * 39 | * @author Janith Bandara 40 | */ 41 | public class SpringAudit4jConfig implements InitializingBean, DisposableBean { 42 | 43 | /** The layout. */ 44 | private Layout layout; 45 | 46 | /** The handlers. */ 47 | private List handlers; 48 | 49 | /** The meta data. */ 50 | private MetaData metaData; 51 | 52 | /** The filters. */ 53 | private List filters; 54 | 55 | /** The commands. */ 56 | private String commands; 57 | 58 | /** The jmx. */ 59 | private JMXConfig jmx; 60 | 61 | /** The properties. */ 62 | private Map properties; 63 | 64 | /** The actor session attribute name. */ 65 | private String actorSessionAttributeName; 66 | 67 | /** Transformer to be used when converting event */ 68 | private AnnotationTransformer annotationTransformer; 69 | 70 | /** 71 | * Initialize audit4j when starting spring application context. 72 | * 73 | * {@inheritDoc} 74 | * 75 | * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet() 76 | */ 77 | @Override 78 | public void afterPropertiesSet() throws Exception { 79 | Configuration configuration = Configuration.INSTANCE; 80 | configuration.setLayout(layout); 81 | configuration.setHandlers(handlers); 82 | configuration.setFilters(filters); 83 | configuration.setCommands(commands); 84 | configuration.setJmx(jmx); 85 | configuration.setProperties(properties); 86 | 87 | if (metaData == null) { 88 | if (actorSessionAttributeName == null) { 89 | configuration.setMetaData(new SpringSecurityWebAuditMetaData()); 90 | } else { 91 | configuration.setMetaData(new WebSessionAuditMetaData()); 92 | } 93 | } else { 94 | configuration.setMetaData(metaData); 95 | } 96 | 97 | if (annotationTransformer != null) { 98 | configuration.setAnnotationTransformer(annotationTransformer); 99 | } 100 | 101 | AuditManager.startWithConfiguration(configuration); 102 | } 103 | 104 | /** 105 | * {@inheritDoc} 106 | * 107 | * @see org.springframework.beans.factory.DisposableBean#destroy() 108 | * 109 | */ 110 | @Override 111 | public void destroy() throws Exception { 112 | AuditManager.shutdown(); 113 | } 114 | 115 | /** 116 | * Sets the layout. 117 | * 118 | * @param layout 119 | * the new layout 120 | */ 121 | public void setLayout(Layout layout) { 122 | this.layout = layout; 123 | } 124 | 125 | /** 126 | * Sets the meta data. 127 | * 128 | * @param metaData 129 | * the new meta data 130 | */ 131 | public void setMetaData(MetaData metaData) { 132 | this.metaData = metaData; 133 | } 134 | 135 | /** 136 | * Sets the handlers. 137 | * 138 | * @param handlers 139 | * the new handlers 140 | */ 141 | public void setHandlers(List handlers) { 142 | this.handlers = handlers; 143 | } 144 | 145 | /** 146 | * Sets the filters. 147 | * 148 | * @param filters 149 | * the new filters 150 | */ 151 | public void setFilters(List filters) { 152 | this.filters = filters; 153 | } 154 | 155 | /** 156 | * Sets the commands. 157 | * 158 | * @param commands 159 | * the new commands 160 | */ 161 | public void setCommands(String commands) { 162 | this.commands = commands; 163 | } 164 | 165 | /** 166 | * Sets the jmx. 167 | * 168 | * @param jmx 169 | * the new jmx 170 | */ 171 | public void setJmx(JMXConfig jmx) { 172 | this.jmx = jmx; 173 | } 174 | 175 | /** 176 | * Sets the properties. 177 | * 178 | * @param properties 179 | * the new properties 180 | */ 181 | 182 | public void setProperties(Map properties) { 183 | this.properties = properties; 184 | } 185 | 186 | /** 187 | * Sets the actor session attribute name. 188 | * 189 | * @param actorSessionAttributeName the new actor session attribute name 190 | */ 191 | public void setActorSessionAttributeName(String actorSessionAttributeName) { 192 | this.actorSessionAttributeName = actorSessionAttributeName; 193 | } 194 | 195 | /** 196 | * Sets the tranformer for converting events. May be left {@code null} and then the default transformer will be 197 | * created. 198 | * 199 | * @param annotationTransformer the transformer to be used 200 | */ 201 | public void setAnnotationTransformer(AnnotationTransformer annotationTransformer) { 202 | this.annotationTransformer = annotationTransformer; 203 | } 204 | } 205 | -------------------------------------------------------------------------------- /src/main/java/org/audit4j/integration/spring/SpringSecurityWebAuditMetaData.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2016 Janith Bandara, This source is a part of 3 | * Audit4j - An open source auditing framework. 4 | * http://audit4j.org 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.audit4j.integration.spring; 20 | 21 | import org.springframework.security.core.Authentication; 22 | import org.springframework.security.core.context.SecurityContextHolder; 23 | import org.springframework.security.core.userdetails.UserDetails; 24 | 25 | /** 26 | * Default Metadata class to capture actor and origin information from spring 27 | * application context using Spring security and servlet requests. 28 | * 29 | * @author Janith Bandara 30 | * 31 | * @since 2.4.1 32 | */ 33 | public class SpringSecurityWebAuditMetaData extends SpringWebAuditMetadata { 34 | 35 | /** The Constant serialVersionUID. */ 36 | private static final long serialVersionUID = 7243065407615627372L; 37 | 38 | /** 39 | * {@inheritDoc} 40 | * 41 | * @see org.audit4j.core.MetaData#getActor() 42 | * 43 | */ 44 | @Override 45 | public String getActor() { 46 | Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); 47 | if (authentication != null && authentication.getPrincipal() instanceof UserDetails) { 48 | return ((UserDetails) authentication.getPrincipal()).getUsername(); 49 | } else if (authentication != null && authentication.getPrincipal() instanceof String) { 50 | return (String) authentication.getPrincipal(); 51 | } 52 | return undefienedActorName; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/org/audit4j/integration/spring/SpringWebAuditMetadata.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2016 Janith Bandara, This source is a part of 3 | * Audit4j - An open source auditing framework. 4 | * http://audit4j.org 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.audit4j.integration.spring; 20 | 21 | import javax.servlet.ServletRequest; 22 | 23 | import org.audit4j.core.MetaData; 24 | import org.audit4j.core.util.annotation.Beeta; 25 | import org.springframework.web.context.request.RequestContextHolder; 26 | import org.springframework.web.context.request.ServletRequestAttributes; 27 | 28 | /** 29 | * Abstraction for Spring metadata implementations. 30 | * 31 | * @author Janith Bandara 32 | * 33 | * @since 2.4.1 34 | */ 35 | @Beeta 36 | public abstract class SpringWebAuditMetadata implements MetaData { 37 | 38 | /** default actor name for unidentified actor. */ 39 | protected String undefienedActorName = "unedentified"; 40 | 41 | /** Default name for unidentified origin. */ 42 | protected String undefienedOriginName = "unedentified"; 43 | 44 | /** 45 | * {@inheritDoc} 46 | * 47 | * @see org.audit4j.core.MetaData#getOrigin() 48 | * 49 | */ 50 | @Override 51 | public String getOrigin() { 52 | try { 53 | return ((ServletRequest) ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()) 54 | .getRequest()).getRemoteAddr(); 55 | } catch (Exception e) { 56 | e.printStackTrace(); 57 | } 58 | return undefienedOriginName; 59 | } 60 | 61 | /** 62 | * Allows to set the undefined actor name. 63 | * 64 | * @param undefinedActorName 65 | * the new undefined actor name 66 | */ 67 | public void setUndefienedActorName(String undefinedActorName) { 68 | this.undefienedActorName = undefinedActorName; 69 | } 70 | 71 | /** 72 | * Allows to set the undefined origin name. 73 | * 74 | * @param undefinedOriginName 75 | * the new undefined origin name 76 | */ 77 | public void setUndefienedOriginName(String undefinedOriginName) { 78 | this.undefienedOriginName = undefinedOriginName; 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/main/java/org/audit4j/integration/spring/WebSessionAuditMetaData.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2014-2016 Janith Bandara, This source is a part of 3 | * Audit4j - An open source auditing framework. 4 | * http://audit4j.org 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package org.audit4j.integration.spring; 19 | 20 | import org.audit4j.core.util.annotation.Beeta; 21 | import org.springframework.web.context.request.RequestAttributes; 22 | import org.springframework.web.context.request.RequestContextHolder; 23 | 24 | /** 25 | * Default Metadata class to capture actor and origin information from spring 26 | * application context using session attributes and servlet requests. 27 | * 28 | * @author Janith Bandara 29 | * 30 | * @since 2.4.1 31 | */ 32 | @Beeta 33 | public class WebSessionAuditMetaData extends SpringWebAuditMetadata { 34 | 35 | /** The Constant serialVersionUID. */ 36 | private static final long serialVersionUID = -8565254148203328955L; 37 | 38 | /** default session attribute name. */ 39 | private String actorSessionAttribute = "userName"; 40 | 41 | /** 42 | * {@inheritDoc} 43 | * 44 | * @see org.audit4j.core.MetaData#getActor() 45 | * 46 | */ 47 | @Override 48 | public String getActor() { 49 | String actor = (String) RequestContextHolder.currentRequestAttributes() 50 | .getAttribute(actorSessionAttribute, RequestAttributes.SCOPE_SESSION); 51 | if (actor != null) { 52 | return actor; 53 | } 54 | return undefienedActorName; 55 | } 56 | 57 | /** 58 | * Sets the actor session attribute. 59 | * 60 | * @param actorSessionAttribute 61 | * the new actor session attribute 62 | */ 63 | public void setActorSessionAttribute(String actorSessionAttribute) { 64 | this.actorSessionAttribute = actorSessionAttribute; 65 | } 66 | } 67 | --------------------------------------------------------------------------------