Skip to content

Added Spring AOP support. #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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)

Expand Down Expand Up @@ -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)
[The Apache Software License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0.txt)
Original file line number Diff line number Diff line change
@@ -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;
}
}

}
29 changes: 28 additions & 1 deletion src/main/resources/context.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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">

<context:annotation-config />

Expand Down Expand Up @@ -54,6 +56,31 @@
<constructor-arg ref="newsEntryDao" />
<constructor-arg ref="passwordEncoder" />
</bean>

<bean id="doAroundMethodBean" class="net.dontdrinkandroot.example.angularrestspringsecurity.aop.DoAroundMethod" />

<bean id="regexAdvisor"
class="org.springframework.aop.support.RegexpMethodPointcutAdvisor">
<property name="patterns">
<list>
<value>.*</value>
</list>
</property>
<property name="advice" ref="doAroundMethodBean" />
</bean>

<bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<property name="beanNames">
<list>
<value>*Dao</value>
</list>
</property>
<property name="interceptorNames">
<list>
<value>regexAdvisor</value>
</list>
</property>
</bean>

<tx:annotation-driven transaction-manager="transactionManager" />

Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/log4j.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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