app/Plugin/Api42/EventListener/UserResolveListener.php line 45

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of EC-CUBE
  4.  *
  5.  * Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
  6.  *
  7.  * http://www.ec-cube.co.jp/
  8.  *
  9.  * For the full copyright and license information, please view the LICENSE
  10.  * file that was distributed with this source code.
  11.  */
  12. namespace Plugin\Api42\EventListener;
  13. use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
  14. use Symfony\Component\Security\Core\User\UserProviderInterface;
  15. use League\Bundle\OAuth2ServerBundle\Event\UserResolveEvent;
  16. final class UserResolveListener
  17. {
  18.     /**
  19.      * @var UserProviderInterface
  20.      */
  21.     private $userProvider;
  22.     /**
  23.      * @var UserPasswordEncoderInterface
  24.      */
  25.     private $userPasswordEncoder;
  26.     /**
  27.      * @param UserProviderInterface $userProvider
  28.      * @param UserPasswordEncoderInterface $userPasswordEncoder
  29.      */
  30.     public function __construct(UserProviderInterface $userProviderUserPasswordEncoderInterface $userPasswordEncoder)
  31.     {
  32.         $this->userProvider $userProvider;
  33.         $this->userPasswordEncoder $userPasswordEncoder;
  34.     }
  35.     /**
  36.      * @param UserResolveEvent $event
  37.      */
  38.     public function onUserResolve(UserResolveEvent $event): void
  39.     {
  40.         $user $this->userProvider->loadUserByUsername($event->getUsername());
  41.         if (null === $user) {
  42.             return;
  43.         }
  44.         if (!$this->userPasswordEncoder->isPasswordValid($user$event->getPassword())) {
  45.             return;
  46.         }
  47.         $event->setUser($user);
  48.     }
  49. }