/**
  * @covers ::applyFilter
  */
 public function testApplyFilterWithFilterprovider()
 {
     $authentication_manager = new AuthenticationManager();
     $auth_provider = $this->getMock('Drupal\\Tests\\Core\\Authentication\\TestAuthenticationProviderInterface');
     $authentication_manager->addProvider($auth_provider, 'filtered', 0);
     $auth_provider->expects($this->once())->method('appliesToRoutedRequest')->willReturn(TRUE);
     $request = new Request();
     $this->assertTrue($authentication_manager->appliesToRoutedRequest($request, FALSE));
 }
 /**
  * {@inheritdoc}
  */
 public function enhance(array $defaults, Request $request)
 {
     $auth_provider_triggered = $request->attributes->get('_authentication_provider');
     if (!empty($auth_provider_triggered)) {
         $route = isset($defaults[RouteObjectInterface::ROUTE_OBJECT]) ? $defaults[RouteObjectInterface::ROUTE_OBJECT] : NULL;
         $auth_providers = $route && $route->getOption('_auth') ? $route->getOption('_auth') : array($this->manager->defaultProviderId());
         // If the request was authenticated with a non-permitted provider,
         // force the user back to anonymous.
         if (!in_array($auth_provider_triggered, $auth_providers)) {
             $anonymous_user = new AnonymousUserSession();
             $this->currentUser->setAccount($anonymous_user);
             // The global $user object is included for backward compatibility only
             // and should be considered deprecated.
             // @todo Remove this line once global $user is no longer used.
             $GLOBALS['user'] = $anonymous_user;
         }
     }
     return $defaults;
 }