@param RoleManager $rm

@throws CasbinException
431661
public function buildRoleLinks(RoleManager $rm)
    {
        $this->rM = $rm;
        $count = substr_count($this->value, '_');

        foreach ($this->policy as $rule) {
            if ($count < 2) {
                throw new CasbinException('the number of "_" in role definition should be at least 2');
            }
            if (\count($rule) < $count) {
                throw new CasbinException('grouping policy elements do not meet role definition');
            }

            if (2 == $count) {
                $this->rM->addLink($rule[0], $rule[1]);
            } elseif (3 == $count) {
                $this->rM->addLink($rule[0], $rule[1], $rule[2]);
            } elseif (4 == $count) {
                $this->rM->addLink($rule[0], $rule[1], $rule[2], $rule[3]);
            }
        }

        Log::logPrint('Role links for: '.$this->key);
        $this->rM->printRoles();
    }
676715
public function removeRolePermission(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());
        }

        $query->delete();

        $this->resetPermissionsCacheForRole($role);
    }
1191297
protected function addRolesToSU(Role $roleSu)
    {
        $this->stdout("Init SU assigning roles\n",  Console::FG_YELLOW);
        foreach ($this->authManager->getRoles() as $role) {
            try {
                if ($role->name !== $roleSu->name) {
                    $this->authManager->addChild($roleSu, $role);
                    $this->stdout("\tAssign to SU role: {$role->name} - success\n", Console::FG_GREEN);
                }
            } catch(\Exception $e) {
                $this->stdout("\t- already exist\n",  Console::FG_RED);
            }
        };
    }
34409
public static function setVcsTypeRepositories(RepositoryManager $rm)
    {
        foreach (Assets::getTypes() as $assetType) {
            foreach (Assets::getVcsRepositoryDrivers() as $driverType => $repositoryClass) {
                $rm->setRepositoryClass($assetType.'-'.$driverType, $repositoryClass);
            }
        }
    }
269023
protected function assign($role = null, $action = null, $allow = true)
    {
        $role   = $this->roles->findKey($role);
        $action = $this->actions->findKey($action);

        if (!is_null($role) && !is_null($action)) {
            $key             = $role . ':' . $action;
            $this->acl[$key] = $allow;
        }
    }
253748
public function removeRolePermission(Role $role, Permission $permission)
    {
        // Remove permissions which match the action and resource
        $this->permissions[$this->getRoleKey($role)] = array_filter(
            $this->getRolePermissions($role),
            function (Permission $rolePermission) use ($permission) {
                // Only keep permissions which don't exactly match the one which we're trying to remove.
                return ! $rolePermission->matchesPermission($permission);
            }
        );
    }
309156
public function handle($request, Closure $next, $role)
    {
        if ($this->auth->check() && $this->auth->user()->isRole($role)) {
            return $next($request);
        }
        throw new RoleDeniedException($role);
    }
1277891
public function update($id, RoleRequest $request)
    {
        // Update the role
        $role = Role::findOrFail($id);
        $role->update($request->all());

        // Sync permissions
        $permission_ids = $request->get('permission_id', []);
        $role->permissions()->sync($permission_ids);

        return redirect()->action('\Aginev\Acl\Http\Controllers\RoleController@index')
                         ->with('success', trans('acl::role.edit.updated'));
    }
1294372
public function removeRoleAssignment(RoleAssignment $roleAssignment)
    {
        if ($this->repository->canUser('role', 'assign', $roleAssignment) !== true) {
            throw new UnauthorizedException('role', 'assign');
        }

        $spiRoleAssignment = $this->userHandler->loadRoleAssignment($roleAssignment->id);

        $this->repository->beginTransaction();
        try {
            $this->userHandler->removeRoleAssignment($spiRoleAssignment->id);
            $this->repository->commit();
        } catch (Exception $e) {
            $this->repository->rollback();
            throw $e;
        }
    }
