Validate a permission against the given params

@param \BeatSwitch\Lock\Lock $lock
@param string $action
@param \BeatSwitch\Lock\Resources\Resource|null $resource
@return bool
962437
public function isAllowed(Lock $lock, $action, Resource $resource = null)
    {
        return $this->resolve($lock, $action, $resource);
    }
1350022
protected function resolvePermissions($action, Resource $resource)
    {
        $permissions = $this->getInheritedRolePermissions($this->role);

        // Search for restrictions in the permissions. We'll do this first
        // because restrictions should override any privileges.
        if (! $this->resolveRestrictions($permissions, $action, $resource)) {
            return false;
        }

        // If there are restrictions on the roles but caller specific privileges are set, allow this to pass.
        return $this->resolvePrivileges($permissions, $action, $resource);
    }
311082
public function cannot($action, $resource = null, $resourceId = null)
    {
        return ! $this->can($action, $resource, $resourceId);
    }
943301
protected function authorizationFailedError($resource, $action) {
    // when reading only log the error to avoid errors on the display
    $msg = ObjectFactory::getInstance('message')->
            getText("Authorization failed for action '%0%' on '%1%'.", [$action, $resource]);
    if ($action == PersistenceAction::READ) {
      self::$logger->error($msg."\n".ErrorHandler::getStackTrace());
    }
    else {
      throw new AuthorizationException($msg);
    }
  }
694492
protected function check_access($action = null)
	{
		is_null($action) and $action = $this->request->action;

		if ($this->has_access($action) === false)
		{
			$context = array(
				'form' => array(
					'%action%' => $action,
					'%items%'  => $this->get_name(999),
				)
			);

			\Logger::instance('alert')->error(gettext('You are not authorized to %action% %items%.'), $context);

			return \Response::redirect_back(\Uri::admin(false));
		}
	}
1227219
public static function can($action, $object=null, $message=null)
    {
        if (!static::getAuthorizer()->can($action, $object)) {
            throw new Exception($message ?: self::DEFAULT_MSG , 112);
        }
        return true;
    }
1304548
public function cannot($action, $resource = null, $resourceId = null)
    {
        $this->assertLockInstanceIsSet();

        return $this->lock->cannot($action, $resource, $resourceId);
    }
982575
public function clear($action = null, $resource = null, $resourceId = null)
    {
        $actions = (array) $action;
        $resourceObject = $this->convertResourceToObject($resource, $resourceId);
        $permissions = $this->getPermissions();

        if ($action === null && $resource === null) {
            // Clear every permission for this lock instance.
            foreach ($permissions as $permission) {
                $this->removePermission($permission);
            }
        } elseif ($action === null && $resource !== null) {
            // Clear all permissions for a given resource.
            /** @todo Needs to be implemented */
        } else {
            // Clear every permission for the given actions.
            foreach ($actions as $action) {
                $this->clearPermission($action, $resourceObject, $permissions);
            }
        }
    }
58047
public function release_lock(lock $lock) {
        $params = array('noexpires' => null,
                        'token' => $lock->get_key(),
                        'noowner' => null);

        $sql = 'UPDATE {lock_db}
                    SET
                        expires = :noexpires,
                        owner = :noowner
                    WHERE
                        owner = :token';
        $result = $this->db->execute($sql, $params);
        if ($result) {
            unset($this->openlocks[$lock->get_key()]);
        }
        return $result;
    }
325203
public function hasPermissionTo($action)
    {
        return $this->allPermissions->has(
            function($permission) use ($action) {
                return $permission->action == $action;
            }
        );
    }
1266674
public function can($action, $resource, $resourceValue = null)
    {
        if (is_object($resource)) {
            $resourceValue = $resource;
            $resource = get_classname($resourceValue);
        } elseif (is_array($resource)) {
            // Nested resources can be passed through an associative array, this way conditions which are
            // dependent upon the association will work when using a class.
            $resourceValue = head(array_values($resource));
            $resource = head(array_keys($resource));
        }

        // The conditional callback (Closure) is only evaluated when an actual instance object is present.
        // It is not evaluated when checking permissions on the class name (such as in the 'index' action).
        $skipConditions = false;
        if (is_string($resource) && ! is_object($resourceValue) && $this->hasCondition($action, $resource)) {
            $skipConditions = true;
        }

        $self = $this;
        $rules = $this->getRulesFor($action, $resource);

        if (! $rules->isEmpty()) {
            $allowed = array_reduce($rules->all(), function ($result, $rule) use ($self, $resourceValue, $skipConditions) {
                if ($skipConditions) {
                    return $rule->getBehavior(); // Short circuit
                } else {
                    if ($rule->isRestriction()) {
                        // 'deny' rules override prior rules.
                        $result = $result && $rule->isAllowed($self, $resourceValue);
                    } else {
                        // 'allow' rules do not override prior rules but instead are logically or'ed.
                        // Unlike Authority default behavior.
                        $result =  $result || $rule->isAllowed($self, $resourceValue);
                    }
                }

                return $result;
            }, false);
        } else {
            $allowed = false;
        }

        return $allowed;
    }
104040
public function lock($id)
    {
        $id = (int) $id;
        if ($id <= 0) {
            throw new Exception('Invalid param id');
        }
        return $this->rest->put("$this->action/$id/lock");
    }
307902
public function userAllowed($action)
    {
        if (user()->isAdmin()) {
            return true;
        }

        $this->_loadPermissions();
        $allowedRoles = $this->_permissions
            ->filter(function ($rule) use ($action) {
                return $rule->get('action') == $action;
            })
            ->extract('role_id')
            ->toArray();
        $intersect = array_intersect($allowedRoles, user()->get('role_ids'));

        return !empty($intersect);
    }
1041073
public final void checkPermission( String resource , String action ) throws JMSException
    {
        if (securityContext == null)
            return; // Security is disabled

        securityContext.checkPermission(resource, action);        
    }
511843
public function canIfAs(Authorizable $user, string $action): bool
    {
        $this->setUser($user);

        $permission = $this->canIf($action);

        $this->revokeUser();

        return $permission;
    }
339126
@Override
	public void checkPermission(String resourceName, String action) throws JMSException 
	{
		for (int i = 0; i < privileges.size(); i++)
		{
			Privilege privilege = privileges.get(i);
			if (privilege.matches(resourceName, action))
				return;
		}
		throw new FFMQException("Access denied to resource '"+resourceName+"' for action '"+action+"'","ACCESS_DENIED");
	}
430831
private function checkPermission($permission, $object, $options = [], $throwException = false)
    {
        if ('cli' === php_sapi_name()) {
            return true;
        }

        switch ($object) {
            //@todo Remove that line once we can
            case $object instanceof ResourceNode:
              $collection = new ResourceCollection([$object]);
              break;
            case is_array($object):
              $collection = new ObjectCollection($object, $options);
              break;
            default:
              $collection = new ObjectCollection([$object], $options);
        }

        $granted = $this->authorization->isGranted($permission, $collection);

        if (!$granted && $throwException) {
            throw new AccessDeniedException(
                sprintf('Operation "%s" cannot be done on object %s', $permission, get_class($object))
            );
        }

        return $granted;
    }