Annotation that can be used to annotate a CDI bean method that checks
if a matching
PermissionsAllowed
permission with the value()
name can be granted.
For example:
@Path("hello")
public class HelloResource {
@PermissionsAllowed("speak")
@GET
public String sayHello() {
return "Hello World!";
}
@PermissionChecker("speak")
public boolean canSpeak(SecurityIdentity identity) {
return "speaker".equals(identity.getPrincipal().getName());
}
}
The permission checker methods can include any of the secured method parameters, matched by name.
Consider the following secured method:
@PermissionsAllowed("update")
public String updateString(String a, String b, String c, String d) {
...
}
The permission checker that grants access to the updateString
method can include
any of the updateString
method parameters, SecurityIdentity
can also be included:
@PermissionChecker("update")
public boolean canUpdate(String c, String a, SecurityIdentity identity) {
...
}
The permission checker method parameters are matched with the secured method parameters exactly the same way as
the constructor parameters of a custom permission are. Please see PermissionsAllowed.params()
for more information.
If thePermissionsAllowed
annotation lists several permission names and itsPermissionsAllowed.inclusive()
property is set to `true` then an equal number of permission checker methods must be available. Consider the following secured method:For the access to the@PermissionsAllowed(value={"read:all", "write"}, inclusive=true) public String readWriteString(String a) { ... }
readWriteString
method be granted, two permission checkers, one for the `read:all` permission, and another one for the `write` permission, must be available:Note that a permission checker matches one of the@PermissionChecker("read:all") public boolean canRead(SecurityIdentity identity) { ... } @PermissionChecker("write") public boolean canWrite(SecurityIdentity identity) { ... }
PermissionsAllowed
permissions if their String names are equal.
-
Required Element Summary
Required Elements
-
Element Details
-
value
String valueSpecifies a permission this checker grants.- Returns:
- name of the permission this checker grants
- See Also:
-