-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add @permissionchecker security annotation
- Loading branch information
1 parent
8e9154b
commit 995167d
Showing
1 changed file
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package io.quarkus.security; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
/** | ||
* Annotation that can be used to annotate a CDI bean method that checks | ||
* if a {@link io.quarkus.security.identity.SecurityIdentity} holds a permission specified by the {@link #value()}. | ||
* For example: | ||
* <pre> | ||
* {@code | ||
* @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()); | ||
* } | ||
* } | ||
* } | ||
* </pre> | ||
* The permission checker methods can include any of secured method parameters (matched by name). | ||
* Consider the following secured method: | ||
* <pre> | ||
* {@code | ||
* @PermissionsAllowed("update") | ||
* public String updateString(String a, String b, String c, String d) { | ||
* ... | ||
* } | ||
* } | ||
* </pre> | ||
* The permission checker that grants access to the {@code updateString} method can inject | ||
* any arguments it requires and optionally even {@link io.quarkus.security.identity.SecurityIdentity}: | ||
* <pre> | ||
* {@code | ||
* @PermissionChecker("update") | ||
* public boolean canUpdate(String c, String a, SecurityIdentity identity) { | ||
* ... | ||
* } | ||
* } | ||
* </pre> | ||
* The permission checker method parameters are matched with the secured method parameters in exactly same fashion | ||
* as are constructor parameters of a custom permission. Please see {@link PermissionsAllowed#params()} for more information. | ||
*/ | ||
@Target(ElementType.METHOD) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface PermissionChecker { | ||
|
||
/** | ||
* Specifies a permission this checker grants. | ||
* | ||
* @see PermissionsAllowed#value() | ||
* @return name of the permission this checker grants | ||
*/ | ||
String value(); | ||
|
||
} |