Is it correct to put @Secured
annotations on interface methods or on methods within classes implementing the interface? Are there any recommendations for this?
When I dig into the class defining the @Secured
annotation, I can see that it has the @Inherited
annotation set:
@Target({ ElementType.METHOD, ElementType.TYPE })
@Retention(RetentionPolicy.RUNTIME)
@Inherited
@Documented
public @interface Secured {
/**
* Returns the list of security configuration attributes (e.g. ROLE_USER, ROLE_ADMIN).
*
* @return String[] The secure method attributes
*/
public String[]value();
}
Having read this answer, I guess I can set the @Secured
annotation on the interface to consistently enforce authorization over all implementations of the interface.