public abstract class PermissionBackend
extends java.lang.Object
check
methods should be used during action handlers to verify the user is allowed to
exercise the specified permission. For convenience in implementation check
methods throw
AuthException
if the permission is denied.
test
methods should be used when constructing replies to the client and the result
object needs to include a true/false hint indicating the user's ability to exercise the
permission. This is suitable for configuring UI button state, but should not be relied upon to
guard handlers before making state changes.
PermissionBackend
is a singleton for the server, acting as a factory for lightweight
request instances. Implementation classes may cache supporting data inside of PermissionBackend.WithUser
,
PermissionBackend.ForProject
, PermissionBackend.ForRef
, and PermissionBackend.ForChange
instances, in addition to storing
within CurrentUser
using a CurrentUser.PropertyKey
.
GlobalPermission
caching for PermissionBackend.WithUser
may best cached inside CurrentUser
as PermissionBackend.WithUser
instances are frequently created.
Example use:
private final PermissionBackend permissions; private final Provideruser; @Inject Foo(PermissionBackend permissions, Provider user) { this.permissions = permissions; this.user = user; } public void apply(...) { permissions.user(user).change(cd).check(ChangePermission.SUBMIT); } public UiAction.Description getDescription(ChangeResource rsrc) { return new UiAction.Description() .setLabel("Submit") .setVisible(rsrc.permissions().testCond(ChangePermission.SUBMIT)); }
Modifier and Type | Class and Description |
---|---|
static class |
PermissionBackend.ForChange
PermissionBackend scoped to a user, project, reference and change.
|
static class |
PermissionBackend.ForProject
PermissionBackend scoped to a user and project.
|
static class |
PermissionBackend.ForRef
PermissionBackend scoped to a user, project and reference.
|
static class |
PermissionBackend.RefFilterOptions
Options for filtering refs using
PermissionBackend.ForProject . |
static class |
PermissionBackend.WithUser
PermissionBackend scoped to a specific user.
|
Constructor and Description |
---|
PermissionBackend() |
Modifier and Type | Method and Description |
---|---|
abstract PermissionBackend.WithUser |
absentUser(Account.Id id)
Returns an instance scoped to the provided user.
|
void |
bulkEvaluateTest(java.util.Set<PermissionBackendCondition> conds)
Bulk evaluate a set of
PermissionBackendCondition for view handling. |
void |
checkUsesDefaultCapabilities()
Throw
ResourceNotFoundException if this backend does not use the default global
capabilities. |
abstract PermissionBackend.WithUser |
currentUser()
Returns an instance scoped to the current user.
|
abstract PermissionBackend.WithUser |
user(CurrentUser user)
Returns an instance scoped to the specified user.
|
boolean |
usesDefaultCapabilities()
Check whether this
PermissionBackend respects the same global capabilities as the
DefaultPermissionBackend . |
public abstract PermissionBackend.WithUser currentUser()
public abstract PermissionBackend.WithUser user(CurrentUser user)
IllegalStateException
.
If an instance scoped to the current user is desired, use currentUser()
instead.
public abstract PermissionBackend.WithUser absentUser(Account.Id id)
Usage should be very limited as this can expose a group-oracle.
public boolean usesDefaultCapabilities()
PermissionBackend
respects the same global capabilities as the
DefaultPermissionBackend
.
If true, then it makes sense for downstream callers to refer to built-in Gerrit capability names in user-facing error messages, for example.
public void checkUsesDefaultCapabilities() throws ResourceNotFoundException
ResourceNotFoundException
if this backend does not use the default global
capabilities.ResourceNotFoundException
public void bulkEvaluateTest(java.util.Set<PermissionBackendCondition> conds)
PermissionBackendCondition
for view handling.
Overridden implementations should call PermissionBackendCondition.set(boolean)
to
cache the result of testOrFalse
in the condition for later evaluation. Caching the
result will bypass the usual invocation of testOrFalse
.
conds
- conditions to consider.