diff options
Diffstat (limited to 'Http')
-rw-r--r-- | Http/Firewall.php | 2 | ||||
-rw-r--r-- | Http/Firewall/AccessListener.php | 4 | ||||
-rw-r--r-- | Http/Firewall/ExceptionListener.php | 11 | ||||
-rw-r--r-- | Http/HttpUtils.php | 37 | ||||
-rw-r--r-- | Http/RememberMe/AbstractRememberMeServices.php | 2 |
5 files changed, 37 insertions, 19 deletions
diff --git a/Http/Firewall.php b/Http/Firewall.php index 996df29..9d05f86 100644 --- a/Http/Firewall.php +++ b/Http/Firewall.php @@ -30,7 +30,6 @@ class Firewall { private $map; private $dispatcher; - private $currentListeners; /** * Constructor. @@ -42,7 +41,6 @@ class Firewall { $this->map = $map; $this->dispatcher = $dispatcher; - $this->currentListeners = array(); } /** diff --git a/Http/Firewall/AccessListener.php b/Http/Firewall/AccessListener.php index 0cb45ac..877b6c3 100644 --- a/Http/Firewall/AccessListener.php +++ b/Http/Firewall/AccessListener.php @@ -11,7 +11,7 @@ namespace Symfony\Component\Security\Http\Firewall; -use Symfony\Component\Security\Core\SecurityContext; +use Symfony\Component\Security\Core\SecurityContextInterface; use Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface; use Symfony\Component\Security\Http\AccessMap; use Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface; @@ -33,7 +33,7 @@ class AccessListener implements ListenerInterface private $authManager; private $logger; - public function __construct(SecurityContext $context, AccessDecisionManagerInterface $accessDecisionManager, AccessMap $map, AuthenticationManagerInterface $authManager, LoggerInterface $logger = null) + public function __construct(SecurityContextInterface $context, AccessDecisionManagerInterface $accessDecisionManager, AccessMap $map, AuthenticationManagerInterface $authManager, LoggerInterface $logger = null) { $this->context = $context; $this->accessDecisionManager = $accessDecisionManager; diff --git a/Http/Firewall/ExceptionListener.php b/Http/Firewall/ExceptionListener.php index 737d644..c757390 100644 --- a/Http/Firewall/ExceptionListener.php +++ b/Http/Firewall/ExceptionListener.php @@ -26,6 +26,7 @@ use Symfony\Component\HttpKernel\Log\LoggerInterface; use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent; +use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; use Symfony\Component\EventDispatcher\EventDispatcherInterface; /** @@ -113,16 +114,16 @@ class ExceptionListener if (!$response instanceof Response) { return; } - } else { - if (null === $this->errorPage) { - return; - } - + } elseif (null !== $this->errorPage) { $subRequest = $this->httpUtils->createRequest($request, $this->errorPage); $subRequest->attributes->set(SecurityContextInterface::ACCESS_DENIED_ERROR, $exception); $response = $event->getKernel()->handle($subRequest, HttpKernelInterface::SUB_REQUEST, true); $response->setStatusCode(403); + } else { + $event->setException(new AccessDeniedHttpException($exception->getMessage(), $exception)); + + return; } } catch (\Exception $e) { if (null !== $this->logger) { diff --git a/Http/HttpUtils.php b/Http/HttpUtils.php index 6b674aa..51168cc 100644 --- a/Http/HttpUtils.php +++ b/Http/HttpUtils.php @@ -13,7 +13,7 @@ namespace Symfony\Component\Security\Http; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\RedirectResponse; -use Symfony\Component\Routing\Generator\UrlGeneratorInterface; +use Symfony\Component\Routing\RouterInterface; /** * Encapsulates the logic needed to create sub-requests, redirect the user, and match URLs. @@ -22,16 +22,16 @@ use Symfony\Component\Routing\Generator\UrlGeneratorInterface; */ class HttpUtils { - private $urlGenerator; + private $router; /** * Constructor. * - * @param UrlGeneratorInterface $urlGenerator An UrlGeneratorInterface instance + * @param RouterInterface $router An RouterInterface instance */ - public function __construct(UrlGeneratorInterface $urlGenerator = null) + public function __construct(RouterInterface $router = null) { - $this->urlGenerator = $urlGenerator; + $this->router = $router; } /** @@ -48,6 +48,19 @@ class HttpUtils if (0 === strpos($path, '/')) { $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()); + } + $path = $this->generateUrl($path, true); } @@ -82,7 +95,13 @@ class HttpUtils public function checkRequestPath(Request $request, $path) { if ('/' !== $path[0]) { - $path = preg_replace('#'.preg_quote($request->getBaseUrl(), '#').'#', '', $this->generateUrl($path)); + try { + $parameters = $this->router->match($request->getPathInfo()); + + return $path === $parameters['_route']; + } catch (\Exception $e) { + return false; + } } return $path === $request->getPathInfo(); @@ -90,10 +109,10 @@ class HttpUtils private function generateUrl($route, $absolute = false) { - if (null === $this->urlGenerator) { - throw new \LogicException('You must provide a UrlGeneratorInterface instance to be able to use routes.'); + if (null === $this->router) { + throw new \LogicException('You must provide a RouterInterface instance to be able to use routes.'); } - return $this->urlGenerator->generate($route, array(), $absolute); + return $this->router->generate($route, array(), $absolute); } } diff --git a/Http/RememberMe/AbstractRememberMeServices.php b/Http/RememberMe/AbstractRememberMeServices.php index 7d273b9..2118a86 100644 --- a/Http/RememberMe/AbstractRememberMeServices.php +++ b/Http/RememberMe/AbstractRememberMeServices.php @@ -285,7 +285,7 @@ abstract class AbstractRememberMeServices implements RememberMeServicesInterface return true; } - $parameter = $request->request->get($this->options['remember_me_parameter']); + $parameter = $request->request->get($this->options['remember_me_parameter'], null, true); if ($parameter === null && null !== $this->logger) { $this->logger->debug(sprintf('Did not send remember-me cookie (remember-me parameter "%s" was not sent).', $this->options['remember_me_parameter'])); |