Ejemplo n.º 1
0
 /**
  * Creates a new account and sets the given password and roles
  *
  * @param string $identifier Identifier of the account, must be unique
  * @param string $password The clear text password
  * @param array $roleIdentifiers Optionally an array of role identifiers to assign to the new account
  * @param string $authenticationProviderName Optional name of the authentication provider the account is affiliated with
  * @param string $passwordHashingStrategy Optional password hashing strategy to use for the password
  * @return \TYPO3\FLOW3\Security\Account A new account, not yet added to the account repository
  */
 public function createAccountWithPassword($identifier, $password, $roleIdentifiers = array(), $authenticationProviderName = 'DefaultProvider', $passwordHashingStrategy = 'default')
 {
     $roles = array();
     foreach ($roleIdentifiers as $roleIdentifier) {
         $roles[] = new \TYPO3\FLOW3\Security\Policy\Role($roleIdentifier);
     }
     $account = new \TYPO3\FLOW3\Security\Account();
     $account->setAccountIdentifier($identifier);
     $account->setCredentialsSource($this->hashService->hashPassword($password, $passwordHashingStrategy));
     $account->setAuthenticationProviderName($authenticationProviderName);
     $account->setRoles($roles);
     return $account;
 }
Ejemplo n.º 2
0
 /**
  * @test
  */
 public function administratorsCanSeeOthersRestrictableEntites()
 {
     $ownAccount = $this->authenticateRoles(array('Administrator', 'Customer'));
     $ownAccount->setAccountIdentifier('ownAccount');
     $ownAccount->setAuthenticationProviderName('SomeProvider');
     $ownAccount->setCredentialsSource('foobar');
     $otherAccount = new \TYPO3\FLOW3\Security\Account();
     $otherAccount->setAccountIdentifier('othersAccount');
     $otherAccount->setAuthenticationProviderName('SomeProvider');
     $otherAccount->setCredentialsSource('foobar');
     $this->persistenceManager->add($ownAccount);
     $this->persistenceManager->add($otherAccount);
     $ownEntity = new Fixtures\RestrictableEntity('ownEntity');
     $ownEntity->setOwnerAccount($ownAccount);
     $othersEntity = new Fixtures\RestrictableEntity('othersEntity');
     $othersEntity->setOwnerAccount($otherAccount);
     $this->restrictableEntityRepository->add($ownEntity);
     $ownEntityIdentifier = $this->persistenceManager->getIdentifierByObject($ownEntity);
     $this->restrictableEntityRepository->add($othersEntity);
     $othersEntityIdentifier = $this->persistenceManager->getIdentifierByObject($othersEntity);
     $this->persistenceManager->persistAll();
     $this->persistenceManager->clearState();
     $result = $this->restrictableEntityRepository->findAll();
     $this->assertTrue(count($result) === 2);
     $this->assertNotNull($this->persistenceManager->getObjectByIdentifier($ownEntityIdentifier, 'TYPO3\\FLOW3\\Tests\\Functional\\Security\\Fixtures\\RestrictableEntity'));
     $this->assertNotNull($this->persistenceManager->getObjectByIdentifier($othersEntityIdentifier, 'TYPO3\\FLOW3\\Tests\\Functional\\Security\\Fixtures\\RestrictableEntity'));
     $this->restrictableEntityRepository->removeAll();
     $this->persistenceManager->persistAll();
     $this->persistenceManager->clearState();
 }