コード例 #1
0
 /**
  * Removes a role from this repository.
  *
  * @param \TYPO3\Flow\Security\Policy\Role $role The role to remove
  * @return void
  */
 public function remove($role)
 {
     if (isset($this->newRoles[$role->getIdentifier()])) {
         unset($this->newRoles[$role->getIdentifier()]);
     }
     parent::remove($role);
 }
コード例 #2
0
 /**
  * @test
  */
 public function setRolesWorks()
 {
     $roles = array($this->administratorRole, $this->customerRole);
     $expectedRoles = array($this->administratorRole->getIdentifier() => $this->administratorRole, $this->customerRole->getIdentifier() => $this->customerRole);
     $this->account->setRoles($roles);
     $this->assertSame($expectedRoles, $this->account->getRoles());
 }
コード例 #3
0
 /**
  * Adds a role to this account
  *
  * @param Role $role
  * @return void
  * @throws \InvalidArgumentException
  * @api
  */
 public function addRole(Role $role)
 {
     if ($role->isAbstract()) {
         throw new \InvalidArgumentException(sprintf('Abstract roles can\'t be assigned to accounts directly, but the role "%s" is marked abstract', $role->getIdentifier()), 1399900657);
     }
     $this->initializeRoles();
     if (!$this->hasRole($role)) {
         $roleIdentifier = $role->getIdentifier();
         $this->roleIdentifiers[] = $roleIdentifier;
         $this->roles[$roleIdentifier] = $role;
     }
 }
コード例 #4
0
 /**
  * Returns TRUE if the given role is a directly assigned parent of this role.
  *
  * @param Role $role
  * @return boolean
  */
 public function hasParentRole(Role $role)
 {
     return isset($this->parentRoles[$role->getIdentifier()]);
 }
コード例 #5
0
 /**
  * Parses the global policy configuration and initializes roles and privileges accordingly
  *
  * @return void
  * @throws SecurityException
  */
 protected function initialize()
 {
     if ($this->initialized) {
         return;
     }
     $this->policyConfiguration = $this->configurationManager->getConfiguration(ConfigurationManager::CONFIGURATION_TYPE_POLICY);
     $this->emitConfigurationLoaded($this->policyConfiguration);
     $this->initializePrivilegeTargets();
     $privilegeTargetsForEverybody = $this->privilegeTargets;
     $this->roles = array();
     $everybodyRole = new Role('TYPO3.Flow:Everybody');
     $everybodyRole->setAbstract(true);
     if (isset($this->policyConfiguration['roles'])) {
         foreach ($this->policyConfiguration['roles'] as $roleIdentifier => $roleConfiguration) {
             if ($roleIdentifier === 'TYPO3.Flow:Everybody') {
                 $role = $everybodyRole;
             } else {
                 $role = new Role($roleIdentifier);
                 if (isset($roleConfiguration['abstract'])) {
                     $role->setAbstract((bool) $roleConfiguration['abstract']);
                 }
             }
             if (isset($roleConfiguration['privileges'])) {
                 foreach ($roleConfiguration['privileges'] as $privilegeConfiguration) {
                     $privilegeTargetIdentifier = $privilegeConfiguration['privilegeTarget'];
                     if (!isset($this->privilegeTargets[$privilegeTargetIdentifier])) {
                         throw new SecurityException(sprintf('privilege target "%s", referenced in role configuration "%s" is not defined!', $privilegeTargetIdentifier, $roleIdentifier), 1395869320);
                     }
                     $privilegeTarget = $this->privilegeTargets[$privilegeTargetIdentifier];
                     if (!isset($privilegeConfiguration['permission'])) {
                         throw new SecurityException(sprintf('No permission set for privilegeTarget "%s" in Role "%s"', $privilegeTargetIdentifier, $roleIdentifier), 1395869331);
                     }
                     $privilegeParameters = isset($privilegeConfiguration['parameters']) ? $privilegeConfiguration['parameters'] : array();
                     try {
                         $privilege = $privilegeTarget->createPrivilege($privilegeConfiguration['permission'], $privilegeParameters);
                     } catch (\Exception $exception) {
                         throw new SecurityException(sprintf('Error for privilegeTarget "%s" in Role "%s": %s', $privilegeTargetIdentifier, $roleIdentifier, $exception->getMessage()), 1401886654, $exception);
                     }
                     $role->addPrivilege($privilege);
                     if ($roleIdentifier === 'TYPO3.Flow:Everybody') {
                         unset($privilegeTargetsForEverybody[$privilegeTargetIdentifier]);
                     }
                 }
             }
             $this->roles[$roleIdentifier] = $role;
         }
     }
     // create ABSTAIN privilege for all uncovered privilegeTargets
     /** @var PrivilegeTarget $privilegeTarget */
     foreach ($privilegeTargetsForEverybody as $privilegeTarget) {
         if ($privilegeTarget->hasParameters()) {
             continue;
         }
         $everybodyRole->addPrivilege($privilegeTarget->createPrivilege(PrivilegeInterface::ABSTAIN));
     }
     $this->roles['TYPO3.Flow:Everybody'] = $everybodyRole;
     // Set parent roles
     /** @var Role $role */
     foreach ($this->roles as $role) {
         if (isset($this->policyConfiguration['roles'][$role->getIdentifier()]['parentRoles'])) {
             foreach ($this->policyConfiguration['roles'][$role->getIdentifier()]['parentRoles'] as $parentRoleIdentifier) {
                 $role->addParentRole($this->roles[$parentRoleIdentifier]);
             }
         }
     }
     $this->emitRolesInitialized($this->roles);
     $this->initialized = true;
 }
コード例 #6
0
 /**
  * Returns the privilege a specific role has for the given resource.
  * Note: Resources with runtime evaluations return always a PRIVILEGE_DENY!
  * @see getPrivilegesForJoinPoint() instead, if you need privileges for them.
  *
  * @param \TYPO3\Flow\Security\Policy\Role $role The role for which the privileges should be returned
  * @param string $resource The resource for which the privileges should be returned
  * @return integer One of: PRIVILEGE_GRANT, PRIVILEGE_DENY
  * @throws \TYPO3\Flow\Security\Exception\NoEntryInPolicyException
  */
 public function getPrivilegeForResource(\TYPO3\Flow\Security\Policy\Role $role, $resource)
 {
     if (!isset($this->acls[$resource])) {
         if (isset($this->resources[$resource])) {
             return self::PRIVILEGE_DENY;
         } else {
             throw new \TYPO3\Flow\Security\Exception\NoEntryInPolicyException('The given resource ("' . $resource . '") was not found in the policy cache. Most likely you have to recreate the AOP proxy classes.', 1248348214);
         }
     }
     $roleIdentifier = $role->getIdentifier();
     if (!array_key_exists($roleIdentifier, $this->acls[$resource])) {
         return NULL;
     }
     if ($this->acls[$resource][$roleIdentifier]['runtimeEvaluationsClosureCode'] !== FALSE) {
         return self::PRIVILEGE_DENY;
     }
     return $this->acls[$resource][$roleIdentifier]['privilege'];
 }