Neos\Flow\Security\Authentication\Provider\FileBasedSimpleKeyProvider::authenticate PHP Метод

authenticate() публичный Метод

Sets isAuthenticated to TRUE for all tokens.
public authenticate ( Neos\Flow\Security\Authentication\TokenInterface $authenticationToken ) : void
$authenticationToken Neos\Flow\Security\Authentication\TokenInterface The token to be authenticated
Результат void
    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);
        }
    }

Usage Example

 /**
  * @test
  * @expectedException \Neos\Flow\Security\Exception\UnsupportedAuthenticationTokenException
  */
 public function authenticatingAnUnsupportedTokenThrowsAnException()
 {
     $someInvalidToken = $this->createMock(TokenInterface::class);
     $authenticationProvider = new FileBasedSimpleKeyProvider('myProvider');
     $authenticationProvider->authenticate($someInvalidToken);
 }
FileBasedSimpleKeyProvider