@Target(value={TYPE,METHOD}) @Retention(value=RUNTIME) public @interface RequiresRoles
Subject
to have all of the
specified roles. If they do not have the role(s), the method will not be executed and
an AuthorizationException
is thrown.
For example,
@RequiresRoles("aRoleName");
void someMethod();
means someMethod() could only be executed by subjects who have been assigned the
'aRoleName' role.
*Usage Note*: Be careful using this annotation if your application has a dynamic security model where roles can be added and deleted at runtime. If your application allowed the annotated role to be deleted during runtime, the method would not be able to be executed by anyone (at least until a new role with the same name was created again).
If you require such dynamic functionality, only the
RequiresPermissions
annotation makes sense - Permission
types will not change during runtime for an application since permissions directly correspond to how
the application's functionality is programmed (that is, they reflect the application's functionality only, not
who is executing the the functionality).
Subject.hasRole(String)
Copyright © 2004–2016 The Apache Software Foundation. All rights reserved.