lib/Common/PimcoreUtil/Entity/Base/AbstractSessionAuthenticator.php line 21

Open in your IDE?
  1. <?php
  2. namespace Common\PimcoreUtil\Entity\Base;
  3. use Common\PimcoreHelper\ControllerHelper\ResponseMaker;
  4. use Common\PimcoreUtil\SessionUtil\Session;
  5. use Symfony\Component\HttpFoundation\Request;
  6. use Symfony\Component\HttpFoundation\Response;
  7. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  8. use Symfony\Component\Security\Core\Exception\AuthenticationException;
  9. use Symfony\Component\Security\Core\User\UserInterface;
  10. use Symfony\Component\Security\Core\User\UserProviderInterface;
  11. use Symfony\Component\Security\Guard\AbstractGuardAuthenticator;
  12. abstract class AbstractSessionAuthenticator extends AbstractGuardAuthenticator{
  13.     abstract static function getSession():Session;
  14.     public function start(Request $request,AuthenticationException $authException=null):Response{
  15.         return ResponseMaker::makeStrResponse('no user found');
  16.     }
  17.     public function supports(Request $request):bool{
  18.         return static::getSession()->has('identifier');
  19.     }
  20.     public function getCredentials(Request $request):string{
  21.         return static::getSession()->get('identifier','');
  22.     }
  23.     public function getUser(mixed $credentials,UserProviderInterface $userProvider):UserInterface{
  24.         return $userProvider->loadUserByUsername($credentials);
  25.     }
  26.     public function checkCredentials(mixed $credentials,UserInterface $user):bool{
  27.         return true;
  28.     }
  29.     public function onAuthenticationFailure(Request $request,AuthenticationException $exception):Response{
  30.         return ResponseMaker::makeJsonResponse(['info'=>'authentication failure']);
  31.     }
  32.     public function onAuthenticationSuccess(Request $request,TokenInterface $token,string $providerKey):?Response{
  33.         return null;
  34.     }
  35.     public function supportsRememberMe():bool{
  36.         return true;
  37.     }
  38. }