SwitchUserTokenProcessor.php 1018 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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\Bridge\Monolog\Processor;
  11. use Symfony\Component\Security\Core\Authentication\Token\SwitchUserToken;
  12. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  13. /**
  14. * Adds the original security token to the log entry.
  15. *
  16. * @author Igor Timoshenko <igor.timoshenko@i.ua>
  17. */
  18. class SwitchUserTokenProcessor extends AbstractTokenProcessor
  19. {
  20. /**
  21. * {@inheritdoc}
  22. */
  23. protected function getKey(): string
  24. {
  25. return 'impersonator_token';
  26. }
  27. /**
  28. * {@inheritdoc}
  29. */
  30. protected function getToken(): ?TokenInterface
  31. {
  32. $token = $this->tokenStorage->getToken();
  33. if ($token instanceof SwitchUserToken) {
  34. return $token->getOriginalToken();
  35. }
  36. return null;
  37. }
  38. }