I have the following problem:
I have create annotation for Security:
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD, ElementType.TYPE})
@Inherited
@Documented
public @interface Security {
Role[] roles();
}
I am now annotating classes and methods with this annotation. In some cases the class is annotated with this annotation and specific method within this class is also annotated with @Security with different roles.
How can create @Before advice that will catch either methods annotated with @Security ot methods within classes annotated with @Security, and also to get the more specific definition in case there are annotation on both the class and method.
I obviously need also the content of the annotation as well (the roles).
Is it possible?
Is it also possible in cases that I have inhertience between classes that all of them have the @Security annotation to get the most specific definition?
Yosi
This should work (native AspectJ code, but you can translate to @Aspect if you prefer that):