diff --git a/core/lib/Drupal/Core/Routing/AccessAwareRouter.php b/core/lib/Drupal/Core/Routing/AccessAwareRouter.php index 1091736..247ef90 100644 --- a/core/lib/Drupal/Core/Routing/AccessAwareRouter.php +++ b/core/lib/Drupal/Core/Routing/AccessAwareRouter.php @@ -37,7 +37,7 @@ class AccessAwareRouter implements AccessAwareRouterInterface { /** * Authentication provider. * - * @var AuthenticationProviderInterface + * @var \Drupal\Core\Authentication\AuthenticationProviderInterface */ protected $authenticationProvider; @@ -55,7 +55,7 @@ class AccessAwareRouter implements AccessAwareRouterInterface { * The chain router doing the actual routing. * @param \Drupal\Core\Access\AccessManagerInterface $access_manager * The access manager. - * @param AuthenticationProviderInterface $authentication_provider + * @param \Drupal\Core\Authentication\AuthenticationProviderInterface $authentication_provider * The authentication provider. * @param \Drupal\Core\Session\AccountProxyInterface $account_proxy * The account proxy to authenticate and to use in access checks. @@ -97,12 +97,21 @@ public function getContext() { * Thrown when access checking failed. */ public function matchRequest(Request $request) { - $parameters = $this->chainRouter->matchRequest($request); - $request->attributes->add($parameters); + try { + $parameters = $this->chainRouter->matchRequest($request); + $request->attributes->add($parameters); + } + catch (\Exception $e) { + $routing_exception = $e; + } // Authenticate the user. $this->accountProxy->setAccount($this->authenticationProvider->authenticate($request)); + if (isset($routing_exception)) { + throw $routing_exception; + } + $this->checkAccess($request); // We can not return $parameters because the access check can change the // request attributes. diff --git a/core/tests/Drupal/Tests/Core/Routing/AccessAwareRouterTest.php b/core/tests/Drupal/Tests/Core/Routing/AccessAwareRouterTest.php index 17409b4..ad7d95d 100644 --- a/core/tests/Drupal/Tests/Core/Routing/AccessAwareRouterTest.php +++ b/core/tests/Drupal/Tests/Core/Routing/AccessAwareRouterTest.php @@ -35,9 +35,16 @@ class AccessAwareRouterTest extends UnitTestCase { protected $accessManager; /** - * @var \Drupal\Core\Session\AccountInterface||\PHPUnit_Framework_MockObject_MockObject + * Authentication provider. + * + * @var \Drupal\Core\Authentication\AuthenticationProviderInterface|\PHPUnit_Framework_MockObject_MockObject + */ + protected $authenticationProvider; + + /** + * @var \Drupal\Core\Session\AccountProxyInterface|\PHPUnit_Framework_MockObject_MockObject */ - protected $currentUser; + protected $accountProxy; /** * @var \Drupal\Core\Routing\AccessAwareRouter @@ -51,7 +58,8 @@ public function setUp() { parent::setUp(); $this->route = new Route('test'); $this->accessManager = $this->getMock('Drupal\Core\Access\AccessManagerInterface'); - $this->currentUser = $this->getMock('Drupal\Core\Session\AccountInterface'); + $this->authenticationProvider = $this->getMock('Drupal\Core\Authentication\AuthenticationProviderInterface'); + $this->accountProxy = $this->getMock('Drupal\Core\Session\AccountProxyInterface'); } /** @@ -64,7 +72,10 @@ protected function setupRouter() { $this->chainRouter->expects($this->once()) ->method('matchRequest') ->will($this->returnValue(array(RouteObjectInterface::ROUTE_OBJECT => $this->route))); - $this->router = new AccessAwareRouter($this->chainRouter, $this->accessManager, $this->currentUser); + $this->authenticationProvider->expects($this->once()) + ->method('authenticate') + ->will($this->returnValue($this->getMock('Drupal\Core\Session\AccountInterface'))); + $this->router = new AccessAwareRouter($this->chainRouter, $this->accessManager, $this->authenticationProvider, $this->accountProxy); } /** @@ -113,7 +124,7 @@ public function testCall() { ->method('add') ->with($mock_router) ->willReturnSelf(); - $this->router = new AccessAwareRouter($this->chainRouter, $this->accessManager, $this->currentUser); + $this->router = new AccessAwareRouter($this->chainRouter, $this->accessManager, $this->authenticationProvider, $this->accountProxy); $this->router->add($mock_router); }