vendor/symfony/security/Core/User/UserChecker.php line 36

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\User;
  11. use Symfony\Component\Security\Core\Exception\AccountExpiredException;
  12. use Symfony\Component\Security\Core\Exception\CredentialsExpiredException;
  13. use Symfony\Component\Security\Core\Exception\DisabledException;
  14. use Symfony\Component\Security\Core\Exception\LockedException;
  15. /**
  16.  * UserChecker checks the user account flags.
  17.  *
  18.  * @author Fabien Potencier <fabien@symfony.com>
  19.  */
  20. class UserChecker implements UserCheckerInterface
  21. {
  22.     /**
  23.      * {@inheritdoc}
  24.      */
  25.     public function checkPreAuth(UserInterface $user)
  26.     {
  27.         if (!$user instanceof AdvancedUserInterface && !$user instanceof User) {
  28.             return;
  29.         }
  30.         if ($user instanceof AdvancedUserInterface && !$user instanceof User) {
  31.             @trigger_error(sprintf('Calling "%s()" with an AdvancedUserInterface is deprecated since Symfony 4.1. Create a custom user checker if you wish to keep this functionality.'__METHOD__), E_USER_DEPRECATED);
  32.         }
  33.         if (!$user->isAccountNonLocked()) {
  34.             $ex = new LockedException('User account is locked.');
  35.             $ex->setUser($user);
  36.             throw $ex;
  37.         }
  38.         if (!$user->isEnabled()) {
  39.             $ex = new DisabledException('User account is disabled.');
  40.             $ex->setUser($user);
  41.             throw $ex;
  42.         }
  43.         if (!$user->isAccountNonExpired()) {
  44.             $ex = new AccountExpiredException('User account has expired.');
  45.             $ex->setUser($user);
  46.             throw $ex;
  47.         }
  48.     }
  49.     /**
  50.      * {@inheritdoc}
  51.      */
  52.     public function checkPostAuth(UserInterface $user)
  53.     {
  54.         if (!$user instanceof AdvancedUserInterface && !$user instanceof User) {
  55.             return;
  56.         }
  57.         if ($user instanceof AdvancedUserInterface && !$user instanceof User) {
  58.             @trigger_error(sprintf('Calling "%s()" with an AdvancedUserInterface is deprecated since Symfony 4.1. Create a custom user checker if you wish to keep this functionality.'__METHOD__), E_USER_DEPRECATED);
  59.         }
  60.         if (!$user->isCredentialsNonExpired()) {
  61.             $ex = new CredentialsExpiredException('User credentials have expired.');
  62.             $ex->setUser($user);
  63.             throw $ex;
  64.         }
  65.     }
  66. }