55 lines
1.8 KiB
PHP
55 lines
1.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace KupShop\UserBundle\Security;
|
|
|
|
use Symfony\Component\HttpFoundation\RedirectResponse;
|
|
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\Http\Authenticator\AbstractAuthenticator;
|
|
use Symfony\Component\Security\Http\Authenticator\InteractiveAuthenticatorInterface;
|
|
use Symfony\Component\Security\Http\Authenticator\Passport\Passport;
|
|
use Symfony\Component\Security\Http\EntryPoint\AuthenticationEntryPointInterface;
|
|
|
|
class CustomAuthenticator extends AbstractAuthenticator implements AuthenticationEntryPointInterface, InteractiveAuthenticatorInterface
|
|
{
|
|
public function authenticate(Request $request): Passport
|
|
{
|
|
throw new \RuntimeException('Custom authenticator is not implemented');
|
|
}
|
|
|
|
public function onAuthenticationFailure(Request $request, AuthenticationException $exception): ?Response
|
|
{
|
|
// next authenticator is called when `null` is returned
|
|
return null;
|
|
}
|
|
|
|
public function onAuthenticationSuccess(Request $request, TokenInterface $token, string $firewallName): ?Response
|
|
{
|
|
return null;
|
|
}
|
|
|
|
protected function getLoginUrl(Request $request): string
|
|
{
|
|
return path('kupshop_user_login_login');
|
|
}
|
|
|
|
public function supports(Request $request): bool
|
|
{
|
|
return false;
|
|
}
|
|
|
|
public function start(Request $request, ?AuthenticationException $authException = null): Response
|
|
{
|
|
return new RedirectResponse($this->getLoginUrl($request));
|
|
}
|
|
|
|
public function isInteractive(): bool
|
|
{
|
|
return true;
|
|
}
|
|
}
|