AuthenticationTrustResolver.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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;
  11. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  12. /**
  13. * The default implementation of the authentication trust resolver.
  14. *
  15. * @author Johannes M. Schmitt <schmittjoh@gmail.com>
  16. */
  17. class AuthenticationTrustResolver implements AuthenticationTrustResolverInterface
  18. {
  19. private $anonymousClass;
  20. private $rememberMeClass;
  21. /**
  22. * @param string $anonymousClass
  23. * @param string $rememberMeClass
  24. */
  25. public function __construct($anonymousClass, $rememberMeClass)
  26. {
  27. $this->anonymousClass = $anonymousClass;
  28. $this->rememberMeClass = $rememberMeClass;
  29. }
  30. /**
  31. * {@inheritdoc}
  32. */
  33. public function isAnonymous(TokenInterface $token = null)
  34. {
  35. if (null === $token) {
  36. return false;
  37. }
  38. return $token instanceof $this->anonymousClass;
  39. }
  40. /**
  41. * {@inheritdoc}
  42. */
  43. public function isRememberMe(TokenInterface $token = null)
  44. {
  45. if (null === $token) {
  46. return false;
  47. }
  48. return $token instanceof $this->rememberMeClass;
  49. }
  50. /**
  51. * {@inheritdoc}
  52. */
  53. public function isFullFledged(TokenInterface $token = null)
  54. {
  55. if (null === $token) {
  56. return false;
  57. }
  58. return !$this->isAnonymous($token) && !$this->isRememberMe($token);
  59. }
  60. }