roles() method.

@return bool
763510
protected function _roles()
    {
        $this->loadModel('CakeManager.Roles');

        $list = $this->Roles->find('list')->toArray();

        if (empty($list)) {
            $this->out('No roles found.');
        }

        // Creating administrators
        if (!in_array('Administrators', $list)) {
            $data = [
                'name' => 'Administrators',
                'login_redirect' => '/admin/manager/pages/dashboard',
            ];

            $new = $this->Roles->newEntity($data);
            if ($this->Roles->save($new)) {
                $this->out('Role "Administrators" created');
            } else {
                $this->out('Role "Administrators" could not be created');
                return false;
            }
        }

        // Creating moderators
        if (!in_array('Moderators', $list)) {
            $data = [
                'name' => 'Moderators',
                'login_redirect' => '/',
            ];

            $new = $this->Roles->newEntity($data);
            if ($this->Roles->save($new)) {
                $this->out('Role "Moderators" created');
            } else {
                $this->out('Role "Moderators" could not be created');
                return false;
            }
        }

        // Creating Users
        if (!in_array('Users', $list)) {
            $data = [
                'name' => 'Users',
                'login_redirect' => '/',
            ];

            $new = $this->Roles->newEntity($data);
            if ($this->Roles->save($new)) {
                $this->out('Role "Users" created');
            } else {
                $this->out('Role "Users" could not be created');
                return false;
            }
        }

        // Creating unregisterd
        if (!in_array('Users', $list)) {
            $data = [
                'name' => 'Unregistered',
                'login_redirect' => '/',
            ];

            $new = $this->Roles->newEntity($data);
            if ($this->Roles->save($new)) {
                $this->out('Role "Unregistered" created');
            } else {
                $this->out('Role "Unregistered" could not be created');
                return false;
            }
        }

        $this->out("Done.");
        return true;
    }
435342
public function assignRole($roleId = null)
    {
        $roles = $this->roles;

        if (! $roles->contains($roleId)) {
            return $this->roles()->attach($roleId);
        }

        return false;
    }
373819
public function getRoles()
    {
        $roles = $this->roles;

        foreach ($this->getGroups() as $group) {
            /** @noinspection SlowArrayOperationsInLoopInspection */
            $roles = array_merge($roles, $group->getRoles());
        }

        // we need to make sure to have at least one role
        $roles[] = static::ROLE_DEFAULT;

        return array_unique($roles);
    }
74698
public function roles() {
		$user = $this->user();
		if (!$user) {
			return [];
		}

		$roles = $this->_getUserRoles($user);

		return $roles;
	}
971171
public function getRoles()
    {
        if(!$this->roles){
            $this->roles = $this->grantedRoles()->get();

            $deniedRoles = $this->deniedRoles()->get();
            foreach($deniedRoles as $role)
                $deniedRoles = $deniedRoles->merge($role->descendants());

            foreach($this->roles as $role)
                if(!$deniedRoles->contains($role))
                    $this->roles = $this->roles->merge($role->descendants());

            $this->roles = $this->roles->filter(function($role) use ($deniedRoles){
                return !$deniedRoles->contains($role);
            });
        }
        return  $this->roles;
    }
322445
public function hasRole($role, $user = null)
    {
        $roleName = $role instanceof Role ? $role->getRole() : $role;

        $user = $user ?: $this->getUser();

        if (!($user instanceof UserInterface)) {
            return false;
        }

        if (null === $this->roleHierarchy) {
            return in_array($roleName, $user->getRoles(), true);
        }

        $userRoles = $this->roleHierarchy->getReachableRoles($this->getUserRolesAsObjects($user));
        foreach ($userRoles as $userRole) {
            if ($roleName === $userRole->getRole()) {
                return true;
            }
        }

        return false;
    }
1078200
public function assignRoles() {
    $auth = Yii::$app->authManager;
    $auth->assign($auth->getRole(Access::ROLE_USER), $this->id);
  }
1143386
public function getRolesCount(): int {
        $count = 0;
        foreach ($this->roles as $i) {
            $count += count($i);
        }
        return $count;
    }
