Example #1
0
 /**
  * Construct a user
  */
 public function __construct()
 {
     parent::__construct();
     $account = new \TYPO3\FLOW3\Security\Account();
     $account->setAuthenticationProviderName('AdminInterfaceProvider');
     $this->addAccount($account);
 }
 /**
  * Returns the currently valid roles.
  *
  * @return array Array of TYPO3\FLOW3\Security\Authentication\Role objects
  * @author Andreas Förthner <*****@*****.**>
  */
 public function getRoles()
 {
     if ($this->account !== NULL && $this->isAuthenticated()) {
         return $this->account->getRoles();
     }
     return array();
 }
Example #3
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;
 }
Example #4
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();
 }
Example #5
0
 /**
  * Creates a new account, assigns it the given roles and authenticates it.
  * The created account is returned for further modification, for example for attaching a Party object to it.
  *
  * @param array $roleNames A list of roles the new account should have
  * @return \TYPO3\FLOW3\Security\Account The created account
  * @api
  */
 protected function authenticateRoles(array $roleNames)
 {
     $account = new \TYPO3\FLOW3\Security\Account();
     $roles = array();
     foreach ($roleNames as $roleName) {
         $roles[] = new \TYPO3\FLOW3\Security\Policy\Role($roleName);
     }
     $account->setRoles($roles);
     $this->authenticateAccount($account);
     return $account;
 }