-
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.
- Loading branch information
1 parent
8e9154b
commit 070b54b
Showing
1 changed file
with
66 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,66 @@ | ||
package io.quarkus.security; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
/** | ||
* Used to annotate CDI bean methods that check if a user holds a permission specified by the {@link #value()}. | ||
* Quarkus Security will augment every {@link io.quarkus.security.identity.SecurityIdentity} with this permission checker. | ||
* Such a permission checker grants access to methods secured with the {@link PermissionsAllowed} security annotation. | ||
* Following example shows how it works: | ||
* <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(); | ||
|
||
} |