Validate a permission against the given params.

@param \BeatSwitch\Lock\Lock $lock
@param string $action
@param \BeatSwitch\Lock\Resources\Resource|null $resource
@return bool
499457
protected function resolve(Lock $lock, $action, Resource $resource = null)
    {
        // If no resource was set for this permission we'll only need to check the action.
        if ($this->resource === null || $this->resource->getResourceType() === null) {
            return $this->matchesAction($action) && $this->resolveConditions($lock, $action, $resource);
        }

        return (
            $this->matchesAction($action) &&
            $this->matchesResource($resource) &&
            $this->resolveConditions($lock, $action, $resource)
        );
    }
505500
protected function applyLock($resource)
    {
        if ($this->shouldLock === false) {
            $this->lockApplied = false;
            return flock($resource, LOCK_UN);
        }

        $lock = $this->shouldLock === true ? $this->getLockMode() : $this->shouldLock;


        if (!flock($resource, $lock)) {
            return false;
        }

        $this->lockApplied = true;

        return true;
    }
822689
protected function checkAuth($action,$resource)
	{
		return true; // remove after testing
		try {
			$userModel  = new User();
			$auth       = new BasicAuthenticator($userModel);
			$user       = $auth->currentUser();
			if ($user instanceof UserInterface) {
				$authorizer = new Authorizer( $user );
				$result     = $authorizer->can( $action, $resource );
			} else {
				$result = false;
			}
		} catch (\Exception $e) {
			\error_log($e->getMessage());
			$result = false;
		}
		return $result;
	}
1286009
public void checkLock(Session session, String path, List<String> tokens) throws LockException
   {
      String repoPath = session.getRepository().hashCode() + "/" + session.getWorkspace().getName() + "/" + path;

      String currentToken = nullResourceLocks.get(repoPath);

      if (currentToken == null)
      {
         return;
      }

      if (tokens != null)
      {
         for (String token : tokens)
         {
            if (token.equals(currentToken))
            {
               return;
            }
         }
      }

      throw new LockException("Resource already locked " + repoPath);
   }
421373
public function checkAccess($action, $resource)
    {
        if ((is_null($resource) || is_null($resource->getId())) && (empty($action) || in_array(strtolower($action), array('list', 'create', 'post')))) {
            return true;
        }

        if (!is_null($resource)) {
            $query = $this->createQueryBuilder();
            $query->andWhere($query->getRootAliases()[0] . '.id = ' . $this->addNamedParameter('id', $resource, $query));
            $result = $this->getOneOrNullResultFromQueryBuilder($query);
            if ($result) {
                return true;
            } else {
                $this->throwException('Access for this resource has been denied', 'access-denied');
            }
        }
    }
460222
public function lock($entity, $lockMode, $lockVersion = null)
    {
        if ($entity === null) {
            throw new InvalidArgumentException('No entity passed to UnitOfWork#lock().');
        }

        if ($this->getEntityState($entity, self::STATE_DETACHED) !== self::STATE_MANAGED) {
            throw ORMInvalidArgumentException::entityNotManaged($entity);
        }

        $class = $this->em->getClassMetadata(get_class($entity));

        switch (true) {
            case $lockMode === LockMode::OPTIMISTIC:
                if (! $class->isVersioned()) {
                    throw OptimisticLockException::notVersioned($class->getClassName());
                }

                if ($lockVersion === null) {
                    return;
                }

                if ($entity instanceof GhostObjectInterface && ! $entity->isProxyInitialized()) {
                    $entity->initializeProxy();
                }

                $entityVersion = $class->versionProperty->getValue($entity);

                if ($entityVersion !== $lockVersion) {
                    throw OptimisticLockException::lockFailedVersionMismatch($entity, $lockVersion, $entityVersion);
                }

                break;

            case $lockMode === LockMode::NONE:
            case $lockMode === LockMode::PESSIMISTIC_READ:
            case $lockMode === LockMode::PESSIMISTIC_WRITE:
                if (! $this->em->getConnection()->isTransactionActive()) {
                    throw TransactionRequiredException::transactionRequired();
                }

                $oid = spl_object_id($entity);

                $this->getEntityPersister($class->getClassName())->lock(
                    array_combine($class->getIdentifierFieldNames(), $this->entityIdentifiers[$oid]),
                    $lockMode
                );
                break;

            default:
                // Do nothing
        }
    }
