private function initRoles() { if (!$this->policyService->hasRole('DLigo.Animaltool:Admin')) { $this->policyService->createRole('DLigo.Animaltool:Admin'); } if (!$this->policyService->hasRole('DLigo.Animaltool:Catcher')) { $this->policyService->createRole('DLigo.Animaltool:Catcher'); } if (!$this->policyService->hasRole('DLigo.Animaltool:Doctor')) { $this->policyService->createRole('DLigo.Animaltool:Doctor'); } }
/** * Returns Collection of roles. * * @param string $providerName Provider name to fetch roles from. * @param array $casAttributes * * @throws \Exception * @throws Exception\WrongMappingConfigurationException * * @return \Doctrine\Common\Collections\Collection<\TYPO3\Flow\Security\Policy\Role> */ public function getRoles($providerName, array $casAttributes) { $rolesSettings = $this->settings[$providerName]['Roles']; $rolesCollection = new ArrayCollection(); $iterator = 0; foreach ($rolesSettings as $roleSettings) { // Map Cas Attributes if (empty($roleSettings['staticIdentifier']) && !empty($roleSettings['identifier']) && is_string($roleSettings['identifier'])) { $roleIdentifier = ArraysUtility::getValueByPath($casAttributes, $roleSettings['identifier']); if (!is_string($roleIdentifier) && !is_int($roleIdentifier)) { throw new WrongMappingConfigurationException(sprintf('Cas attribute catched by path "%s" from CAS-Attributes array defined at ....%s.providerOptions.Mapping.Roles.%s.identifier must be a string but "%s" is given.', $roleSettings['identifier'], $providerName, $iterator, gettype($roleIdentifier)), 1371209193); } if (isset($roleSettings['rewriteRoles'])) { $roleIdentifier = $this->rewriteRole($roleIdentifier, $roleSettings['rewriteRoles']); } } // Map static Role if (isset($roleSettings['staticIdentifier']) && is_string($roleSettings['staticIdentifier'])) { $roleIdentifier = $roleSettings['staticIdentifier']; if (isset($roleSettings['rewriteRoles'])) { $roleIdentifier = $this->rewriteRole($roleIdentifier, $roleSettings['rewriteRoles']); } } if (is_string($roleIdentifier) || is_int($roleIdentifier)) { try { $role = $this->policyService->getRole($roleSettings['packageKey'] . ':' . $roleIdentifier); } catch (NoSuchRoleException $exc) { /* @var $exc \Exception */ if ($exc->getCode() === 1353085860) { $role = $this->policyService->createRole($roleSettings['packageKey'] . ':' . $roleIdentifier); } else { throw new \Exception('Unknown exception by PolicyService->getRole(). Message: ' . $exc->getMessage() . ' Code: ' . $exc->getCode(), 1371211532); } } } $rolesCollection->add($role); $iterator++; } return $rolesCollection; }