@param mixed $permission
@param mixed $object
@param array $options
@param bool  $throwException

@return bool
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;
    }
1282751
public function getValidator(PermissionInterface $permission)
    {
        /** @var ValidatorInterface|null $validator */
        $validator = $this->validatorPluginManager->get($permission->getValidator());

        if (!$validator) {
            throw new Exception\ValidatorNotFound(sprintf(
                'The validator \"%s\" could not be found',
                is_object($validator) ? get_class($validator) : gettype($validator)
            ));
        }

        if ($permission->getValidatorOptions()) {
            $json = $permission->getValidatorOptions();
            $options = json_decode($json, true);

            if (!$options) {
                throw new Exception\RuntimeException(sprintf(
                    'The options for validator \"%s\" must be in json format',
                    is_object($validator) ? get_class($validator) : gettype($validator)
                ));
            }

            foreach ($options as $method => $value) {
                $validator->{$method}($value);
            }
        }

        return $validator;
    }
1360998
public function addPermission($permission)
    {
        if (!$this->hasPermission($permission)) {
            return PermissionRole::create(['role_id' => $this->id, 'permission_id' => $permission->id]);
        }

        return false;
    }
422444
public function associate(string $role, string $permission, string $rule = AllowRule::class): PermissionManager
    {
        if (!$this->hasRole($role)) {
            throw new RoleException("Undefined role '{$role}'");
        }

        if (!$this->rules->has($rule)) {
            throw new PermissionException("Undefined rule '{$rule}'");
        }

        $this->permissions[$role][$permission] = $rule;

        return $this;
    }
955454
public function roleHasPermission($permission, $force = false)
    {
        if (! is_null($this->getUser())) {
            return $this->getUser()->roleHasPermission($permission, $force);
        }

        return false;
    }
570131
protected function isGranted($attributes, $object = null, $throwException = true)
    {
        if (is_null($object)) {
            $object = $this->config->getObjectIdentity();
        } else {
            $object = $this->get('ekyna_admin.pool_registry')->getObjectIdentity($object);
        }
        if (!$this->get('security.authorization_checker')->isGranted($attributes, $object)) {
            if ($throwException) {
                throw new AccessDeniedHttpException('You are not allowed to view this resource.');
            }
            return false;
        }
        return true;
    }
1130036
public function allowGroup($permissions, $object, $group)
	{
		if(!is_array($permissions))
		{
			$permissions = array($permissions);
		}
		
		foreach($permissions as $permission)
		{
			$this->allowSingleGroupPermission($permission, $object, $group);
		}
	}
425733
public function userCan($permission, $object, $user = null)
	{
		// if no user is specified, default to the Auth one
		if(is_null($user))
		{
			$user = app('auth')->user();
		}
		
		$adminGroups = $this->groupProvider()->findAdminGroups();
		
		if($adminGroups->count() > 0 && $user->inGroup($adminGroups))
			return true;
		
		// find the exact permission for the object
		$permObject = $this->permission->findByPermissionAndObject($permission, $object);
		
		// if the permission object doesn't exist, then they don't have access
		if(!$permObject)
			return false;
		
		// if the user has direct permission, allow
		$uop = $this->userObjectPermission->findPermission($user, $object, $permObject);
		
		if($uop)
			return true;
		
		// get all the groups that have that specific permission on the object
		$gop = $this->groupObjectPermission->findPermissions($object, $permObject);
		
		// if there are no groups, deny
		if(count($gop) == 0)
			return false;
		
		// get all the relevant groups
		$groups = array();
		foreach($gop as $onePermission)
		{
			$groups[] = $onePermission->getGroup();
		}
		
		// allow or deny based on whether the user is in those groups
		return $user->inGroup($groups);
	}
723561
public function addPermission($permission)
    {
        if (is_string($permission)) {
            $name       = $permission;
            $permission = $this->createPermission($name);
        } elseif ($permission instanceof PermissionInterface) {
            $name = $permission->getName();
        } else {
            throw new \InvalidArgumentException('Permission must be a string or implement PermissionInterface');
        }

        $this->permissions[$name] = $permission;
        return $permission;
    }
976769
public static function configure($object, array $options)
    {
        foreach ($options as $property => $value) {
            $object->$property = $value;
        }
    }
401711
public function permissions($permissions = null)
    {
        if (!$this->protect()) {
            return $this;
        }

        if ($permissions === null) {
            return $this->_allow;
        }

        if (is_string($permissions) && $permissions == 'all') {
            $permissions = true;
        }

        if (is_string($permissions) && $permissions == 'none') {
            $permissions = false;
        }

        if (is_array($permissions)) {
            foreach ($permissions as $permission) {
                if (!in_array($permission, $this->_availablePermissions)) {
                    throw new Exception(sprintf('Invalid permission: %s', $permission));
                }

                if (!$this->crypto()->permissionImplemented($permission)) {
                    throw new Exception(sprintf('Permission not implemented in crypto engine: %s', $permission));
                }
            }
        }

        $this->_allow = $permissions;

        return $this;
    }
1006666
static public function hasPerm ($request, $permission)
    {
        $res = User_Precondition::loginRequired($request);
        if (true !== $res) {
            return $res;
        }
        if ($request->user->hasPerm($permission)) {
            return true;
        }
        throw new Pluf_Exception('you do not have permission', 4005, null, 400, 
                '', 'you do not have permission');
    }
965578
public function canAndOwns($permission, $thing, $options = [])
    {
        $options = Helper::checkOrSet('requireAll', $options, [false, true]);
        $options = Helper::checkOrSet('foreignKeyName', $options, [null]);
        $options = Helper::checkOrSet('team', $options, [null]);

        return $this->hasPermission($permission, $options['team'], $options['requireAll'])
                && $this->owns($thing, $options['foreignKeyName']);
    }
1133586
public function error(
        Throwable $throwable,
        string $transactionId,
        array $options = []
    ): CancellablePromiseInterface {
        if (!($throwable instanceof ResponseException)) {
            return reject($throwable);
        }

        return reject(ExceptionFactory::create($throwable->getResponse(), $throwable));
    }
1319285
public function can($permission, $allowAny = false)
    {
        if ($allowAny) {
            return $this->hasAnyAccess(
                is_array($permission) ? $permission : [ $permission ]
            );
        }

        return $this->hasAccess(
            is_array($permission) ? $permission : [ $permission ]
        );
    }
186342
protected function checkPermission($permission, $siteSlug = null)
    {
        if (!$this->Permissions->checkPermission($permission, $siteSlug))
            throw new Exception('Permission denied to action ['.$this->currentActionOrDatasource.']');

        //if(LOG_ENABLE) System::log(self::$logType, 'Passed permission check: ['.$this->currentActionOrDatasource.']');
    }
1058659
public function delete($object, array $options = [])
    {
        $this->checkPermission('DELETE', $object, [], true);

        if ($this->dispatch('delete', 'pre', [$object, $options])) {
            if (!in_array(Options::SOFT_DELETE, $options)) {
                $this->om->remove($object);
                $this->om->flush();
            }
            $this->dispatch('delete', 'post', [$object, $options]);
        }
    }