vendor/pimcore/pimcore/bundles/AdminBundle/Security/User/UserProvider.php line 29

Open in your IDE?
  1. <?php
  2. /**
  3.  * Pimcore
  4.  *
  5.  * This source file is available under two different licenses:
  6.  * - GNU General Public License version 3 (GPLv3)
  7.  * - Pimcore Commercial License (PCL)
  8.  * Full copyright and license information is available in
  9.  * LICENSE.md which is distributed with this source code.
  10.  *
  11.  *  @copyright  Copyright (c) Pimcore GmbH (http://www.pimcore.org)
  12.  *  @license    http://www.pimcore.org/license     GPLv3 and PCL
  13.  */
  14. namespace Pimcore\Bundle\AdminBundle\Security\User;
  15. use Pimcore\Model\User as PimcoreUser;
  16. use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
  17. use Symfony\Component\Security\Core\Exception\UserNotFoundException;
  18. use Symfony\Component\Security\Core\User\UserInterface;
  19. use Symfony\Component\Security\Core\User\UserProviderInterface;
  20. class UserProvider implements UserProviderInterface
  21. {
  22.     /**
  23.      * {@inheritdoc}
  24.      */
  25.     public function loadUserByIdentifier(string $username): UserInterface
  26.     {
  27.         $pimcoreUser PimcoreUser::getByName($username);
  28.         if ($pimcoreUser) {
  29.             return new User($pimcoreUser);
  30.         }
  31.         throw new UserNotFoundException(sprintf('User %s was not found'$username));
  32.     }
  33.     /**
  34.      * {@inheritdoc}
  35.      *
  36.      * @deprecated use loadUserByIdentifier() instead.
  37.      */
  38.     public function loadUserByUsername($identifier)
  39.     {
  40.         return $this->loadUserByIdentifier($identifier);
  41.     }
  42.     /**
  43.      * {@inheritdoc}
  44.      *
  45.      * @param UserInterface $user
  46.      *
  47.      * @return UserInterface
  48.      */
  49.     public function refreshUser(UserInterface $user)//: UserInterface
  50.     {
  51.         if (!$user instanceof User) {
  52.             // user is not supported - we only support pimcore users
  53.             throw new UnsupportedUserException();
  54.         }
  55.         /** @var PimcoreUser $refreshedPimcoreUser */
  56.         $refreshedPimcoreUser PimcoreUser::getById($user->getId());
  57.         return $this->buildUser($refreshedPimcoreUser);
  58.     }
  59.     /**
  60.      * @param PimcoreUser $pimcoreUser
  61.      *
  62.      * @return User
  63.      */
  64.     protected function buildUser(PimcoreUser $pimcoreUser)
  65.     {
  66.         return new User($pimcoreUser);
  67.     }
  68.     /**
  69.      * {@inheritdoc}
  70.      *
  71.      * @return bool
  72.      */
  73.     public function supportsClass($class)//: bool
  74.     {
  75.         return $class === User::class;
  76.     }
  77. }