From e3655f3a5ccfdf866d4cd629c283203330516d67 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Thu, 17 Nov 2011 10:17:51 +0100 Subject: [PATCH] changed priorities for kernel.request listeners The Firewall is now executed after the Router. This was needed to have access to the locale and other request attributes that are set by the Router. This change implies that all Firewall specific URLs have proper (empty) routes like `/login_check` and `/logout`. --- CHANGELOG-2.1.md | 3 +++ .../Resources/config/security.xml | 2 +- .../EventListener/LocaleListener.php | 7 +++++-- .../EventListener/ProfilerListener.php | 3 +++ .../EventListener/RouterListener.php | 5 +++-- .../Component/Security/Http/HttpUtils.php | 19 ------------------- 6 files changed, 15 insertions(+), 24 deletions(-) diff --git a/CHANGELOG-2.1.md b/CHANGELOG-2.1.md index e77e0c0d895c..dcaffb965b2c 100644 --- a/CHANGELOG-2.1.md +++ b/CHANGELOG-2.1.md @@ -36,6 +36,9 @@ To get the diff between two versions, go to https://github.com/symfony/symfony/c ### SecurityBundle + * [BC BREAK] The Firewall listener is now registered after the Router one. + It means that specific Firewall URLs (like /login_check and /logout must now have proper + route defined in your routing configuration) * added a validator for the user password ### SwiftmailerBundle diff --git a/src/Symfony/Bundle/SecurityBundle/Resources/config/security.xml b/src/Symfony/Bundle/SecurityBundle/Resources/config/security.xml index 14c0e3bc3cb9..cd76d55d3d23 100644 --- a/src/Symfony/Bundle/SecurityBundle/Resources/config/security.xml +++ b/src/Symfony/Bundle/SecurityBundle/Resources/config/security.xml @@ -102,7 +102,7 @@ - + diff --git a/src/Symfony/Component/HttpKernel/EventListener/LocaleListener.php b/src/Symfony/Component/HttpKernel/EventListener/LocaleListener.php index 0081fa391a3f..c0b19e99a2be 100644 --- a/src/Symfony/Component/HttpKernel/EventListener/LocaleListener.php +++ b/src/Symfony/Component/HttpKernel/EventListener/LocaleListener.php @@ -76,8 +76,11 @@ static public function getSubscribedEvents() { return array( KernelEvents::REQUEST => array( - array('onEarlyKernelRequest', 253), - array('onKernelRequest', -1) + // must be registered after the session listener + array('onEarlyKernelRequest', 255), + + // must be registered after the Router to have access to the _locale + array('onKernelRequest', 16), ), ); } diff --git a/src/Symfony/Component/HttpKernel/EventListener/ProfilerListener.php b/src/Symfony/Component/HttpKernel/EventListener/ProfilerListener.php index 0d7e26002dd4..3745f28d6424 100644 --- a/src/Symfony/Component/HttpKernel/EventListener/ProfilerListener.php +++ b/src/Symfony/Component/HttpKernel/EventListener/ProfilerListener.php @@ -130,7 +130,10 @@ public function onKernelResponse(FilterResponseEvent $event) static public function getSubscribedEvents() { return array( + // kernel.request must be registered as early as possible to not break + // when an exception is thrown in any other kernel.request listener KernelEvents::REQUEST => array('onKernelRequest', 1024), + KernelEvents::RESPONSE => array('onKernelResponse', -100), KernelEvents::EXCEPTION => 'onKernelException', ); diff --git a/src/Symfony/Component/HttpKernel/EventListener/RouterListener.php b/src/Symfony/Component/HttpKernel/EventListener/RouterListener.php index ed8c9e0b68b8..64589d58b8d9 100644 --- a/src/Symfony/Component/HttpKernel/EventListener/RouterListener.php +++ b/src/Symfony/Component/HttpKernel/EventListener/RouterListener.php @@ -94,8 +94,9 @@ static public function getSubscribedEvents() { return array( KernelEvents::REQUEST => array( - array('onEarlyKernelRequest', 255), - array('onKernelRequest', 10) + // the early method must be called before the Firewall to be able to generate URLs correctly + array('onEarlyKernelRequest', 128), + array('onKernelRequest', 32), ), ); } diff --git a/src/Symfony/Component/Security/Http/HttpUtils.php b/src/Symfony/Component/Security/Http/HttpUtils.php index b31fcf536b5f..f62f84d1239a 100644 --- a/src/Symfony/Component/Security/Http/HttpUtils.php +++ b/src/Symfony/Component/Security/Http/HttpUtils.php @@ -52,7 +52,6 @@ public function createRedirectResponse(Request $request, $path, $status = 302) if ('/' === $path[0]) { $path = $request->getUriForPath($path); } elseif (0 !== strpos($path, 'http')) { - $this->resetLocale($request); $path = $this->generateUrl($path, true); } @@ -70,7 +69,6 @@ public function createRedirectResponse(Request $request, $path, $status = 302) public function createRequest(Request $request, $path) { if ($path && '/' !== $path[0] && 0 !== strpos($path, 'http')) { - $this->resetLocale($request); $path = $this->generateUrl($path, true); } if (0 !== strpos($path, 'http')) { @@ -120,23 +118,6 @@ public function checkRequestPath(Request $request, $path) return $path === $request->getPathInfo(); } - // hack (don't have a better solution for now) - private function resetLocale(Request $request) - { - $context = $this->router->getContext(); - if ($context->getParameter('_locale')) { - return; - } - - try { - $parameters = $this->router->match($request->getPathInfo()); - - $context->setParameter('_locale', isset($parameters['_locale']) ? $parameters['_locale'] : $request->getLocale()); - } catch (\Exception $e) { - // let's hope user doesn't use the locale in the path - } - } - private function generateUrl($route, $absolute = false) { if (null === $this->router) {