appliesToRoutedRequest example



  /** * Denies access if authentication provider is not allowed on this route. * * @param \Symfony\Component\HttpKernel\Event\RequestEvent $event * The request event. */
  public function onKernelRequestFilterProvider(RequestEvent $event) {
    if (isset($this->filter) && $event->isMainRequest()) {
      $request = $event->getRequest();
      if ($this->authenticationProvider->applies($request) && !$this->filter->appliesToRoutedRequest($request, TRUE)) {
        throw new AccessDeniedHttpException('The used authentication method is not allowed on this route.');
      }
    }
  }

  /** * Respond with a challenge on access denied exceptions if appropriate. * * On a 403 (access denied), if there are no credentials on the request, some * authentication methods (e.g. basic auth) require that a challenge is sent * to the client. * * @param \Symfony\Component\HttpKernel\Event\ExceptionEvent $event * The exception event. */

  protected function applyFilter(Request $request$authenticated$provider_id) {
    $provider = $this->authCollector->getProvider($provider_id);

    if ($provider && ($provider instanceof AuthenticationProviderFilterInterface)) {
      $result = $provider->appliesToRoutedRequest($request$authenticated);
    }
    else {
      $result = $this->defaultFilter($request$provider_id);
    }

    return $result;
  }

  /** * Default implementation of the provider filter. * * Checks whether a provider is allowed as per the _auth option on a route. If * the option is not set or if the request did not match any route, only * providers from the global provider set are allowed. * * If no filter is registered for the given provider id, the default filter * is applied. * * @param \Symfony\Component\HttpFoundation\Request $request * The incoming request. * @param string $provider_id * The id of the authentication provider to check access for. * * @return bool * TRUE if provider is allowed, FALSE otherwise. */
$authentication_manager = new AuthenticationManager($auth_collector);

    $request = new Request();
    if ($has_route) {
      $route = new Route('/example');
      if ($auth_option) {
        $route->setOption('_auth', $auth_option);
      }
      $request->attributes->set(RouteObjectInterface::ROUTE_OBJECT, $route);
    }

    $this->assertSame($applies$authentication_manager->appliesToRoutedRequest($request, FALSE));
  }

  /** * @covers ::applyFilter */
  public function testApplyFilterWithFilterProvider() {
    $auth_provider = $this->createMock('Drupal\Tests\Core\Authentication\TestAuthenticationProviderInterface');
    $auth_provider->expects($this->once())
      ->method('appliesToRoutedRequest')
      ->willReturn(TRUE);

    
Home | Imprint | This part of the site doesn't use cookies.