My use case:
I will have a lot of @PreAuthorize
annotation in the form @PreAuthorize("hasAuthority('RESPECT_MY_AUTHORITY')")
.
I'd like to create a meta-annotation @HasAuthority
which takes the authority as a value and pass it to @PreAuthorize("hasAuthority(<value>)")
.
It feels like it's not possible. The closest I get to what I want is something like the @AliasFor
annotation. but the problem is that I can't add anything to the value I'll get in @HasAuthority
. So I would have to repeat the hasAuthority part everytime.
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@PreAuthorize("hasAuthority('RESPECT_MY_AUTHORITY')")
public @interface HasAuthority {
@AliasFor(annotation = PreAuthorize.class, attribute = "value")
String value();
}
I'd like something like:
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@PreAuthorize("hasAuthority(#value)")
public @interface HasAuthority {
String value();
}
Any idea how I could do that, or if it's possible at all?