diff --git a/core/src/main/java/org/springframework/security/intercept/method/aspectj/AspectJAnnotationCallback.java b/core/src/main/java/org/springframework/security/intercept/method/aspectj/AspectJAnnotationCallback.java new file mode 100644 index 0000000000..0956d2aa7b --- /dev/null +++ b/core/src/main/java/org/springframework/security/intercept/method/aspectj/AspectJAnnotationCallback.java @@ -0,0 +1,16 @@ +package org.springframework.security.intercept.method.aspectj; + + +/** + * Called by the {@link AspectJAnnotationSecurityInterceptor} when it wishes for the + * AspectJ processing to continue. + * + * @author Mike Wiesner + * @version $Id$ + */ + +public interface AspectJAnnotationCallback { + //~ Methods ======================================================================================================== + + Object proceedWithObject(); +} diff --git a/core/src/main/java/org/springframework/security/intercept/method/aspectj/AspectJAnnotationSecurityInterceptor.java b/core/src/main/java/org/springframework/security/intercept/method/aspectj/AspectJAnnotationSecurityInterceptor.java new file mode 100644 index 0000000000..2d044b0330 --- /dev/null +++ b/core/src/main/java/org/springframework/security/intercept/method/aspectj/AspectJAnnotationSecurityInterceptor.java @@ -0,0 +1,61 @@ +package org.springframework.security.intercept.method.aspectj; + +import org.springframework.security.intercept.AbstractSecurityInterceptor; +import org.springframework.security.intercept.InterceptorStatusToken; +import org.springframework.security.intercept.ObjectDefinitionSource; +import org.springframework.security.intercept.method.MethodDefinitionSource; + +import org.aspectj.lang.JoinPoint; + +/** + * AspectJ interceptor that supports @Aspect notation. + * + * @author Mike Wiesner + * @version $Id$ + */ +public class AspectJAnnotationSecurityInterceptor extends AbstractSecurityInterceptor { + //~ Instance fields ================================================================================================ + + private MethodDefinitionSource objectDefinitionSource; + + //~ Methods ======================================================================================================== + + public MethodDefinitionSource getObjectDefinitionSource() { + return this.objectDefinitionSource; + } + + public Class getSecureObjectClass() { + return JoinPoint.class; + } + + /** + * This method should be used to enforce security on a JoinPoint. + * + * @param jp The AspectJ joint point being invoked which requires a security decision + * @param advisorProceed the advice-defined anonymous class that implements AspectJCallback containing + * a simple return proceed(); statement + * + * @return The returned value from the method invocation + */ + public Object invoke(JoinPoint jp, AspectJAnnotationCallback advisorProceed) throws Throwable { + Object result = null; + InterceptorStatusToken token = super.beforeInvocation(jp); + + try { + result = advisorProceed.proceedWithObject(); + } finally { + result = super.afterInvocation(token, result); + } + + return result; + } + + public ObjectDefinitionSource obtainObjectDefinitionSource() { + return this.objectDefinitionSource; + } + + public void setObjectDefinitionSource(MethodDefinitionSource newSource) { + this.objectDefinitionSource = newSource; + } + +}