AbstractGuardAuthenticator.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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;
  11. use Symfony\Component\Security\Core\User\UserInterface;
  12. use Symfony\Component\Security\Guard\Token\PostAuthenticationGuardToken;
  13. /**
  14. * An optional base class that creates a PostAuthenticationGuardToken for you.
  15. *
  16. * @author Ryan Weaver <ryan@knpuniversity.com>
  17. */
  18. abstract class AbstractGuardAuthenticator implements GuardAuthenticatorInterface
  19. {
  20. /**
  21. * Shortcut to create a PostAuthenticationGuardToken for you, if you don't really
  22. * care about which authenticated token you're using.
  23. *
  24. * @param UserInterface $user
  25. * @param string $providerKey
  26. *
  27. * @return PostAuthenticationGuardToken
  28. */
  29. public function createAuthenticatedToken(UserInterface $user, $providerKey)
  30. {
  31. return new PostAuthenticationGuardToken(
  32. $user,
  33. $providerKey,
  34. $user->getRoles()
  35. );
  36. }
  37. }