diff options
author | Johannes Schmitt <schmittjoh@gmail.com> | 2011-07-19 16:21:58 +0200 |
---|---|---|
committer | Johannes Schmitt <schmittjoh@gmail.com> | 2011-07-19 16:21:58 +0200 |
commit | eb4868879558c1027e9d76153e8cf0382915e7e0 (patch) | |
tree | b6f9956e4230504a0624d76c59087a1e147e03f8 /Http/HttpUtils.php | |
parent | 4f02e874586a07385cf2120c5fbe93c79f9b1a0f (diff) | |
download | symfony-security-eb4868879558c1027e9d76153e8cf0382915e7e0.zip symfony-security-eb4868879558c1027e9d76153e8cf0382915e7e0.tar.gz symfony-security-eb4868879558c1027e9d76153e8cf0382915e7e0.tar.bz2 |
fixes several bugs
Diffstat (limited to 'Http/HttpUtils.php')
-rw-r--r-- | Http/HttpUtils.php | 57 |
1 files changed, 42 insertions, 15 deletions
diff --git a/Http/HttpUtils.php b/Http/HttpUtils.php index 51168cc..3eccb41 100644 --- a/Http/HttpUtils.php +++ b/Http/HttpUtils.php @@ -11,6 +11,8 @@ namespace Symfony\Component\Security\Http; +use Symfony\Component\Security\Core\SecurityContextInterface; + use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\Routing\RouterInterface; @@ -45,22 +47,10 @@ class HttpUtils */ public function createRedirectResponse(Request $request, $path, $status = 302) { - if (0 === strpos($path, '/')) { + if ('/' === $path[0]) { $path = $request->getUriForPath($path); } elseif (0 !== strpos($path, 'http')) { - // hack (don't have a better solution for now) - $context = $this->router->getContext(); - try { - $parameters = $this->router->match($request->getPathInfo()); - } catch (\Exception $e) { - } - - if (isset($parameters['_locale'])) { - $context->setParameter('_locale', $parameters['_locale']); - } elseif ($session = $request->getSession()) { - $context->setParameter('_locale', $session->getLocale()); - } - + $this->resetLocale($request); $path = $this->generateUrl($path, true); } @@ -78,10 +68,26 @@ class HttpUtils public function createRequest(Request $request, $path) { if ($path && '/' !== $path[0] && 0 !== strpos($path, 'http')) { + $this->resetLocale($request); $path = $this->generateUrl($path, true); } - return Request::create($path, 'get', array(), $request->cookies->all(), array(), $request->server->all()); + $newRequest = Request::create($path, 'get', array(), $request->cookies->all(), array(), $request->server->all()); + if ($session = $request->getSession()) { + $newRequest->setSession($session); + } + + if ($request->attributes->has(SecurityContextInterface::AUTHENTICATION_ERROR)) { + $newRequest->attributes->set(SecurityContextInterface::AUTHENTICATION_ERROR, $request->attributes->get(SecurityContextInterface::AUTHENTICATION_ERROR)); + } + if ($request->attributes->has(SecurityContextInterface::ACCESS_DENIED_ERROR)) { + $newRequest->attributes->set(SecurityContextInterface::ACCESS_DENIED_ERROR, $request->attributes->get(SecurityContextInterface::ACCESS_DENIED_ERROR)); + } + if ($request->attributes->has(SecurityContextInterface::LAST_USERNAME)) { + $newRequest->attributes->set(SecurityContextInterface::LAST_USERNAME, $request->attributes->get(SecurityContextInterface::LAST_USERNAME)); + } + + return $newRequest; } /** @@ -107,6 +113,27 @@ class HttpUtils 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()); + + if (isset($parameters['_locale'])) { + $context->setParameter('_locale', $parameters['_locale']); + } elseif ($session = $request->getSession()) { + $context->setParameter('_locale', $session->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) { |