public function getKey($name)
{
if (strlen($name) === 0) {
throw new SecurityException('Required name argument was empty', 1334215378);
}
$keyPathAndFilename = $this->getKeyPathAndFilename($name);
if (!file_exists($keyPathAndFilename)) {
throw new SecurityException(sprintf('The key "%s" does not exist.', $keyPathAndFilename), 1305812921);
}
$key = Utility\Files::getFileContents($keyPathAndFilename);
if ($key === false) {
throw new SecurityException(sprintf('The key "%s" could not be read.', $keyPathAndFilename), 1334483163);
}
if (strlen($key) === 0) {
throw new SecurityException(sprintf('The key "%s" is empty.', $keyPathAndFilename), 1334483165);
}
return $key;
}
/** * 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); } }