public function setUp()
 {
     $this->mockRole = $this->getMockBuilder(Role::class)->disableOriginalConstructor()->getMock();
     $this->mockRole->expects($this->any())->method('getIdentifier')->will($this->returnValue('Neos.Flow:TestRoleIdentifier'));
     $this->mockPolicyService = $this->getMockBuilder(PolicyService::class)->disableOriginalConstructor()->getMock();
     $this->mockPolicyService->expects($this->any())->method('getRole')->with('Neos.Flow:TestRoleIdentifier')->will($this->returnValue($this->mockRole));
     $this->mockHashService = $this->getMockBuilder(HashService::class)->disableOriginalConstructor()->getMock();
     $expectedPassword = $this->testKeyClearText;
     $expectedHashedPasswordAndSalt = $this->testKeyHashed;
     $this->mockHashService->expects($this->any())->method('validatePassword')->will($this->returnCallback(function ($password, $hashedPasswordAndSalt) use($expectedPassword, $expectedHashedPasswordAndSalt) {
         return $hashedPasswordAndSalt === $expectedHashedPasswordAndSalt && $password === $expectedPassword;
     }));
     $this->mockFileBasedSimpleKeyService = $this->getMockBuilder(FileBasedSimpleKeyService::class)->disableOriginalConstructor()->getMock();
     $this->mockFileBasedSimpleKeyService->expects($this->any())->method('getKey')->with('testKey')->will($this->returnValue($this->testKeyHashed));
     $this->mockToken = $this->getMockBuilder(PasswordToken::class)->disableOriginalConstructor()->getMock();
 }
Exemplo n.º 2
0
 /**
  * @param integer $step The requested setup step
  * @return void
  */
 public function loginAction($step = 0)
 {
     if ($this->fileBasedSimpleKeyService->keyExists($this->keyName) === false || file_exists($this->settings['initialPasswordFile'])) {
         $setupPassword = $this->fileBasedSimpleKeyService->generateKey($this->keyName);
         $initialPasswordFileContents = 'The setup password is:' . PHP_EOL;
         $initialPasswordFileContents .= PHP_EOL;
         $initialPasswordFileContents .= $setupPassword . PHP_EOL;
         $initialPasswordFileContents .= PHP_EOL;
         $initialPasswordFileContents .= 'After you successfully logged in, this file is automatically deleted for security reasons.' . PHP_EOL;
         $initialPasswordFileContents .= 'Make sure to save the setup password for later use.' . PHP_EOL;
         $result = file_put_contents($this->settings['initialPasswordFile'], $initialPasswordFileContents);
         if ($result === false) {
             $this->addFlashMessage('It was not possible to save the initial setup password to file "%s". Check file permissions and retry.', 'Password Generation Failure', Message::SEVERITY_ERROR, [$this->settings['initialPasswordFile']]);
         } else {
             $this->view->assign('initialPasswordFile', $this->settings['initialPasswordFile']);
         }
     }
     $this->view->assign('step', $step);
 }
 /**
  * Sets isAuthenticated to TRUE for all tokens.
  *
  * @param TokenInterface $authenticationToken The token to be authenticated
  * @return void
  * @throws UnsupportedAuthenticationTokenException
  */
 public function authenticate(TokenInterface $authenticationToken)
 {
     if (!$authenticationToken instanceof PasswordToken) {
         throw new UnsupportedAuthenticationTokenException('This provider cannot authenticate the given token.', 1217339840);
     }
     $credentials = $authenticationToken->getCredentials();
     if (is_array($credentials) && isset($credentials['password'])) {
         if ($this->hashService->validatePassword($credentials['password'], $this->fileBasedSimpleKeyService->getKey($this->options['keyName']))) {
             $authenticationToken->setAuthenticationStatus(TokenInterface::AUTHENTICATION_SUCCESSFUL);
             $account = new Account();
             $roles = [];
             foreach ($this->options['authenticateRoles'] as $roleIdentifier) {
                 $roles[] = $this->policyService->getRole($roleIdentifier);
             }
             $account->setRoles($roles);
             $authenticationToken->setAccount($account);
         } else {
             $authenticationToken->setAuthenticationStatus(TokenInterface::WRONG_CREDENTIALS);
         }
     } elseif ($authenticationToken->getAuthenticationStatus() !== TokenInterface::AUTHENTICATION_SUCCESSFUL) {
         $authenticationToken->setAuthenticationStatus(TokenInterface::NO_CREDENTIALS_GIVEN);
     }
 }