From d9c286e5719a445910467c57feed6651e6095a79 Mon Sep 17 00:00:00 2001 From: Abzal Kalimbetov Date: Tue, 19 Aug 2014 23:14:54 +0600 Subject: [PATCH 1/4] Added Spring AOP package. Around pointcut can be used for logging, monitoring and access control check later --- .../aop/DoAroundMethod.java | 39 +++++++++++++++++++ src/main/resources/context.xml | 29 +++++++++++++- src/main/resources/log4j.properties | 2 +- 3 files changed, 68 insertions(+), 2 deletions(-) create mode 100644 src/main/java/net/dontdrinkandroot/example/angularrestspringsecurity/aop/DoAroundMethod.java diff --git a/src/main/java/net/dontdrinkandroot/example/angularrestspringsecurity/aop/DoAroundMethod.java b/src/main/java/net/dontdrinkandroot/example/angularrestspringsecurity/aop/DoAroundMethod.java new file mode 100644 index 0000000..20a38b3 --- /dev/null +++ b/src/main/java/net/dontdrinkandroot/example/angularrestspringsecurity/aop/DoAroundMethod.java @@ -0,0 +1,39 @@ +package net.dontdrinkandroot.example.angularrestspringsecurity.aop; + +import java.util.Arrays; + +import org.aopalliance.intercept.MethodInterceptor; +import org.aopalliance.intercept.MethodInvocation; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class DoAroundMethod implements MethodInterceptor { + private static final Logger LOG = LoggerFactory.getLogger(DoAroundMethod.class); + + public Object invoke(MethodInvocation methodInvocation) throws Throwable { + + LOG.info("****SPRING AOP**** DoAroundMethod: Method name : " + + methodInvocation.getMethod().getName()); + + LOG.info("****SPRING AOP**** DoAroundMethod: Method name : " + + methodInvocation.getMethod().getName()); + LOG.info("****SPRING AOP**** DoAroundMethod: Method arguments : " + + Arrays.toString(methodInvocation.getArguments())); + // same with MethodBeforeAdvice + LOG.info("****SPRING AOP**** DoAroundMethod: Before method executing!"); + + try { + // proceed to original method call + Object result = methodInvocation.proceed(); + // same with AfterReturningAdvice + LOG.info("****SPRING AOP**** DoAroundMethod: After method executing!"); + return result; + + } catch (IllegalArgumentException e) { + // same with ThrowsAdvice + LOG.info("****SPRING AOP**** DoAroundMethod: When method throws Exception!"); + throw e; + } + } + +} \ No newline at end of file diff --git a/src/main/resources/context.xml b/src/main/resources/context.xml index b7a3284..96a7ea9 100644 --- a/src/main/resources/context.xml +++ b/src/main/resources/context.xml @@ -6,13 +6,15 @@ xmlns:util="http://www.springframework.org/schema/util" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:security="http://www.springframework.org/schema/security" + xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.2.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd - http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.2.xsd"> + http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.2.xsd + http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd"> @@ -54,6 +56,31 @@ + + + + + + + .* + + + + + + + + + *Dao + + + + + regexAdvisor + + + diff --git a/src/main/resources/log4j.properties b/src/main/resources/log4j.properties index d448d60..02989cd 100644 --- a/src/main/resources/log4j.properties +++ b/src/main/resources/log4j.properties @@ -4,4 +4,4 @@ log4j.appender.stdout.Target = System.out log4j.appender.stdout.layout = org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern = %d{ABSOLUTE} %3p %c{1}.%M():%L - %m%n -log4j.rootLogger = INFO, stdout \ No newline at end of file +log4j.rootLogger = INFO, stdout, \ No newline at end of file From 6988b8482fcda9aa0aa45c754dd81027fb64df9d Mon Sep 17 00:00:00 2001 From: abzal1991 Date: Wed, 20 Aug 2014 09:11:07 +0600 Subject: [PATCH 2/4] Update log4j.properties --- src/main/resources/log4j.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/log4j.properties b/src/main/resources/log4j.properties index 02989cd..39088dc 100644 --- a/src/main/resources/log4j.properties +++ b/src/main/resources/log4j.properties @@ -4,4 +4,4 @@ log4j.appender.stdout.Target = System.out log4j.appender.stdout.layout = org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern = %d{ABSOLUTE} %3p %c{1}.%M():%L - %m%n -log4j.rootLogger = INFO, stdout, \ No newline at end of file +log4j.rootLogger =INFO, stdout, From 26c9a5ccf21e27c59b71aae43f230bd8536ee978 Mon Sep 17 00:00:00 2001 From: abzal1991 Date: Wed, 20 Aug 2014 09:11:27 +0600 Subject: [PATCH 3/4] Update log4j.properties --- src/main/resources/log4j.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/log4j.properties b/src/main/resources/log4j.properties index 39088dc..be4dd8a 100644 --- a/src/main/resources/log4j.properties +++ b/src/main/resources/log4j.properties @@ -4,4 +4,4 @@ log4j.appender.stdout.Target = System.out log4j.appender.stdout.layout = org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern = %d{ABSOLUTE} %3p %c{1}.%M():%L - %m%n -log4j.rootLogger =INFO, stdout, +log4j.rootLogger = INFO, stdout From c45106dcb4a88ab154c4f3d15d010010b0237074 Mon Sep 17 00:00:00 2001 From: abzal1991 Date: Fri, 26 Sep 2014 11:44:04 +0600 Subject: [PATCH 4/4] Update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6eab094..16a5f40 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ angular-rest-springsecurity =========================== +The difference from master is added Spring AOP example for logging and monitoring. [![Flattr this git repo](http://api.flattr.com/button/flattr-badge-large.png)](https://flattr.com/submit/auto?user_id=shoxrocks&url=http://sorst.net/github/angular-rest-springsecurity&title=AngularJS REST Spring Security Example&language=&tags=github&category=software) @@ -39,4 +40,4 @@ Make sure [Maven](http://maven.apache.org/) >= 2.2.1 is installed on your system License ------- -[The Apache Software License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0.txt) \ No newline at end of file +[The Apache Software License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0.txt)