getRoles() public method

Returns an array of all configured roles
public getRoles ( boolean $includeAbstract = false ) : Role[]
$includeAbstract boolean If TRUE the result includes abstract roles, otherwise those will be skipped
return Role[] Array of all configured roles, indexed by role identifier
コード例 #1
0
 /**
  * Lists all public controller actions not covered by the active security policy
  *
  * @return void
  */
 public function showUnprotectedActionsCommand()
 {
     $methodPrivileges = [];
     foreach ($this->policyService->getRoles(true) as $role) {
         $methodPrivileges = array_merge($methodPrivileges, $role->getPrivilegesByType(MethodPrivilegeInterface::class));
     }
     $controllerClassNames = $this->reflectionService->getAllSubClassNamesForClass(AbstractController::class);
     $allActionsAreProtected = true;
     foreach ($controllerClassNames as $controllerClassName) {
         if ($this->reflectionService->isClassAbstract($controllerClassName)) {
             continue;
         }
         $methodNames = get_class_methods($controllerClassName);
         $foundUnprotectedAction = false;
         foreach ($methodNames as $methodName) {
             if (preg_match('/.*Action$/', $methodName) === 0 || $this->reflectionService->isMethodPublic($controllerClassName, $methodName) === false) {
                 continue;
             }
             /** @var MethodPrivilegeInterface $methodPrivilege */
             foreach ($methodPrivileges as $methodPrivilege) {
                 if ($methodPrivilege->matchesMethod($controllerClassName, $methodName)) {
                     continue 2;
                 }
             }
             if ($foundUnprotectedAction === false) {
                 $this->outputLine(PHP_EOL . '<b>' . $controllerClassName . '</b>');
                 $foundUnprotectedAction = true;
                 $allActionsAreProtected = false;
             }
             $this->outputLine('  ' . $methodName);
         }
     }
     if ($allActionsAreProtected === true) {
         $this->outputLine('All public controller actions are covered by your security policy. Good job!');
     }
 }
コード例 #2
0
 /**
  * @test
  */
 public function getRolesIncludesAbstractRolesIfRequested()
 {
     $this->mockPolicyConfiguration = ['roles' => ['Some.Package:SomeRole' => ['abstract' => true], 'Some.Package:SomeOtherRole' => ['parentRoles' => ['Some.Package:SomeRole']]]];
     $roles = $this->policyService->getRoles(true);
     $this->assertSame(['Some.Package:SomeRole', 'Some.Package:SomeOtherRole', 'Neos.Flow:Everybody'], array_keys($roles));
 }
コード例 #3
0
 /**
  * Edit the given account
  *
  * @param Account $account
  * @return void
  */
 public function editAccountAction(Account $account)
 {
     $this->view->assignMultiple(array('account' => $account, 'user' => $this->userService->getUser($account->getAccountIdentifier(), $account->getAuthenticationProviderName()), 'availableRoles' => $this->policyService->getRoles()));
 }