Search code examples
javaspringaopaspectjspring-aop

AOP vs Spring Security


What the difference between these below...

@org.aspectj.lang.annotation.Aspect
public class Test {
   //@Pointcut, @Around etc etc..
}

And

public aspect Test {

}

And what is the better to use for security among..

  • Spring Security &
  • AOP

in spring app


Solution

  • Check here

    Aspect declarations are supported by the org.aspectj.lang.annotation.Aspect annotation. The declaration:

     @Aspect
     public class Foo {}
    

    Is equivalent to:

     public aspect Foo {}
    

    NOTE: The first one is detected by spring. The later requires AspectJ.

    And for the second question. The comparison is impossible. Because the first one is a framework and the later is a paradigm. Spring security uses AOP to secure method calls, AOP by itself is not a security mechanism. Unless of course, you are going to build your own security using AOP, which is re-inventing the wheel.