<?php
namespace Common\PimcoreUtil\Entity\Base;
use Common\PimcoreHelper\ControllerHelper\ResponseMaker;
use Common\PimcoreUtil\SessionUtil\Session;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Exception\AuthenticationException;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Core\User\UserProviderInterface;
use Symfony\Component\Security\Guard\AbstractGuardAuthenticator;
abstract class AbstractSessionAuthenticator extends AbstractGuardAuthenticator{
abstract static function getSession():Session;
public function start(Request $request,AuthenticationException $authException=null):Response{
return ResponseMaker::makeStrResponse('no user found');
}
public function supports(Request $request):bool{
return static::getSession()->has('identifier');
}
public function getCredentials(Request $request):string{
return static::getSession()->get('identifier','');
}
public function getUser(mixed $credentials,UserProviderInterface $userProvider):UserInterface{
return $userProvider->loadUserByUsername($credentials);
}
public function checkCredentials(mixed $credentials,UserInterface $user):bool{
return true;
}
public function onAuthenticationFailure(Request $request,AuthenticationException $exception):Response{
return ResponseMaker::makeJsonResponse(['info'=>'authentication failure']);
}
public function onAuthenticationSuccess(Request $request,TokenInterface $token,string $providerKey):?Response{
return null;
}
public function supportsRememberMe():bool{
return true;
}
}