429894
public function setRoles(array $roles = array())
    {
        if ($this->instance instanceof \Phavour\Session\Storage) {
            if ($this->instance->isLocked()) {
                $this->instance->unlock();
            }
            $this->instance->set('roles', $roles);
            $this->instance->lock();
            return true;
        }

        return false;
    }
1140283
public function isCorpCharacterWithRoles(): bool
    {

        // Check the role needed for this call. The minimum role would
        // be configured in the roles attribute, but we will add the
        // 'Director' role as directors automatically have all roles.
        array_push($this->roles, 'Director');

        // Perform the check.
        if (in_array($this->scope, $this->token->scopes) && ! empty(
            array_intersect($this->roles, $this->getCharacterRoles()))) {

            return true;
        }

        // Considering a corporation role was required with the scope,
        // fail the authentication check. If we don't fail here, simply
        // granting the SSO scope would pass the next truth test.
        return false;
    }
1122280
public function hasRole(Role $role)
    {
        $role = !is_string($role) ?: Role::where(['name' => $role])->firstOrFail();

        if ($role) {
            foreach ($this->roles as $r) {
                if ($r->id == $role->id) {
                    return true;
                }
            }
        }

        return false;
    }
336450
public function roles(): array
    {
        return array_merge(array(),
            ...array_map(
                function (Attribute $attr) {
                    return $attr->values();
                }, $this->allOf(AttributeType::OID_ROLE)));
    }
177037
public function hasRoles($roles)
    {
        if ($this->user() === null) {
            return null;
        }

        if (!is_array($roles)) {
            $roles = func_get_args();
        }

        // Count roles because user need user to have all roles passed as parameter
        return count(array_intersect($roles, $this->roles)) === count($roles);
    }
19784
public function getRoles()
    {
        $roles = $this->roles;

        foreach ($this->getGroups() as $group) {
            $roles = array_merge($roles, $group->getRoles());
        }

        $newRoles = [];

        if ($this->getActiveRole()) {
            $newRoles = $this->getActiveRole()->getRoles();
        }

        $finalRoles = array_merge($roles, $newRoles);

        // we need to make sure to have at least one role
        $finalRoles[] = static::ROLE_DEFAULT;

        return array_unique($finalRoles);
    }
416417
public function isAuthorized()
    {
        /** @var Rbac $rbac */
        $rbac = $this->getContainer()->get('rbac');

        /** @var Auth $auth */
        $auth = $this->getContainer()->get('auth');
        foreach ($auth->getStorage()->read()['roles'] as $roleName) {
            if (true === $rbac->isGranted($roleName, 'admin.panel.view')) {
                return true;
            }
        }

        return false;
    }
824849
public function roles()
    {
	    $currentSession = $this->getSession();
	    if ($currentSession instanceof \common_session_RestrictedSession) {
	        $this->setData('roles', $currentSession->getUserRoles());
	        $this->setView('userdebug/restore.tpl');
	    } else {
	        $myFormContainer = new UserDebugRoles();
	        $myForm = $myFormContainer->getForm();
	        if($myForm->isSubmited() && $myForm->isValid()){
				$user = $this->getUserService()->getCurrentUser();
				$filter = $myForm->getValue('rolefilter');
				$userUri = $myForm->getValue('user');
				if ($userUri != $currentSession->getUserUri()) {
				    throw new \common_exception_Error('Security exception, user to be changed is not the current user');
				}
				$session = new \common_session_RestrictedSession($this->getSession(), $myForm->getValue('rolefilter'));
				\common_session_SessionManager::startSession($session);
				$this->setData('roles', $currentSession->getUserRoles());
				$this->setView('userdebug/restore.tpl');
	        } else {
    	        $this->setData('formTitle'	, __("Restrict Roles"));
    	        $this->setData('myForm'		, $myForm->render());

    	        $this->setView('form.tpl', 'tao');
	        }
	    }
	}
607575
public function roleListAction()
    {
        $roles = $this->roleManager->getAllPlatformRoles();
        $counts = [];

        foreach ($roles as $role) {
            $counts[$role->getName()] = $this->roleManager->countUsersByRoleIncludingGroup($role);
        }

        return array('roles' => $roles, 'counts' => $counts);
    }