From 01fb8227bb4e32e9e055038c77745653f5088d57 Mon Sep 17 00:00:00 2001 From: Christian Scheb Date: Sat, 16 Apr 2022 12:15:33 +0200 Subject: [PATCH] Allow custom HTTP status code from AuthenticationRequiredHandler, #138 --- src/bundle/Security/Http/Firewall/ExceptionListener.php | 1 + tests/Security/Http/Firewall/ExceptionListenerTest.php | 1 + 2 files changed, 2 insertions(+) diff --git a/src/bundle/Security/Http/Firewall/ExceptionListener.php b/src/bundle/Security/Http/Firewall/ExceptionListener.php index a06218ce..e436eb4a 100644 --- a/src/bundle/Security/Http/Firewall/ExceptionListener.php +++ b/src/bundle/Security/Http/Firewall/ExceptionListener.php @@ -61,6 +61,7 @@ private function handleAccessDeniedException(ExceptionEvent $exceptionEvent): vo $this->eventDispatcher->dispatch($event, TwoFactorAuthenticationEvents::REQUIRE); $response = $this->authenticationRequiredHandler->onAuthenticationRequired($request, $token); + $exceptionEvent->allowCustomResponseCode(); $exceptionEvent->setResponse($response); } diff --git a/tests/Security/Http/Firewall/ExceptionListenerTest.php b/tests/Security/Http/Firewall/ExceptionListenerTest.php index 0d709f79..61b45460 100644 --- a/tests/Security/Http/Firewall/ExceptionListenerTest.php +++ b/tests/Security/Http/Firewall/ExceptionListenerTest.php @@ -103,6 +103,7 @@ private function assertNotHasResponse(ExceptionEvent $event): void private function assertHasResponse(ExceptionEvent $event, Response $response): void { + $this->assertTrue($event->isAllowingCustomResponseCode()); $this->assertSame($response, $event->getResponse()); }