/**
  * 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\Flow\Security\Account A new account, not yet added to the account repository
  */
 public function createAccountWithPassword($identifier, $password, $roleIdentifiers = array(), $authenticationProviderName = 'DefaultProvider', $passwordHashingStrategy = 'default')
 {
     $account = new \TYPO3\Flow\Security\Account();
     $account->setAccountIdentifier($identifier);
     $account->setCredentialsSource($this->hashService->hashPassword($password, $passwordHashingStrategy));
     $account->setAuthenticationProviderName($authenticationProviderName);
     $roles = array();
     foreach ($roleIdentifiers as $roleIdentifier) {
         $roles[] = $this->policyService->getRole($roleIdentifier);
     }
     $account->setRoles($roles);
     return $account;
 }
 /**
  * @test
  */
 public function administratorsCanSeeOthersRestrictableEntites()
 {
     $ownAccount = $this->authenticateRoles(array('TYPO3.Flow:Administrator', 'TYPO3.Flow:Customer'));
     $ownAccount->setAccountIdentifier('ownAccount');
     $ownAccount->setAuthenticationProviderName('SomeProvider');
     $ownAccount->setCredentialsSource('foobar');
     $otherAccount = new \TYPO3\Flow\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\\Flow\\Tests\\Functional\\Security\\Fixtures\\RestrictableEntity'));
     $this->assertNotNull($this->persistenceManager->getObjectByIdentifier($othersEntityIdentifier, 'TYPO3\\Flow\\Tests\\Functional\\Security\\Fixtures\\RestrictableEntity'));
     $this->restrictableEntityRepository->removeAll();
     $this->persistenceManager->persistAll();
     $this->persistenceManager->clearState();
 }