From 3ca210316489b1a1474f54504b979d10f8ad9772 Mon Sep 17 00:00:00 2001 From: Christian Scheb Date: Sun, 17 Oct 2021 17:31:40 +0200 Subject: [PATCH] Remove sorting of security listeners at runtime --- .../DependencyInjection/SecurityExtension.php | 1 + .../CompleteConfigurationTest.php | 1 + .../Component/Security/Http/Firewall.php | 27 +------------------ .../Component/Security/Http/composer.json | 2 +- 4 files changed, 4 insertions(+), 27 deletions(-) diff --git a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php index e467bd2d7f60e..2db662eb9931c 100644 --- a/src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php +++ b/src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php @@ -360,6 +360,7 @@ private function createFirewall(ContainerBuilder $container, string $id, array $ 'csrf_token_id' => $firewall['logout']['csrf_token_id'], 'logout_path' => $firewall['logout']['path'], ]); + $listeners[] = new Reference($logoutListenerId); $logoutSuccessListenerId = 'security.logout.listener.default.'.$id; $container->setDefinition($logoutSuccessListenerId, new ChildDefinition('security.logout.listener.default')) diff --git a/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/CompleteConfigurationTest.php b/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/CompleteConfigurationTest.php index bbc538030e820..839c00deba6cd 100644 --- a/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/CompleteConfigurationTest.php +++ b/src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/CompleteConfigurationTest.php @@ -204,6 +204,7 @@ public function testFirewalls() 'security.channel_listener', 'security.firewall.authenticator.secure', 'security.authentication.switchuser_listener.secure', + 'security.logout_listener.secure', 'security.access_listener', ], [ diff --git a/src/Symfony/Component/Security/Http/Firewall.php b/src/Symfony/Component/Security/Http/Firewall.php index 49b2b9a0d4eac..a7449878426ae 100644 --- a/src/Symfony/Component/Security/Http/Firewall.php +++ b/src/Symfony/Component/Security/Http/Firewall.php @@ -52,38 +52,13 @@ public function onKernelRequest(RequestEvent $event) $authenticationListeners = $listeners[0]; $exceptionListener = $listeners[1]; - $logoutListener = $listeners[2]; if (null !== $exceptionListener) { $this->exceptionListeners[$event->getRequest()] = $exceptionListener; $exceptionListener->register($this->dispatcher); } - // Authentication listeners are pre-sorted by SortFirewallListenersPass - $authenticationListeners = function () use ($authenticationListeners, $logoutListener) { - if (null !== $logoutListener) { - $logoutListenerPriority = $this->getListenerPriority($logoutListener); - } - - foreach ($authenticationListeners as $listener) { - $listenerPriority = $this->getListenerPriority($listener); - - // Yielding the LogoutListener at the correct position - if (null !== $logoutListener && $listenerPriority < $logoutListenerPriority) { - yield $logoutListener; - $logoutListener = null; - } - - yield $listener; - } - - // When LogoutListener has the lowest priority of all listeners - if (null !== $logoutListener) { - yield $logoutListener; - } - }; - - $this->callListeners($event, $authenticationListeners()); + $this->callListeners($event, $authenticationListeners); } public function onKernelFinishRequest(FinishRequestEvent $event) diff --git a/src/Symfony/Component/Security/Http/composer.json b/src/Symfony/Component/Security/Http/composer.json index 0a0c43d849f07..f29efb967d218 100644 --- a/src/Symfony/Component/Security/Http/composer.json +++ b/src/Symfony/Component/Security/Http/composer.json @@ -33,7 +33,7 @@ }, "conflict": { "symfony/event-dispatcher": "<5.4", - "symfony/security-bundle": "<5.4", + "symfony/security-bundle": "<6.0", "symfony/security-csrf": "<5.4" }, "suggest": {