Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1b2ef74

Browse filesBrowse files
committed
[Security] made sure that the exception listener is always removed from the event dispatcher at the end of the request
1 parent b1a062d commit 1b2ef74
Copy full SHA for 1b2ef74

File tree

3 files changed

+30
-7
lines changed
Filter options

3 files changed

+30
-7
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Security/Http/Firewall.php
+18-1Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Symfony\Component\HttpKernel\KernelEvents;
1515
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
16+
use Symfony\Component\HttpKernel\Event\FinishRequestEvent;
1617
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
1718
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
1819

@@ -30,6 +31,7 @@ class Firewall implements EventSubscriberInterface
3031
{
3132
private $map;
3233
private $dispatcher;
34+
private $exceptionListeners;
3335

3436
/**
3537
* Constructor.
@@ -41,6 +43,7 @@ public function __construct(FirewallMapInterface $map, EventDispatcherInterface
4143
{
4244
$this->map = $map;
4345
$this->dispatcher = $dispatcher;
46+
$this->exceptionListeners = new \SplObjectStorage();
4447
}
4548

4649
/**
@@ -57,6 +60,7 @@ public function onKernelRequest(GetResponseEvent $event)
5760
// register listeners for this firewall
5861
list($listeners, $exception) = $this->map->getListeners($event->getRequest());
5962
if (null !== $exception) {
63+
$this->exceptionListeners[$event->getRequest()] = $exception;
6064
$exception->register($this->dispatcher);
6165
}
6266

@@ -70,8 +74,21 @@ public function onKernelRequest(GetResponseEvent $event)
7074
}
7175
}
7276

77+
public function onKernelFinishRequest(FinishRequestEvent $event)
78+
{
79+
$request = $event->getRequest();
80+
81+
if (isset($this->exceptionListeners[$request])) {
82+
$this->exceptionListeners[$request]->unregister($this->dispatcher);
83+
unset($this->exceptionListeners[$request]);
84+
}
85+
}
86+
7387
public static function getSubscribedEvents()
7488
{
75-
return array(KernelEvents::REQUEST => array('onKernelRequest', 8));
89+
return array(
90+
KernelEvents::REQUEST => array('onKernelRequest', 8),
91+
KernelEvents::FINISH_REQUEST => 'onKernelFinishRequest',
92+
);
7693
}
7794
}

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Security/Http/Firewall/ExceptionListener.php
+10-4Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,23 @@ public function register(EventDispatcherInterface $dispatcher)
6969
$dispatcher->addListener(KernelEvents::EXCEPTION, array($this, 'onKernelException'));
7070
}
7171

72+
/**
73+
* Unregisters the dispatcher.
74+
*
75+
* @param EventDispatcherInterface $dispatcher An EventDispatcherInterface instance
76+
*/
77+
public function unregister(EventDispatcherInterface $dispatcher)
78+
{
79+
$dispatcher->removeListener(KernelEvents::EXCEPTION, array($this, 'onKernelException'));
80+
}
81+
7282
/**
7383
* Handles security related exceptions.
7484
*
7585
* @param GetResponseForExceptionEvent $event An GetResponseForExceptionEvent instance
7686
*/
7787
public function onKernelException(GetResponseForExceptionEvent $event)
7888
{
79-
// we need to remove ourselves as the exception listener can be
80-
// different depending on the Request
81-
$event->getDispatcher()->removeListener(KernelEvents::EXCEPTION, array($this, 'onKernelException'));
82-
8389
$exception = $event->getException();
8490
$request = $event->getRequest();
8591

‎src/Symfony/Component/Security/composer.json

Copy file name to clipboardExpand all lines: src/Symfony/Component/Security/composer.json
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
"require": {
1919
"php": ">=5.3.3",
2020
"symfony/event-dispatcher": "~2.1",
21-
"symfony/http-foundation": "~2.1",
22-
"symfony/http-kernel": "~2.1"
21+
"symfony/http-foundation": "~2.4",
22+
"symfony/http-kernel": "~2.4"
2323
},
2424
"require-dev": {
2525
"symfony/form": "~2.0",

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.