PreAuthenticationGuardToken.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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\Guard\Token;
  11. use Symfony\Component\Security\Core\Authentication\Token\AbstractToken;
  12. /**
  13. * The token used by the guard auth system before authentication.
  14. *
  15. * The GuardAuthenticationListener creates this, which is then consumed
  16. * immediately by the GuardAuthenticationProvider. If authentication is
  17. * successful, a different authenticated token is returned
  18. *
  19. * @author Ryan Weaver <ryan@knpuniversity.com>
  20. */
  21. class PreAuthenticationGuardToken extends AbstractToken implements GuardTokenInterface
  22. {
  23. private $credentials;
  24. private $guardProviderKey;
  25. /**
  26. * @param mixed $credentials
  27. * @param string $guardProviderKey Unique key that bind this token to a specific AuthenticatorInterface
  28. */
  29. public function __construct($credentials, string $guardProviderKey)
  30. {
  31. $this->credentials = $credentials;
  32. $this->guardProviderKey = $guardProviderKey;
  33. parent::__construct([]);
  34. // never authenticated
  35. parent::setAuthenticated(false);
  36. }
  37. public function getGuardProviderKey()
  38. {
  39. return $this->guardProviderKey;
  40. }
  41. /**
  42. * Returns the user credentials, which might be an array of anything you
  43. * wanted to put in there (e.g. username, password, favoriteColor).
  44. *
  45. * @return mixed The user credentials
  46. */
  47. public function getCredentials()
  48. {
  49. return $this->credentials;
  50. }
  51. public function setAuthenticated(bool $authenticated)
  52. {
  53. throw new \LogicException('The PreAuthenticationGuardToken is *never* authenticated.');
  54. }
  55. }