Class 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 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 Provider user;
    • Constructor Detail

      • PermissionBackend

        public PermissionBackend()
    • Method Detail

      • bulkEvaluateTest

        public void bulkEvaluateTest​(Collection<PermissionBackendCondition> conds)
        Bulk evaluate a collection of 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 may contain duplicate entries (such as same user, resource, permission triplet). When duplicates exist, implementations should set a result into all instances to ensure testOrFalse does not get invoked during evaluation of the containing condition.

        Parameters:
        conds - conditions to consider.