Groovy Documentation

griffon.plugins.shiro.annotation
[Java] Annotation Type RequiresRoles

java.lang.Object
  griffon.plugins.shiro.annotation.RequiresRoles

@Target({ElementType.TYPE, ElementType.METHOD, ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
public @interface RequiresRoles

Requires the currently executing org.apache.shiro.subject.Subject to have all of the specified roles. If they do not have the role(s), the method will not be executed and an org.apache.shiro.authz.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).

See Also:
org.apache.shiro.subject.Subject#hasRole(String)


Required Element Summary
java.lang.String value

A single String role name or multiple comma-delimitted role names required in order for the method invocation to be allowed.

 
Optional Element Summary
null logical

The logical operation for the permission check in case multiple roles are specified.

 
Method Summary
 
Methods inherited from class Object
wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll
 

Element Detail

logical

public Logical logical
The logical operation for the permission check in case multiple roles are specified. AND is the default @default Logical.AND
Since:
1.1.0


value

public String[] value
A single String role name or multiple comma-delimitted role names required in order for the method invocation to be allowed.


 

Groovy Documentation