Skip to content

Commit 932d473

Browse files
Merge branch '5.0' into 5.1
* 5.0: Handle fetch mode deprecation of DBAL 2.11. Fixed handling of CSRF logout error [WebProfilerBundle] changed label of memory usage in time panel (Mb into MiB) [DotEnv][WebLink][Templating][ErrorHandler] Updated README with minimal example
2 parents eccb37a + 7d29ffd commit 932d473

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

Firewall/ExceptionListener.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public function onKernelException(ExceptionEvent $event)
111111
}
112112

113113
if ($exception instanceof LogoutException) {
114-
$this->handleLogoutException($exception);
114+
$this->handleLogoutException($event, $exception);
115115

116116
return;
117117
}
@@ -183,10 +183,12 @@ private function handleAccessDeniedException(ExceptionEvent $event, AccessDenied
183183
}
184184
}
185185

186-
private function handleLogoutException(LogoutException $exception): void
186+
private function handleLogoutException(ExceptionEvent $event, LogoutException $exception): void
187187
{
188+
$event->setException(new AccessDeniedHttpException($exception->getMessage(), $exception));
189+
188190
if (null !== $this->logger) {
189-
$this->logger->info('A LogoutException was thrown.', ['exception' => $exception]);
191+
$this->logger->info('A LogoutException was thrown; wrapping with AccessDeniedHttpException', ['exception' => $exception]);
190192
}
191193
}
192194

Tests/Firewall/ExceptionListenerTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
2222
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
2323
use Symfony\Component\Security\Core\Exception\AuthenticationException;
24+
use Symfony\Component\Security\Core\Exception\LogoutException;
2425
use Symfony\Component\Security\Http\Authorization\AccessDeniedHandlerInterface;
2526
use Symfony\Component\Security\Http\EntryPoint\AuthenticationEntryPointInterface;
2627
use Symfony\Component\Security\Http\Firewall\ExceptionListener;
@@ -157,6 +158,17 @@ public function testAccessDeniedExceptionNotFullFledged(\Exception $exception, \
157158
$this->assertSame(null === $eventException ? $exception : $eventException, $event->getThrowable()->getPrevious());
158159
}
159160

161+
public function testLogoutException()
162+
{
163+
$event = $this->createEvent(new LogoutException('Invalid CSRF.'));
164+
165+
$listener = $this->createExceptionListener();
166+
$listener->onKernelException($event);
167+
168+
$this->assertEquals('Invalid CSRF.', $event->getException()->getMessage());
169+
$this->assertEquals(403, $event->getException()->getStatusCode());
170+
}
171+
160172
public function getAccessDeniedExceptionProvider()
161173
{
162174
return [

0 commit comments

Comments
 (0)