914879
public function deleteLinkRoleScopeAction($pgid, $rsid) 
    {
        $em = $this->getDoctrine()->getManager();
        
        $permissionsGroup = $em->getRepository('ChillMainBundle:PermissionsGroup')->find($pgid);
        $roleScope = $em->getRepository('ChillMainBundle:RoleScope')->find($rsid);

        if (!$permissionsGroup) {
            throw $this->createNotFoundException('Unable to find PermissionsGroup entity.');
        }
        
        if (!$roleScope) {
            throw $this->createNotFoundException('Unable to find RoleScope entity');
        }
        
        try {
            $permissionsGroup->removeRoleScope($roleScope);
        } catch (\RuntimeException $ex) {
            $this->addFlash('notice', 
                $this->get('translator')->trans("The role '%role%' and circle "
                        . "'%scope%' is not associated with this permission group", array(
                            '%role%' => $this->get('translator')->trans($roleScope->getRole()),
                            '%scope%' => $this->get('chill.main.helper.translatable_string')
                                ->localize($roleScope->getScope()->getName())
                        )));
            
            return $this->redirect($this->generateUrl('admin_permissionsgroup_edit', 
                array('id' => $pgid)));
        }
        
        $em->flush();
        
        $this->addFlash('notice', 
                $this->get('translator')->trans("The role '%role%' on circle "
                        . "'%scope%' has been removed", array(
                            '%role%' => $this->get('translator')->trans($roleScope->getRole()),
                            '%scope%' => $this->get('chill.main.helper.translatable_string')
                                ->localize($roleScope->getScope()->getName())
                        )));
        
        return $this->redirect($this->generateUrl('admin_permissionsgroup_edit', 
                array('id' => $pgid)));
    }
725660
public function update(RoleRequst $request, Model $role)
    {
        try {
            $role->update($request->all());
            $this->_saveRolePermissions($request, $role);
        } catch (\Exception $e) {
            echo 'Caught exception: ', $e->getMessage(), "\n";
        }

        return redirect()->route('admin.role.index')->with('notificationText', ' Role Updates Successfully!');
    }
777277
public function roleForm(Container $container): void
	{
		$roles = ['' => $this->translate('form.none')] + $this->orm->aclRoles->fetchPairs($this->viewSuperadmin);
		$container->addText('title', 'cms.permissions.role')
			->setRequired();
		$container->addText('name', 'cms.permissions.name')
			->setRequired();
		$container->addSelect('parent', $this->translate('cms.permissions.parent'))
			->setTranslator()
			->setItems($roles);
	}
1238579
function assign($Role, $Permission)
	{
	    if (is_numeric($Role))
	    {
	        $RoleID = $Role;
	    } else {
	        if (substr($Role, 0, 1) == "/")
	            $RoleID = Jf::$Rbac->Roles->pathId($Role);
	        else
	            $RoleID = Jf::$Rbac->Roles->titleId($Role);
	    }

	    if (is_numeric($Permission))
	    {
	        $PermissionID = $Permission;
	    }  else {
	        if (substr($Permission, 0, 1) == "/")
	            $PermissionID = Jf::$Rbac->Permissions->pathId($Permission);
	        else
	            $PermissionID = Jf::$Rbac->Permissions->titleId($Permission);
	    }

	    return Jf::sql("INSERT INTO {$this->tablePrefix()}rolepermissions
	        (RoleID,PermissionID,AssignmentDate)
	        VALUES (?,?,?)", $RoleID, $PermissionID, Jf::time()) >= 1;
	}
48717
public function setRole($role_id)
    {
        if (!empty($role_id) && $this->policy === Rule::NOINHERIT)
            throw new Exception("Rule::NOINHERIT can not be used in combination with a role");

        if ($role_id instanceof Role)
        {
            $this->role = $role_id;
            $role_id = $role_id->getID();
        }
        elseif (!is_scalar($role_id))
            throw new Exception("Role-ID must be a Role or a scalar");

        if ($role_id !== $this->role_id)
        {
            $this->changed = true;
            $this->role_id = $role_id;
        }
    }
520736
public static function roleRevoke($role) {
		if (!empty($role) && !empty($_SESSION['numbers']['user']['roles'])) {
			if (!is_array($role)) $role = [$role];
			foreach ($role as $v) {
				$key = array_search($v, $_SESSION['numbers']['user']['roles']);
				if ($key !== false) {
					unset($_SESSION['numbers']['user']['roles'][$key]);
				}
			}
		}
	}
632507
public function deassociate(string $role, string $permission): PermissionManager
    {
        return $this->associate($role, $permission, ForbidRule::class);
    }
274250
public function buildRoleLinks($rm)
    {
        if (!isset($this->model['g'])) {
            return;
        }
        foreach ($this->model['g'] as $ast) {
            $ast->buildRoleLinks($rm);
        }
    }