|
9 | 9 | import java.security.Permission;
|
10 | 10 |
|
11 | 11 | /**
|
12 |
| - * Indicates that a resource can only be accessed by a user with one of permissions specified through {@link #value()}. |
13 |
| - * There are some situations where you want to require more than one permission, this can be achieved by repeating |
14 |
| - * annotation. Please see an example below: |
15 |
| - * |
16 |
| - * <pre> |
17 |
| - * @PermissionsAllowed("create") |
18 |
| - * @PermissionsAllowed("update") |
19 |
| - * public Resource createOrUpdate(Long id) { |
20 |
| - * // business logic |
21 |
| - * } |
22 |
| - * </pre> |
23 |
| - * |
24 |
| - * To put it another way, permissions specified by one annotation instance are disjunctive and the permission check is |
25 |
| - * only true if all annotation instances are evaluated as true. |
| 12 | + * Lists one or more required permissions that must be granted. |
26 | 13 | */
|
27 | 14 | @Documented
|
28 | 15 | @Retention(RetentionPolicy.RUNTIME)
|
|
32 | 19 |
|
33 | 20 | /**
|
34 | 21 | * Constant value for {@link #params()} indicating that the constructor parameters of the {@link #permission()}
|
35 |
| - * should be autodetected based on formal parameter names. For example, consider following method secured with this |
| 22 | + * should be autodetected based on formal parameter names. For example, consider the following method secured with this |
36 | 23 | * annotation:
|
37 | 24 | * <pre>
|
38 | 25 | * {@code
|
|
81 | 68 |
|
82 | 69 | /**
|
83 | 70 | * Colon is used to separate a {@link Permission#getName()} and an element of the {@link Permission#getActions()}.
|
84 |
| - * For example, {@link StringPermission} created for method 'getResource': |
| 71 | + * For example, {@link StringPermission} created for the 'getResource' method: |
85 | 72 | *
|
86 | 73 | * <pre>
|
87 | 74 | * @PermissionsAllowed("resource:retrieve")
|
|
97 | 84 | String PERMISSION_TO_ACTION_SEPARATOR = ":";
|
98 | 85 |
|
99 | 86 | /**
|
100 |
| - * Specifies a list of permissions that grants the access to the resource. It is also possible to define permission's |
101 |
| - * actions that are permitted for the resource. Yet again, consider method 'getResource': |
| 87 | + * Specifies a list of permissions that grants access to the resource. |
| 88 | + * It is also possible to define permission actions that are permitted for the resource. |
| 89 | + * Consider the `getResource` method: |
102 | 90 | *
|
103 | 91 | * <pre>
|
104 | 92 | * @PermissionsAllowed({"resource:crud", "resource:retrieve", "system-resource:retrieve"})
|
|
107 | 95 | * }
|
108 | 96 | * </pre>
|
109 | 97 | *
|
110 |
| - * Two {@link StringPermission}s will be created: |
| 98 | + * Two {@link StringPermission} permissions will be created: |
111 | 99 | *
|
112 | 100 | * <pre>
|
113 | 101 | * var pem1 = new StringPermission("resource", "crud", "retrieve");
|
114 | 102 | * var pem2 = new StringPermission("system-resource", "retrieve");
|
115 | 103 | * </pre>
|
116 | 104 | *
|
117 |
| - * And the permission check will pass if either {@code pem1} or {@code pem2} implies user permissions. |
118 |
| - * Technically, it is also possible to both define actions and no action for same-named permission like this: |
| 105 | + * The permission check will pass if either {@code pem1} or {@code pem2} implies user permissions. |
| 106 | + * It is also possible to combine permissions with and without actions like this: |
119 | 107 | *
|
120 | 108 | * <pre>
|
121 | 109 | * @PermissionsAllowed({"resource:crud", "resource:retrieve", "natural-resource"})
|
|
130 | 118 | * var pem1 = new StringPermission("resource", "crud", "retrieve");
|
131 | 119 | * var pem2 = new StringPermission("natural-resource");
|
132 | 120 | * </pre>
|
| 121 | + * Alternatively, when multiple required permissions must be listed, you can repeat the annotation, for example: |
| 122 | + * <pre> |
| 123 | + * @PermissionsAllowed("create") |
| 124 | + * @PermissionsAllowed("update") |
| 125 | + * public Resource createOrUpdate(Long id) { |
| 126 | + // business logic |
| 127 | + * } |
| 128 | + * </pre> |
133 | 129 | *
|
134 |
| - * To see how the example above is evaluated, please see "implies" method of your {@link #permission()}. |
135 |
| - * |
136 |
| - * @see StringPermission#implies(Permission) for more details on how above-mentioned example is evaluated |
| 130 | + * @see StringPermission#implies(Permission) for more details on how the above example is evaluated. |
137 | 131 | *
|
138 |
| - * @return permissions linked to respective actions |
| 132 | + * @return permissions |
139 | 133 | */
|
140 | 134 | String[] value();
|
141 | 135 |
|
142 | 136 | /**
|
143 |
| - * Choose a relation between permissions specified via {@link #value()}. By default, at least one of permissions |
144 |
| - * is required (please see the example above). You can require all of them by setting `inclusive` to `true`. |
145 |
| - * Let's re-use same example and make permissions inclusive: |
| 137 | + * Choose a relation between multiple permissions specified in {@link #value()}. |
| 138 | + * By default, at least one of permissions must be granted. |
| 139 | + * You can request that all of the listed permissions by setting the `inclusive` property to `true`. |
| 140 | + * For example: |
146 | 141 | *
|
147 | 142 | * <pre>
|
148 | 143 | * @PermissionsAllowed(value = {"resource:crud", "resource:retrieve", "natural-resource"}, inclusive = true)
|
|
158 | 153 | * var pem2 = new StringPermission("system-resource", "retrieve");
|
159 | 154 | * </pre>
|
160 | 155 | *
|
161 |
| - * And the permission check will pass if <b>both</b> {@code pem1} and {@code pem2} implies user permissions. |
| 156 | + * And the permission check will pass if <b>both</b> {@code pem1} and {@code pem2} imply user permissions. |
162 | 157 | *
|
163 | 158 | * @return `true` if permissions should be inclusive
|
164 | 159 | */
|
165 | 160 | boolean inclusive() default false;
|
166 | 161 |
|
167 | 162 | /**
|
168 | 163 | * Mark parameters of the annotated method that should be passed to the constructor of the {@link #permission()}.
|
169 |
| - * First, let's define ourselves three classes: |
| 164 | + * Consider the following three classes: |
170 | 165 | *
|
171 | 166 | * <pre>
|
172 | 167 | * class ResourceIdentity { }
|
173 | 168 | * class User extends ResourceIdentity { }
|
174 | 169 | * class Admin extends ResourceIdentity { }
|
175 | 170 | * </pre>
|
176 | 171 | *
|
177 |
| - * Now that we have defined parameter data types, please consider the secured method 'getResource': |
| 172 | + * Next, consider the secured 'getResource' method: |
178 | 173 | *
|
179 | 174 | * <pre>
|
180 | 175 | * @PermissionsAllowed(permission = UserPermission.class, value = "resource", params = {user1, admin1})
|
|
183 | 178 | * }
|
184 | 179 | * </pre>
|
185 | 180 | *
|
186 |
| - * In the example above, we marked parameters {@code user1} and {@code admin1} as {@link #permission()} constructor |
| 181 | + * In the example above, the parameters {@code user1} and {@code admin1} are marked as {@link #permission()} constructor |
187 | 182 | * arguments:
|
188 | 183 | *
|
189 | 184 | * <pre>
|
|
202 | 197 | * }
|
203 | 198 | * </pre>
|
204 | 199 | *
|
205 |
| - * Please mention that: |
| 200 | + * Please note that: |
206 | 201 | * <ul>
|
207 |
| - * <li>constructor parameter names {@code user1} and {@code admin1} must exactly match respective "params",</li> |
208 |
| - * <li>"ResourceIdentity" could be used as constructor parameter data type, for "User" and "Admin" are assignable |
209 |
| - * from "ResourceIdentity",</li> |
210 |
| - * <li>"getResource" parameters {@code user} and {@code admin} are not passed to the "UserPermission" constructor.</li> |
| 202 | + * <li>The constructor parameter names {@code user1} and {@code admin1} must match respective {@code PermissionsAllowed#params}</li> |
| 203 | + * <li>`ResourceIdentity` can also be used as a constructor parameter data type</li> |
211 | 204 | * </ul>
|
212 | 205 | *
|
213 |
| - * When this annotation is used as the class-level annotation, same requirements are put on every single secured method. |
214 |
| - * |
215 |
| - * <p> |
216 |
| - * <b>WARNING:</b> "params" attribute is only supported in the scenarios explicitly named in the Quarkus documentation. |
217 |
| - * </p> |
| 206 | + * When this annotation is used as the class-level annotation, it applies to every secured method in the class. |
218 | 207 | *
|
219 | 208 | * Method parameter fields or methods can be passed to a Permission constructor as well.
|
220 | 209 | * Consider the following secured method and its parameters:
|
|
252 | 241 | * }
|
253 | 242 | * </pre>
|
254 | 243 | *
|
255 |
| - * Here, the constructor parameter {@code param1} refers to the {@code admin1#param1} secured method parameter |
256 |
| - * and the constructor parameter {@code param3} to the {@code user1#getParam3} secured method parameter. |
| 244 | + * The constructor parameter {@code param1} refers to the {@code admin1#param1} secured method parameter |
| 245 | + * and the constructor parameter {@code param3} refers to the {@code user1#getParam3} secured method parameter. |
257 | 246 | *
|
258 | 247 | * @see #AUTODETECTED
|
259 | 248 | *
|
|
262 | 251 | String[] params() default AUTODETECTED;
|
263 | 252 |
|
264 | 253 | /**
|
265 |
| - * The class that extends the {@link Permission} class, used to create permissions specified via {@link #value()}. |
| 254 | + * The class that extends the {@link Permission} class to create a permission specified in {@link #value()}. |
266 | 255 | *
|
267 | 256 | * For example:
|
268 | 257 | *
|
|
287 | 276 | Class<? extends Permission> permission() default StringPermission.class;
|
288 | 277 |
|
289 | 278 | /**
|
290 |
| - * The repeatable holder for {@link PermissionsAllowed}. The annotation is not repeatable on class-level as |
291 |
| - * repeatable interceptor bindings declared on classes are not supported by Quarkus. |
| 279 | + * The repeatable holder for {@link PermissionsAllowed}. The annotation can only be repeatable on methods. |
292 | 280 | */
|
293 | 281 | @Target(ElementType.METHOD)
|
294 | 282 | @Retention(RetentionPolicy.RUNTIME)
|
|
0 commit comments