vendor/symfony/security-core/Authentication/Provider/RememberMeAuthenticationProvider.php line 22

Open in your IDE?
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <[email protected]>
  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\RememberMeToken;
  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. use Symfony\Component\Security\Core\Exception\LogicException;
  16. use Symfony\Component\Security\Core\User\UserCheckerInterface;
  17. use Symfony\Component\Security\Core\User\UserInterface;
  18. trigger_deprecation('symfony/security-core', '5.3', 'The "%s" class is deprecated, use the new authenticator system instead.', RememberMeAuthenticationProvider::class);
  19. /**
  20. * @deprecated since Symfony 5.3, use the new authenticator system instead
  21. */
  22. class RememberMeAuthenticationProvider implements AuthenticationProviderInterface
  23. {
  24. private $userChecker;
  25. private $secret;
  26. private $providerKey;
  27. /**
  28. * @param string $secret A secret
  29. * @param string $providerKey A provider secret
  30. */
  31. public function __construct(UserCheckerInterface $userChecker, string $secret, string $providerKey)
  32. {
  33. $this->userChecker = $userChecker;
  34. $this->secret = $secret;
  35. $this->providerKey = $providerKey;
  36. }
  37. /**
  38. * {@inheritdoc}
  39. */
  40. public function authenticate(TokenInterface $token)
  41. {
  42. if (!$this->supports($token)) {
  43. throw new AuthenticationException('The token is not supported by this authentication provider.');
  44. }
  45. if ($this->secret !== $token->getSecret()) {
  46. throw new BadCredentialsException('The presented secret does not match.');
  47. }
  48. $user = $token->getUser();
  49. if (!$user instanceof UserInterface) {
  50. throw new LogicException(sprintf('Method "%s::getUser()" must return a "%s" instance, "%s" returned.', get_debug_type($token), UserInterface::class, get_debug_type($user)));
  51. }
  52. $this->userChecker->checkPreAuth($user);
  53. $this->userChecker->checkPostAuth($user);
  54. $authenticatedToken = new RememberMeToken($user, $this->providerKey, $this->secret);
  55. $authenticatedToken->setAttributes($token->getAttributes());
  56. return $authenticatedToken;
  57. }
  58. /**
  59. * {@inheritdoc}
  60. */
  61. public function supports(TokenInterface $token)
  62. {
  63. return $token instanceof RememberMeToken && $token->getFirewallName() === $this->providerKey;
  64. }
  65. }