vendor/symfony/security-http/EventListener/UserProviderListener.php line 35

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\Http\EventListener;
  11. use Symfony\Component\Security\Core\User\UserProviderInterface;
  12. use Symfony\Component\Security\Http\Authenticator\Passport\Badge\UserBadge;
  13. use Symfony\Component\Security\Http\Event\CheckPassportEvent;
  14. /**
  15. * Configures the user provider as user loader, if no user load
  16. * has been explicitly set.
  17. *
  18. * @author Wouter de Jong <[email protected]>
  19. *
  20. * @final
  21. */
  22. class UserProviderListener
  23. {
  24. private $userProvider;
  25. public function __construct(UserProviderInterface $userProvider)
  26. {
  27. $this->userProvider = $userProvider;
  28. }
  29. public function checkPassport(CheckPassportEvent $event): void
  30. {
  31. $passport = $event->getPassport();
  32. if (!$passport->hasBadge(UserBadge::class)) {
  33. return;
  34. }
  35. /** @var UserBadge $badge */
  36. $badge = $passport->getBadge(UserBadge::class);
  37. if (null !== $badge->getUserLoader()) {
  38. return;
  39. }
  40. // @deprecated since Symfony 5.3, change to $this->userProvider->loadUserByIdentifier() in 6.0
  41. if (method_exists($this->userProvider, 'loadUserByIdentifier')) {
  42. $badge->setUserLoader([$this->userProvider, 'loadUserByIdentifier']);
  43. } else {
  44. trigger_deprecation('symfony/security-http', '5.3', 'Not implementing method "loadUserByIdentifier()" in user provider "%s" is deprecated. This method will replace "loadUserByUsername()" in Symfony 6.0.', get_debug_type($this->userProvider));
  45. $badge->setUserLoader([$this->userProvider, 'loadUserByUsername']);
  46. }
  47. }
  48. }