Check for a access to a resource

@param  Zend\Permissions\Acl\Resource\ResourceInterface|string    $resource
@param  string|array                                              $privilege
@return boolean
15653
public function isAllowed($resource = null, $privilege = null)
    {
        if (is_array($privilege)) {
            foreach ($privilege as $privilegeSingular) {
                if ($this->isAllowed($resource, $privilegeSingular)) {
                    return true;
                }
            }
            return false;
        }
        try {
            $result = $this->getContextualAcl()->isAllowed($this->getContextId(), $resource, $privilege);
        } catch (InvalidArgumentException $e) {
            return false;
        }
        return $result;
    }
530106
public function getPermissionStatus(string $role, string $permission, string $resource) : bool
    {
        if (!$this->roleRegistry->exists($role)) {
            throw new \Exception(
                sprintf(
                    "The role: %s doesnt exist",
                    (string)$role
                )
            );
        }

        if (!$this->permissionRegistry->exists($permission)) {
            throw new \Exception(
                sprintf(
                    "The permission: %s doesnt exist",
                    (string)$permission
                )
            );
        }

        if (!$this->resourceRegistry->exists($resource)) {
            throw new \Exception(
                sprintf(
                    "The resource: %s doesnt exist",
                    (string)$resource
                )
            );
        }

        $roleObject = $this->globalRegistry->get($role);

        if (isset($roleObject[$resource][$permission]["status"]))
        {
            return $roleObject[$resource][$permission]["status"];
        }

        $parents = $this->roleRegistry->getRegistry()[$role];

        foreach ($parents as $parentRole)
        {
            $permissionStatus = $this->getPermissionStatus($parentRole, $permission, $resource);

            if ($permissionStatus)
            {
                return true;
            }
        }

        return false;
    }
1027176
public static function allPermissionsFor($resource)
    {
        $result = [];
        foreach (static::$permissions as $permission) {
            $result[] = sprintf('%s %s', $permission, str_plural($resource));
        }

        return $result;
    }
999629
public function can($action, $resource = null, $resourceId = null)
    {
        $actions = (array) $action;
        $resource = $this->convertResourceToObject($resource, $resourceId);
        $permissions = $this->getPermissions();

        foreach ($actions as $action) {
            if ($aliases = $this->getAliasesForAction($action)) {
                if ($this->can($aliases, $resource) && $this->resolveRestrictions($permissions, $action, $resource)) {
                    return true;
                }
            }

            if (! $this->resolvePermissions($action, $resource)) {
                return false;
            }
        }

        return true;
    }
102635
public function grantAccess($roleOrPermission, UserInterface $user = null)
    {
        $user = $user ? : $this->currentUser();

        if (is_array($roleOrPermission) && $this->grantAccessByRoles($roleOrPermission, $user)) {
            return true;
        } else if (is_array($roleOrPermission) && $this->grantAccessByPermissions($roleOrPermission, $user)) {
            return true;
        } else if ($this->grantAccessByRole($roleOrPermission, $user)) {
            return true;
        } else if ($this->grantAccessByPermission($roleOrPermission, $user)) {
            return true;
        }

        return false;
    }
1138506
public function canDo(string $privilege): bool
    {
        // $privileges = CacheFile::fromMap('privileges');
        $privileges = cache('privileges') ?? Privilege::getModel()->privileges();

        return $privileges[$privilege][$this->role] ?? false;
    }
1124239
public function setAllowed($role = self::ALL, $resource = self::ALL, $privilege = self::ALL)
    {
        if ($this->policy == self::POLICY_ALLOW) {
            $this->permission->allow($role, $resource, $privilege);
        } else {
            $this->permission->deny($role, $resource, $privilege);
        }
    }
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');
            }
        }
    }
212751
public function checkAccess(EventInterface $event) {
        if ($event->hasArgument('skipAccessControl') &&
            $event->getArgument('skipAccessControl') === true) {
            return;
        }

        $request = $event->getRequest();
        $aclAdapter = $event->getAccessControl();
        $resource = $event->getName();
        $publicKey = $request->getPublicKey();
        $user = $request->getUser();

        $hasAccess = $aclAdapter->hasAccess($publicKey, $resource, $user);

        if ($hasAccess) {
            return;
        }

        // If we're asking for info on a public key, and that public key happens to be the one
        // used to sign the request, accept this as a valid request and let the user have access
        // to the resource. Note that this requires the accessToken listener to be in place -
        // if disabled, any user can ask for the access rules for all public keys
        if (in_array($resource, $this->ownPublicKeyAllowedResources)) {
            $routePubKey = $request->getRoute()->get('publickey');
            if ($routePubKey === $publicKey) {
                return;
            }
        }

        // If a public key has access to resources within a resource group, allow the
        // public key to access the group resource to see which resources it contains
        if (in_array($resource, $this->groupLookupResources)) {
            $routeGroup = $request->getRoute()->get('group');
            $aclList = $aclAdapter->getAccessListForPublicKey($publicKey);

            foreach ($aclList as $aclRule) {
                if (isset($aclRule['groups']) && in_array($routeGroup, $aclRule['groups'])) {
                    return;
                }
            }
        }

        throw new RuntimeException('Permission denied (public key)', 400);
    }
