src/Security/OauthUserChecker.php line 22

Open in your IDE?
  1. <?php
  2. namespace App\Security;
  3. use Symfony\Component\HttpFoundation\RequestStack;
  4. use Symfony\Component\Security\Core\Exception\AccountExpiredException;
  5. use Symfony\Component\Security\Core\Exception\CustomUserMessageAccountStatusException;
  6. use Symfony\Component\Security\Core\Exception\DisabledException;
  7. use Symfony\Component\Security\Core\User\UserCheckerInterface;
  8. use Symfony\Component\Security\Core\User\UserInterface;
  9. class OauthUserChecker implements UserCheckerInterface
  10. {
  11.     private $requestStack;
  12.     public function __construct(RequestStack $requestStack)
  13.     {
  14.         $this->requestStack $requestStack;
  15.     }
  16.     public function checkPreAuth(UserInterface $user)
  17.     {
  18.         if (!$user->isEnabled()) {
  19.             $ex = new CustomUserMessageAccountStatusException("Account is disabled.");
  20.             $ex->setUser($user);
  21.             throw $ex;
  22.         }
  23.     }
  24.     public function checkPostAuth(UserInterface $user)
  25.     {
  26.         if(
  27.             is_array($user->getWhitelistedIps()) &&
  28.             sizeof($user->getWhitelistedIps()) &&
  29.             !in_array($this->requestStack->getCurrentRequest()->getClientIp(), $user->getWhitelistedIps())
  30.         ) {
  31. //        throw new CustomUserMessageAccountStatusException('User Inactive');
  32.             $ex = new CustomUserMessageAccountStatusException("IP address not authorised for access.");
  33.             $ex->setUser($user);
  34.             throw $ex;
  35.         }
  36.     }
  37. }