Added aspect to intercept method execution which needs authentication

parent 07b92a47
...@@ -251,6 +251,26 @@ ...@@ -251,6 +251,26 @@
<artifactId>jackson-databind</artifactId> <artifactId>jackson-databind</artifactId>
<version>2.0.6</version> <version>2.0.6</version>
</dependency> </dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.7.1</version>
</dependency>
<dependency>
<groupId>aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.5.4</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
<version>${org.springframework-version}</version>
</dependency>
</dependencies> </dependencies>
<build> <build>
<plugins> <plugins>
......
package de.thm.arsnova.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface Authenticated {
}
package de.thm.arsnova.aop;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import de.thm.arsnova.annotation.Authenticated;
@Aspect
public class AuthorizationAdviser {
@Pointcut("execution(public * de.thm.arsnova.services.*.*(..))")
public void serviceMethods() {}
@Autowired
@Before("serviceMethods() && @annotation(authenticated) && this(object)")
public void check(Authenticated authenticated, Object object) {
System.out.println("******************************: " + object.getClass().getName());
}
}
...@@ -33,6 +33,7 @@ import org.springframework.stereotype.Service; ...@@ -33,6 +33,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation; import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import de.thm.arsnova.annotation.Authenticated;
import de.thm.arsnova.dao.IDatabaseDao; import de.thm.arsnova.dao.IDatabaseDao;
import de.thm.arsnova.entities.Feedback; import de.thm.arsnova.entities.Feedback;
import de.thm.arsnova.entities.Session; import de.thm.arsnova.entities.Session;
...@@ -68,16 +69,19 @@ public class SessionService implements ISessionService { ...@@ -68,16 +69,19 @@ public class SessionService implements ISessionService {
} }
@Override @Override
@Authenticated
public Session getSession(String keyword) { public Session getSession(String keyword) {
return databaseDao.getSession(keyword); return databaseDao.getSession(keyword);
} }
@Override @Override
@Authenticated
public Session saveSession(Session session) { public Session saveSession(Session session) {
return databaseDao.saveSession(session); return databaseDao.saveSession(session);
} }
@Override @Override
@Authenticated
public Feedback getFeedback(String keyword) { public Feedback getFeedback(String keyword) {
return databaseDao.getFeedback(keyword); return databaseDao.getFeedback(keyword);
} }
......
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" <beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p" xmlns:util="http://www.springframework.org/schema/util" xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:task="http://www.springframework.org/schema/task" xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd xmlns:util="http://www.springframework.org/schema/util"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:task="http://www.springframework.org/schema/task"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.1.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.1.xsd">
<aop:aspectj-autoproxy />
<bean id="propertyPlaceholderConfigurer" <bean id="propertyPlaceholderConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment