From e1264a61d56a82361f8f34d9b5cad33166913151 Mon Sep 17 00:00:00 2001 From: "lucio.lelii" Date: Wed, 17 May 2017 16:15:15 +0000 Subject: [PATCH] git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/Common/authorization-common-library@148810 82a268e6-3cf1-43bd-a215-b396298e98cf --- pom.xml | 64 ++++++++++++++++++- .../library/aspect/AuthorizationAspect.java | 36 +++++++++++ src/main/resources/gcube.authorization | 2 +- 3 files changed, 99 insertions(+), 3 deletions(-) create mode 100644 src/main/java/org/gcube/common/authorization/library/aspect/AuthorizationAspect.java diff --git a/pom.xml b/pom.xml index 0dcf5d2..8db2f29 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 org.gcube.common common-authorization - 2.0.2-SNAPSHOT + 2.1.1-SNAPSHOT authorization service common library @@ -17,7 +17,7 @@ - + org.gcube.core common-scope [1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT) @@ -33,6 +33,11 @@ 4.11 test + + org.aspectj + aspectjrt + 1.8.2 + org.slf4j slf4j-api @@ -41,7 +46,62 @@ + + + + org.eclipse.m2e + lifecycle-mapping + 1.0.0 + + + + + + org.codehaus.mojo + aspectj-maven-plugin + [1.0,) + + test-compile + compile + + + + + + + + + + + + org.codehaus.mojo + aspectj-maven-plugin + 1.7 + + 1.7 + 1.7 + 1.7 + + + + + compile + + + + + + + + + org.codehaus.mojo + aspectj-maven-plugin + + + org.apache.maven.plugins + maven-compiler-plugin + org.apache.maven.plugins maven-resources-plugin diff --git a/src/main/java/org/gcube/common/authorization/library/aspect/AuthorizationAspect.java b/src/main/java/org/gcube/common/authorization/library/aspect/AuthorizationAspect.java new file mode 100644 index 0000000..018b6ea --- /dev/null +++ b/src/main/java/org/gcube/common/authorization/library/aspect/AuthorizationAspect.java @@ -0,0 +1,36 @@ + +package org.gcube.common.authorization.library.aspect; + +import java.lang.reflect.Method; + +import org.aspectj.lang.JoinPoint; +import org.aspectj.lang.annotation.Aspect; +import org.aspectj.lang.annotation.Before; +import org.aspectj.lang.annotation.Pointcut; +import org.aspectj.lang.reflect.MethodSignature; +import org.gcube.common.authorization.library.annotations.AuthorizationControl; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +@Aspect +public class AuthorizationAspect { + + Logger log = LoggerFactory.getLogger(AuthorizationAspect.class); + + @Pointcut("@annotation(org.gcube.common.authorization.library.annotations.AuthorizationControl)") + public void authorizationEntyPoint() { + } + + @Pointcut("execution(* *(..))") + public void atExecution() { + } + + @Before("authorizationEntyPoint() && atExecution()") + public void before(JoinPoint joinPoint) { + MethodSignature signature = (MethodSignature) joinPoint.getSignature(); + Method method = signature.getMethod(); + AuthorizationControl authAnn = (AuthorizationControl) method.getAnnotation(AuthorizationControl.class); + log.info("aspect before with annotation {} and value {} in method {}", authAnn.annotationType(), authAnn.check(), method.getName()); + } + +} diff --git a/src/main/resources/gcube.authorization b/src/main/resources/gcube.authorization index a0918cc..abc8979 100644 --- a/src/main/resources/gcube.authorization +++ b/src/main/resources/gcube.authorization @@ -1 +1 @@ -node7.d.d4science.research-infrastructures.eufalse9000 \ No newline at end of file +auth-d.dev.d4science.orgtrue443 \ No newline at end of file