@param string      $permission
@param SecurityApi $security

@return static
519047
public static function permissionDenied($permission, SecurityApi $security)
    {
        $e = new static("Permission [$permission] permissionDenied.");

        $e->setSecurity($security);
        $e->setPermission($permission);

        return $e;
    }
350168
public function removeUserPermission($user, $permission)
    {
        $permissions=   $this->findPermissionByKey($permission);
        $user       =   $this->findUserById($user);

        return $user->remove($permission);
    }
1245213
public function addPermission(ChildPermission $permission)
    {
        if ($this->collPermissions === null) {
            $this->initPermissions();
        }

        if (!$this->getPermissions()->contains($permission)) {
            // only add it if the **same** object is not already associated
            $this->collPermissions->push($permission);
            $this->doAddPermission($permission);
        }

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

        return false;
    }
900601
protected function initPermission(RequesterInterface $requester, ResourceInterface $resource, $mask = 0)
    {
        $maskBuilder = $this->getMaskBuilder();
        $maskBuilder->set($mask);

        return new Permission($requester, $resource, $maskBuilder);
    }
9866
public void addPermission(Permission permission) {
        if ((securityManager != null) && (permission != null)) {
            permissionList.add(permission);
        }
    }
1157094
public function allow(string $role, string $permission, string $resource, bool $status=null)
    {
        $status = $status ?? true;
        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
                )
            );
        }

        $this->globalRegistry->save($role, $resource, $permission, $status);
    }
52759
public function deletePermissionForUser($user, ...$permission)
    {
        $params = [];

        $params[] = $user;
        foreach ($permission as $perm) {
            $params[] = $perm;
        }

        return $this->removePolicy(...$params);
    }
1213715
public function grant($permission)
    {
        $commandClass = $this->getCommandClass('grant');
        $this->command = new $commandClass($permission);

        return $this->command;
    }
640400
public function getPermission($permission)
    {
        if ($permission instanceof PermissionInterface) {
            $permission =   $permission->key;
        }

        return $this->permissions()
            ->key($permission)
            ->first();
    }
100679
private function createResource(Permission $permission): void
	{
		/* @var $resource AclResource */
		foreach ($this->orm->aclResources->findAll() as $resource) {
			$permission->addResource($resource->resource);
		}
	}
1031690
public function add(Permission $permission)
    {
        $name = $permission->getName();

        if (isset($this->permissions[$name])) {
            throw new InvalidArgumentException("Permission name $name is already set.");
        }

        $bit = $permission->getBit();

        if ($this->bitMap & $bit) {
            throw new InvalidArgumentException("Permission bit $bit is already set.");
        }

        $this->bitMap |= $bit;
        $this->permissions[$name] = $permission;

        return $this;
    }
698166
public function addPermission(Permission $permission)
    {
        if (!$permission->permission_id) {
            throw new ValidationError("Permission has invalid state");
        }
        if (!in_array($permission, $this->permissions)) {
            $this->permissions[] = $permission;
            return true;
        }
        return false;
    }
1122290
private function removeDeletedPermissions(array $permission)
    {
        $configActions = collect($permission['actions']);

        $actions = Permissions::where('name', $permission['name'])->pluck('action');

        $removedActions = $actions->diff($configActions);

        if( ! $removedActions->isEmpty() )
            foreach ( $removedActions as $action )
                Permissions::deletePermission($action);
    }
1327200
public static function check($permission)
    {
        if (static::isAdministrator()) {
            return true;
        }

        if (is_array($permission)) {
            collect($permission)->each(function ($permission) {
                call_user_func([Permission::class, 'check'], $permission);
            });

            return;
        }

        if (Auth::guard('merchant')->user()->cannot($permission)) {
            static::error();
        }
    }
609223
protected function garbageCollect(SecurityApi $security, SecurityContextConfiguration $configuration)
    {
        try
        {
            $activations = $security->activations();
            $reminders   = $security->reminders();

            $this->sweep($activations, $configuration->getActivationsLottery());
            $this->sweep($reminders,   $configuration->getRemindersLottery());
        }
        catch (\Exception $e)
        {
            // Silently fail and report, but still serve the content.
            $this->logger->error(
                'Unable to garbage collect reminders or activations: '.
                $e->getMessage(),
                $e->getTrace()
            );
        }
    }
408786
public function addPermission(string ...$permission)
    {
        foreach ($permission as $_permission)
        {
            $this->permissionRegistry->save($_permission);
        }
    }