Skip to content

Commit 6770f83

Browse files
MatTheCatnicolas-grekas
authored andcommitted
[Security] Fix logout
1 parent 15ab837 commit 6770f83

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

Firewall.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,20 +47,29 @@ public function onKernelRequest(GetResponseEvent $event)
4747
}
4848

4949
// register listeners for this firewall
50-
list($listeners, $exceptionListener) = $this->map->getListeners($event->getRequest());
50+
$listeners = $this->map->getListeners($event->getRequest());
51+
52+
$authenticationListeners = $listeners[0];
53+
$exceptionListener = $listeners[1];
54+
$logoutListener = isset($listeners[2]) ? $listeners[2] : null;
55+
5156
if (null !== $exceptionListener) {
5257
$this->exceptionListeners[$event->getRequest()] = $exceptionListener;
5358
$exceptionListener->register($this->dispatcher);
5459
}
5560

5661
// initiate the listener chain
57-
foreach ($listeners as $listener) {
62+
foreach ($authenticationListeners as $listener) {
5863
$listener->handle($event);
5964

6065
if ($event->hasResponse()) {
6166
break;
6267
}
6368
}
69+
70+
if (null !== $logoutListener) {
71+
$logoutListener->handle($event);
72+
}
6473
}
6574

6675
public function onKernelFinishRequest(FinishRequestEvent $event)

FirewallMap.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Symfony\Component\HttpFoundation\RequestMatcherInterface;
1515
use Symfony\Component\HttpFoundation\Request;
1616
use Symfony\Component\Security\Http\Firewall\ExceptionListener;
17+
use Symfony\Component\Security\Http\Firewall\LogoutListener;
1718

1819
/**
1920
* FirewallMap allows configuration of different firewalls for specific parts
@@ -25,9 +26,9 @@ class FirewallMap implements FirewallMapInterface
2526
{
2627
private $map = array();
2728

28-
public function add(RequestMatcherInterface $requestMatcher = null, array $listeners = array(), ExceptionListener $exceptionListener = null)
29+
public function add(RequestMatcherInterface $requestMatcher = null, array $listeners = array(), ExceptionListener $exceptionListener = null, LogoutListener $logoutListener = null)
2930
{
30-
$this->map[] = array($requestMatcher, $listeners, $exceptionListener);
31+
$this->map[] = array($requestMatcher, $listeners, $exceptionListener, $logoutListener);
3132
}
3233

3334
/**
@@ -37,10 +38,10 @@ public function getListeners(Request $request)
3738
{
3839
foreach ($this->map as $elements) {
3940
if (null === $elements[0] || $elements[0]->matches($request)) {
40-
return array($elements[1], $elements[2]);
41+
return array($elements[1], $elements[2], $elements[3]);
4142
}
4243
}
4344

44-
return array(array(), null);
45+
return array(array(), null, null);
4546
}
4647
}

0 commit comments

Comments
 (0)