Class PermissionBackend
- java.lang.Object
-
- com.google.gerrit.server.permissions.PermissionBackend
-
- Direct Known Subclasses:
DefaultPermissionBackend
public abstract class PermissionBackend extends Object
Checks authorization to perform an action on a project, reference, or change.check
methods should be used during action handlers to verify the user is allowed to exercise the specified permission. For convenience in implementationcheck
methods throwAuthException
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 ofPermissionBackend.WithUser
,PermissionBackend.ForProject
,PermissionBackend.ForRef
, andPermissionBackend.ForChange
instances, in addition to storing withinCurrentUser
using aCurrentUser.PropertyKey
.GlobalPermission
caching forPermissionBackend.WithUser
may best cached insideCurrentUser
asPermissionBackend.WithUser
instances are frequently created.Example use:
private final PermissionBackend permissions; private final Provider
user;
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
PermissionBackend.AcceptsReviewDb<T>
PermissionBackend with an optional per-request ReviewDb handle.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.WithUser
PermissionBackend scoped to a specific user.
-
Constructor Summary
Constructors Constructor Description PermissionBackend()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
bulkEvaluateTest(Collection<PermissionBackendCondition> conds)
Bulk evaluate a collection ofPermissionBackendCondition
for view handling.abstract PermissionBackend.WithUser
user(CurrentUser user)
<U extends CurrentUser>
PermissionBackend.WithUseruser(com.google.inject.Provider<U> user)
-
-
-
Method Detail
-
user
public abstract PermissionBackend.WithUser user(CurrentUser user)
- Returns:
- lightweight factory scoped to answer for the specified user.
-
user
public <U extends CurrentUser> PermissionBackend.WithUser user(com.google.inject.Provider<U> user)
- Returns:
- lightweight factory scoped to answer for the specified user.
-
bulkEvaluateTest
public void bulkEvaluateTest(Collection<PermissionBackendCondition> conds)
Bulk evaluate a collection ofPermissionBackendCondition
for view handling.Overridden implementations should call
PermissionBackendCondition.set(boolean)
to cache the result oftestOrFalse
in the condition for later evaluation. Caching the result will bypass the usual invocation oftestOrFalse
.conds
may contain duplicate entries (such as same user, resource, permission triplet). When duplicates exist, implementations should set a result into all instances to ensuretestOrFalse
does not get invoked during evaluation of the containing condition.- Parameters:
conds
- conditions to consider.
-
-