Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 544
Mr. Mak Avatar asked Dec 07 '22 20:12

Mr. Mak


2 Answers

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.

like image 153
Amanuel Nega Avatar answered Dec 15 '22 15:12

Amanuel Nega


Marking your class Test with @Aspect annotation will make your class an Aspect, means Spring's ApplicationContext or BeanFactory will now read and scan your class to find advices, pointcuts, joinpoints, you can define your extra cross-cutting functinality (functionality which you keep separate from your business logic) which you want to get executed for some event like before a method call, after a method call, after method throw an exception etc.

AOP (Aspect-oriented programming) is design pattern which spring follows to provide you cross-cutting functionality while Spring Security is a part of complete spring framework, which you can use to secure your application

Spring Security internally uses AOP and Filters to do its work.

like image 41
Naresh Joshi Avatar answered Dec 15 '22 15:12

Naresh Joshi