Files
e-cosplay/src/Security/AuthenticationEntryPoint.php
Serreau Jovann bfc2370d2e ```
 feat(security): Ajoute la route de déconnexion et configure la redirection.
 feat(Dto/Ag): Crée les DTOs AgType, AgMembersType et AgOrderType.
 feat(Controller/Admin): Implémente la gestion des AG (CRUD complet).
 feat(templates/admin): Ajoute les templates pour la gestion des AG.
```
2025-11-23 17:06:10 +01:00

57 lines
2.2 KiB
PHP

<?php
namespace App\Security;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Security\Core\Authentication\Token\RememberMeToken;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Symfony\Component\Security\Core\Exception\AuthenticationException;
use Symfony\Component\Security\Core\Exception\InsufficientAuthenticationException;
use Symfony\Component\Security\Http\EntryPoint\AuthenticationEntryPointInterface;
class AuthenticationEntryPoint implements AuthenticationEntryPointInterface
{
/**
* @var \Symfony\Component\Routing\Generator\UrlGeneratorInterface|mixed
*/
public $urlGenerator;
/**
* @var AccessDeniedHandler|mixed
*/
public $accessDeniedHandler;
public function __construct(
UrlGeneratorInterface $urlGenerator,
AccessDeniedHandler $accessDeniedHandler
) {
$this->urlGenerator = $urlGenerator;
$this->accessDeniedHandler = $accessDeniedHandler;
}
public function start(Request $request, AuthenticationException $authException = null): Response
{
$previous = $authException !== null ? $authException->getPrevious() : null;
// Parque le composant security est un peu bête et ne renvoie pas un AccessDenied pour les utilisateur connecté avec un cookie
// On redirige le traitement de cette situation vers le AccessDeniedHandler
if ($authException instanceof InsufficientAuthenticationException &&
$previous instanceof AccessDeniedException &&
$authException->getToken() instanceof RememberMeToken
) {
return $this->accessDeniedHandler->handle($request, $previous);
}
if (in_array('application/json', $request->getAcceptableContentTypes())) {
return new JsonResponse(
['title' => "Vous n'avez pas les permissions suffisantes pour effectuer cette action"],
Response::HTTP_FORBIDDEN
);
}
return new RedirectResponse($this->urlGenerator->generate('app_login'));
}
}