vendor/symfony/security/Core/Authentication/Provider/SimpleAuthenticationProvider.php line 22

Open in your IDE?
  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\Provider;
  11. use Symfony\Component\Security\Core\Authentication\SimpleAuthenticatorInterface;
  12. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  13. use Symfony\Component\Security\Core\Exception\AuthenticationException;
  14. use Symfony\Component\Security\Core\User\UserChecker;
  15. use Symfony\Component\Security\Core\User\UserCheckerInterface;
  16. use Symfony\Component\Security\Core\User\UserInterface;
  17. use Symfony\Component\Security\Core\User\UserProviderInterface;
  18. @trigger_error(sprintf('The "%s" class is deprecated since Symfony 4.2, use Guard instead.'SimpleAuthenticationProvider::class), \E_USER_DEPRECATED);
  19. /**
  20.  * @author Jordi Boggiano <j.boggiano@seld.be>
  21.  *
  22.  * @deprecated since Symfony 4.2, use Guard instead.
  23.  */
  24. class SimpleAuthenticationProvider implements AuthenticationProviderInterface
  25. {
  26.     private $simpleAuthenticator;
  27.     private $userProvider;
  28.     private $providerKey;
  29.     private $userChecker;
  30.     public function __construct(SimpleAuthenticatorInterface $simpleAuthenticatorUserProviderInterface $userProviderstring $providerKeyUserCheckerInterface $userChecker null)
  31.     {
  32.         $this->simpleAuthenticator $simpleAuthenticator;
  33.         $this->userProvider $userProvider;
  34.         $this->providerKey $providerKey;
  35.         $this->userChecker $userChecker ?? new UserChecker();
  36.     }
  37.     public function authenticate(TokenInterface $token)
  38.     {
  39.         $authToken $this->simpleAuthenticator->authenticateToken($token$this->userProvider$this->providerKey);
  40.         if (!$authToken instanceof TokenInterface) {
  41.             throw new AuthenticationException('Simple authenticator failed to return an authenticated token.');
  42.         }
  43.         $user $authToken->getUser();
  44.         if (!$user instanceof UserInterface) {
  45.             return $authToken;
  46.         }
  47.         $this->userChecker->checkPreAuth($user);
  48.         $this->userChecker->checkPostAuth($user);
  49.         return $authToken;
  50.     }
  51.     public function supports(TokenInterface $token)
  52.     {
  53.         return $this->simpleAuthenticator->supportsToken($token$this->providerKey);
  54.     }
  55. }