10BC0 Revert changes on logout listener · symfony/symfony@1bc5c7b · GitHub
[go: up one dir, main page]

Skip to content

Commit 1bc5c7b

Browse files
committed
Revert changes on logout listener
1 parent c8d75dd commit 1bc5c7b

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,6 @@ private function createFirewall(ContainerBuilder $container, string $id, array $
395395
'csrf_token_id' => $firewall['logout']['csrf_token_id'],
396396
'logout_path' => $firewall['logout']['path'],
397397
]);
398-
$listeners[] = new Reference($logoutListenerId);
399398

400399
// add default logout listener
401400
if (isset($firewall['logout']['success_handler'])) {

src/Symfony/Component/Security/Http/Firewall.php

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Component\HttpKernel\Event\FinishRequestEvent;
1616
use Symfony\Component\HttpKernel\Event\RequestEvent;
1717
use Symfony\Component\HttpKernel\KernelEvents;
18+
use Symfony\Component\Security\Http\Firewall\FirewallListenerInterface;
1819
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
1920

2021
/**
@@ -51,13 +52,38 @@ public function onKernelRequest(RequestEvent $event)
5152

5253
$authenticationListeners = $listeners[0];
5354
$exceptionListener = $listeners[1];
55+
$logoutListener = $listeners[2];
5456

5557
if (null !== $exceptionListener) {
5658
$this->exceptionListeners[$event->getRequest()] = $exceptionListener;
5759
$exceptionListener->register($this->dispatcher);
5860
}
5961

60-
$this->callListeners($event, $authenticationListeners);
62+
// Authentication listeners are pre-sorted by SortFirewallListenersPass
63+
$authenticationListeners = function () use ($authenticationListeners, $logoutListener) {
64+
if (null !== $logoutListener) {
65+
$logoutListenerPriority = $this->getListenerPriority($logoutListener);
66+
}
67+
68+
foreach ($authenticationListeners as $listener) {
69+
$listenerPriority = $this->getListenerPriority($listener);
70+
71+
// Yielding the LogoutListener at the correct position
72+
if (null !== $logoutListener && $listenerPriority < $logoutListenerPriority) {
73+
yield $logoutListener;
74+
$logoutListener = null;
75+
}
76+
77+
yield $listener;
78+
}
79+
80+
// When LogoutListener has the lowest priority of all listeners
81+
if (null !== $logoutListener) {
82+
yield $logoutListener;
83+
}
84+
};
85+
86+
$this->callListeners($event, $authenticationListeners());
6187
}
6288

6389
public function onKernelFinishRequest(FinishRequestEvent $event)
@@ -91,4 +117,9 @@ protected function callListeners(RequestEvent $event, iterable $listeners)
91117
}
92118
}
93119
}
120+
121+
private function getListenerPriority(object $logoutListener): int
122+
{
123+
return $logoutListener instanceof FirewallListenerInterface ? $logoutListener->getPriority() : 0;
124+
}
94125
}

0 commit comments

Comments
 (0)
0