1023093
public function revoke($permissions, $resourceName = null, $resourceId = null)
    {
        return $this->lock()->deny($permissions, $resourceName, $resourceId);
    }
1264619
public function can($permission, $operator = null)
    {
        // user permissions including
        // all of user role permissions
        $merge =  \Cache::remember(
            'acl.getMergeById_'.$this->id,
            config('acl.cacheMinutes'),
            function () {
                return $this->getPermissions();
            }
        );

        // lets call our base can() method
        // from role class. $merge already
        // has user & role permissions
        $model = config('acl.role', 'Kodeine\Acl\Models\Eloquent\Role');

        return (new $model)->can($permission, $operator, $merge);
    }
1204206
public static CmsLockActionRecord ensureLock(CmsObject cms, CmsResource resource) throws CmsException {

        LockChange change = LockChange.unchanged;
        List<CmsResource> blockingResources = cms.getBlockingLockedResources(resource);
        if ((blockingResources != null) && !blockingResources.isEmpty()) {
            throw new CmsException(
                Messages.get().container(
                    Messages.ERR_RESOURCE_HAS_BLOCKING_LOCKED_CHILDREN_1,
                    cms.getSitePath(resource)));
        }
        CmsUser user = cms.getRequestContext().getCurrentUser();
        CmsLock lock = cms.getLock(resource);
        if (!lock.isOwnedBy(user)) {
            cms.lockResourceTemporary(resource);
            change = LockChange.locked;
            lock = cms.getLock(resource);
        } else if (!lock.isOwnedInProjectBy(user, cms.getRequestContext().getCurrentProject())) {
            cms.changeLock(resource);
            change = LockChange.changed;
            lock = cms.getLock(resource);
        }
        return new CmsLockActionRecord(lock, change);
    }
915121
public function checkPermission($roleId, $action)
    {
        if ($roleId == ROLE_ID_ADMINISTRATOR) {
            return true;
        }

        $this->_loadPermissions();
        $rule = $this->_permissions
            ->filter(function ($rule) use ($roleId, $action) {
                return $rule->get('role_id') == $roleId && $rule->get('action') == $action;
            })
            ->first();

        return !empty($rule);
    }
516010
protected function canIf(string $action, ?Authorizable $user = null): bool
    {
        return ! \is_null($user)
                    ? $this->acl->canIfAs($user, $action)
                    : $this->acl->canIf($action);
    }
1223419
public function isGranted($resource, $action = 'view')
    {
        return $this->aclOperator->isAccessGranted($resource, $this->getPermission($action));
    }
470670
public function passesOrFail($action = null)
    {
        if(  !$this->passes($action) ){
            throw new ValidatorException( $this->errorsBag() );
        }

        return true;
    }
1204582
public function hasPermission($permissionName, Subject $subject, Resource $resource = null, array $params = [])
    {
        return in_array($permissionName, $this->getPermissions($subject, $resource, $params));
    }
880276
protected function getNecessaryPermission($action)
    {
        $parsed = $this->parseAction($action);

        return ResourcePermissions::permissionFor($parsed['resource'], $parsed['action']);
    }
833935
protected function getPermissionInstance($resource, $context, $action) {
    $query = new ObjectQuery($this->permissionType, __CLASS__.__METHOD__);
    $tpl = $query->getObjectTemplate($this->permissionType);
    $tpl->setValue('resource', Criteria::asValue('=', $resource));
    $tpl->setValue('context', Criteria::asValue('=', $context));
    $tpl->setValue('action', Criteria::asValue('=', $action));
    $permissions = $query->execute(BuildDepth::SINGLE);
    return (sizeof($permissions) > 0) ? $permissions[0] : null;
  }
281785
public function hasPermission($permission, $force = false)
    {
        if (! is_null($this->getUser())) {
            return $this->getUser()->hasPermission($permission, $force);
        }

        return false;
    }