Skip to content

Commit 1972786

Browse files
committed
Add logout listener to the list of authentication listeners
so that it can be sorted in correctly by SortFirewallListenersPass
1 parent a106327 commit 1972786

File tree

2 files changed

+2
-31
lines changed

2 files changed

+2
-31
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,7 @@ 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);
398399

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

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

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -52,38 +52,13 @@ public function onKernelRequest(RequestEvent $event)
5252

5353
$authenticationListeners = $listeners[0];
5454
$exceptionListener = $listeners[1];
55-
$logoutListener = $listeners[2];
5655

5756
if (null !== $exceptionListener) {
5857
$this->exceptionListeners[$event->getRequest()] = $exceptionListener;
5958
$exceptionListener->register($this->dispatcher);
6059
}
6160

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());
61+
$this->callListeners($event, $authenticationListeners);
8762
}
8863

8964
public function onKernelFinishRequest(FinishRequestEvent $event)
@@ -117,9 +92,4 @@ protected function callListeners(RequestEvent $event, iterable $listeners)
11792
}
11893
}
11994
}
120-
121-
private function getListenerPriority(object $logoutListener): int
122-
{
123-
return $logoutListener instanceof FirewallListenerInterface ? $logoutListener->getPriority() : 0;
124-
}
12595
}

0 commit comments

Comments
 (0)