In my project I use pre-defined annotation @With
:
@With(Secure.class)
public class Test { //....
The source code of @Wit
You can use annotation for annotation like this:
@Target({ElementType.METHOD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Inherited
@Documented
@WithSecurityContext(factory = WithCustomUserSecurityContextFactory.class)
public @interface WithCustomUser {
String username() default "demo@demo.com";
String password() default "demo";
String[] authorities() default {Authority.USER};
}
And define exact state in its "child"
@Target({ElementType.METHOD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Inherited
@Documented
@WithCustomUser(username = "admin@admin.com",
password = "admin",
authorities = {Authority.USER, Authority.ADMINISTRATOR})
public @interface WithAdminUser {
}
In this case you have a some kind of "state" and access to the parent annotation fields via reflection/aspect.