1370357
function isAllowed(/*iAuthResource*/ $resource = null, /*iIdentity*/ $role = null)
    {
        $role = ($role) ?: $this->getAuthAdapter()->identity();

        if (!is_object($resource)
            || (!$resource instanceof PermResource || !method_exists($resource, 'getRouteName'))
        )
            throw new \Exception('Invalid Resource Type, Can`t Check The Permissions.');

        // All has access on home, but authorized users has access on other routes
        return ($resource->getRouteName() == 'home' || $role->hasAuthenticated());
    }
517891
public function getResourcePermissions(ResourceInterface $resource) : array
    {
        $query = $this->getRepository()->createQueryBuilder('r')
            ->select('r')
            ->where('r.resource_class = :resourceClass AND r.resource_id=:resourceId')
            ->setParameter('resourceClass', $resource->getClass())
            ->setParameter('resourceId', $resource->getId())
            ->getQuery();

        return $query->getResult();
    }
628566
public function hasRolePermission(Role $role, Permission $permission)
    {
        $query = $this->getTable()
            ->where('role', $role->getRoleName())
            ->where('type', $permission->getType())
            ->where('action', $permission->getAction());

        if (is_null($permission->getResourceType())) {
            $query->whereNull('resource_type');
        } else {
            $query->where('resource_type', $permission->getResourceType());
        }

        if (is_null($permission->getResourceId())) {
            $query->whereNull('resource_id');
        } else {
            $query->where('resource_id', $permission->getResourceId());
        }

        return (bool) $query->first();
    }
604985
public function isGranted($resource)
    {
        foreach ($this->roles as $role) {
            if (true === $role->hasResource($resource)) {
                return true;
            }
        }

        return false;
    }
83182
protected function processIsGranted(RequesterInterface $requester, ResourceInterface $resource, $action, &$buffer = [])
    {
        try {
            $permission = $this->findPermission($requester, $resource);

            $isGranted = $permission->isGranted($action);
        } catch (PermissionNotFoundException $e) {
            $this->permissionBuffer->add($this->initPermission($requester, $resource, 0));

            $isGranted = false;
        }

        if (false === $isGranted && $requester instanceof CascadingRequesterInterface) {
            $buffer[] = $requester->getAclRequesterIdentifier();

            foreach ($requester->getAclParentsRequester() as $requesterParent) {
                if (in_array($requesterParent->getAclRequesterIdentifier(), $buffer)) {
                    return $isGranted;
                }

                $buffer[] = $requesterParent->getAclRequesterIdentifier();
                if (true === $this->processIsGranted($requesterParent, $resource, $action, $buffer)) {
                    return true;
                }
            }
        }

        return $isGranted;
    }
506459
protected function isAllowed($resourceId, $privilege)
    {
        $rcmUserService = $this->getServiceLocator()->get(
            'RcmUser\Service\RcmUserService'
        );

        return $rcmUserService->isAllowed(
            $resourceId,
            $privilege
        );
    }
26867
public function checkPrivilegeRequest($privilege, $resource)
    {
        $em = $this->getEntityManager();
        $privilege = trim($privilege);
        $resource = trim($resource);
        // Check the input values.
        if ($resource === '' || $privilege === '') {
            return false;
        }
        // Try to find the privilege request in the database.
        $requestedPrivilege = $em->getRepository('JaztecAcl\Entity\Monitor\RequestedPrivilege')->findOneBy([
            'privilege' => $privilege,
            'resource'  => $resource,
        ]);
        if ($requestedPrivilege instanceof \JaztecAcl\Entity\Monitor\RequestedPrivilege) {
            return true;
        }
        // Create the privilege request.
        $newRequestedPrivilege = new \JaztecAcl\Entity\Monitor\RequestedPrivilege();
        $newRequestedPrivilege
            ->setPrivilege($privilege)
            ->setResource($resource);
        $em->persist($newRequestedPrivilege);
        $em->flush();
        return true;
    }
522433
public function checkResource( $resource, $parent = null )
    {
        if ( null === $resource )
        {
            return null;
        }

        if ( $resource instanceof Acl\Resource\ResourceInterface )
        {
            $resource = $resource->getResourceId();
        }

        $acl = $this->getAcl();

        if ( ! $acl->hasResource( $resource ) )
        {
            if ( null === $parent )
            {
                $parent = $this->getParentId( $resource );
            }
            elseif ( $parent instanceof Acl\Resource\ResourceInterface )
            {
                $parent = $parent->getResourceId();
            }

            $parent = $this->checkResource( $parent );
            $acl->addResource( $resource, $parent );
        }

        return $resource;
    }