vendor/symfony/security-core/Authentication/Provider/AnonymousAuthenticationProvider.php line 19

Open in your IDE?
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Security\Core\Authentication\Provider;
  11. use Symfony\Component\Security\Core\Authentication\Token\AnonymousToken;
  12. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  13. use Symfony\Component\Security\Core\Exception\AuthenticationException;
  14. use Symfony\Component\Security\Core\Exception\BadCredentialsException;
  15. trigger_deprecation('symfony/security-core', '5.3', 'The "%s" class is deprecated, use the new authenticator system instead.', AnonymousAuthenticationProvider::class);
  16. /**
  17. * AnonymousAuthenticationProvider validates AnonymousToken instances.
  18. *
  19. * @author Fabien Potencier <fabien@symfony.com>
  20. *
  21. * @deprecated since Symfony 5.3, use the new authenticator system instead
  22. */
  23. class AnonymousAuthenticationProvider implements AuthenticationProviderInterface
  24. {
  25. /**
  26. * Used to determine if the token is created by the application
  27. * instead of a malicious client.
  28. *
  29. * @var string
  30. */
  31. private $secret;
  32. /**
  33. * @param string $secret The secret shared with the AnonymousToken
  34. */
  35. public function __construct(string $secret)
  36. {
  37. $this->secret = $secret;
  38. }
  39. /**
  40. * {@inheritdoc}
  41. */
  42. public function authenticate(TokenInterface $token)
  43. {
  44. if (!$this->supports($token)) {
  45. throw new AuthenticationException('The token is not supported by this authentication provider.');
  46. }
  47. if ($this->secret !== $token->getSecret()) {
  48. throw new BadCredentialsException('The Token does not contain the expected key.');
  49. }
  50. return $token;
  51. }
  52. /**
  53. * {@inheritdoc}
  54. */
  55. public function supports(TokenInterface $token)
  56. {
  57. return $token instanceof AnonymousToken;
  58. }
  59. }