Request listener to prevent access to profiler routes when debugging is
not enabled, or the user is logged off & debugging is not configured to
show when logged off.

@param GetResponseEvent $event
354693
public function onKernelRequest(GetResponseEvent $event)
    {
        $request = $event->getRequest();
        if (!$this->isProfilerRequest($request)) {
            return;
        }

        $token = $this->session->isStarted() ? $this->session->get('authentication') : null;
        if ($this->debug && ($token instanceof Token || $this->debugLoggedOff)) {
            return;
        }

        throw new NotFoundHttpException();
    }
242439
public function handleRequest(GetResponseEvent $event)
    {
        if (!($tagcacheConfig = $this->getTagcacheConfig($event->getRequest()))) {
            return;
        }

        if (is_array($cacheContent = $this->tagcache->get($tagcacheConfig->getKey()))) {
            if ($cacheContent['Expires'] - (time() - $cacheContent['CreatedAt']) < 0) {
                return;
            }
            $response = new TagcacheResponse($this->renderCacheContent($cacheContent));
            $response->headers->add($cacheContent['Headers']);
            $event->setResponse($response);
        }
    }
600229
public function onKernelRequest(GetResponseEvent $event)
    {
        if (!$event->isMasterRequest()) {
            // don't do anything if it's not the master request
            return;
        }

        $request = $event->getRequest();

        $session = $this->getContainer()->get('session');

        $utm_params = [
            'utm_source',
            'utm_campaign',
            'utm_medium',
            'utm_term',
        ];

        foreach ($utm_params as $param) {
            if ($request->get($param)) {
                $session->set($param, $request->get($param));
            }
        }
    }
931543
public function onKernelRequestIndex(GetResponseEvent $event)
    {
        $request = $event->getRequest();
        $semanticPathinfo = $request->attributes->get('semanticPathinfo') ?: '/';
        if (
            $event->getRequestType() === HttpKernelInterface::MASTER_REQUEST
            && $semanticPathinfo === '/'
        ) {
            $indexPage = $this->configResolver->getParameter('index_page');
            if ($indexPage !== null) {
                $indexPage = '/' . ltrim($indexPage, '/');
                $request->attributes->set('semanticPathinfo', $indexPage);
                $request->attributes->set('needsForward', true);
            }
        }
    }
1107323
public function onKernelRequest(GetResponseEvent $event)
    {
        $request = $event->getRequest();

        // This call is required in all cases, because the default router needs our webspace information
        // Would be nice to also only call this if the _requestAnalyzer attribute is set, but it's set on the next line
        $this->requestAnalyzer->analyze($request);
        $this->baseRouteListener->onKernelRequest($event);
        if (false !== $request->attributes->get(static::REQUEST_ANALYZER, true)) {
            $this->requestAnalyzer->validate($request);
        }
    }
1343274
public function onRequestEarly(GetResponseEvent $event)
    {
        $validator = $this->app['config.validator'];
        $response = $validator->checks();
        if ($response instanceof Response) {
            $event->setResponse($response);
        }
    }
583457
public function onKernelRequest(GetResponseEvent $event): void
    {
        $request = $event->getRequest();
        if (!($request->attributes->has('_api_resource_class') || $request->attributes->getBoolean('_api_respond', false) || $request->attributes->getBoolean('_graphql', false))) {
            return;
        }
        // BC check to be removed in 3.0
        if (null !== $this->formatsProvider) {
            $this->formats = $this->formatsProvider->getFormatsFromAttributes(RequestAttributesExtractor::extractAttributes($request));
        }
        $this->formatMatcher = new FormatMatcher($this->formats);

        $this->populateMimeTypes();
        $this->addRequestFormats($request, $this->formats);

        // Empty strings must be converted to null because the Symfony router doesn't support parameter typing before 3.2 (_format)
        if (null === $routeFormat = $request->attributes->get('_format') ?: null) {
            $mimeTypes = array_keys($this->mimeTypes);
        } elseif (!isset($this->formats[$routeFormat])) {
            throw new NotFoundHttpException(sprintf('Format "%s" is not supported', $routeFormat));
        } else {
            $mimeTypes = Request::getMimeTypes($routeFormat);
        }

        // First, try to guess the format from the Accept header
        /** @var string|null $accept */
        $accept = $request->headers->get('Accept');
        if (null !== $accept) {
            if (null === $mediaType = $this->negotiator->getBest($accept, $mimeTypes)) {
                throw $this->getNotAcceptableHttpException($accept, $mimeTypes);
            }

            $request->setRequestFormat($this->formatMatcher->getFormat($mediaType->getType()));

            return;
        }

        // Then use the Symfony request format if available and applicable
        $requestFormat = $request->getRequestFormat('') ?: null;
        if (null !== $requestFormat) {
            $mimeType = $request->getMimeType($requestFormat);

            if (isset($this->mimeTypes[$mimeType])) {
                return;
            }

            throw $this->getNotAcceptableHttpException($mimeType);
        }

        // Finally, if no Accept header nor Symfony request format is set, return the default format
        foreach ($this->formats as $format => $mimeType) {
            $request->setRequestFormat($format);

            return;
        }
    }
237769
public function onKernelRequest(GetResponseEvent $event)
    {
        if (!$event->isMasterRequest()) {
            // don't do anything if it's not the master request
            return;
        }

        $request = $event->getRequest();

        $referer = $request->headers->get('referer');

        if ($referer && false === mb_strpos($referer, $request->getHost())) {
            $session = $this->getContainer()->get('session');

            $session->set('referer', $referer);
        }
    }
510678
public function onRequest(GetResponseEvent $event)
    {
        if (!$event->isMasterRequest()) {
            return;
        }

        $this->manager->initialize($event->getRequest());
    }
1333190
public function onRequest(GetResponseEvent $event)
    {
        if (!$event->isMasterRequest()) {
            return;
        }

        $request = $event->getRequest();
        $request->setSession($this->session);

        $this->prependBasePathToCookie($request);
        $this->appendRealmToName($request);

        $name = $this->session->getName();
        if ($request->cookies->has($name)) {
            $this->session->setId($request->cookies->get($name));
            $this->session->start();
        }
    }
1167348
public function onKernelRequest(GetResponseEvent $event)
    {
        if ($event->getRequestType() !== HttpKernelInterface::MASTER_REQUEST) {
            return;
        }

        $requestAttributes = $event->getRequest()->attributes;

        $currentSiteAccess = $requestAttributes->get('siteaccess');
        $allowedSiteAccesses = $requestAttributes->get(self::ALLOWED_SITEACCESSES_KEY);

        // We allow the route if no current siteaccess is set or
        // no allowed siteaccesses (meaning all are allowed) are defined
        if (!$currentSiteAccess instanceof SiteAccess || empty($allowedSiteAccesses)) {
            return;
        }

        if (!is_array($allowedSiteAccesses)) {
            $allowedSiteAccesses = array($allowedSiteAccesses);
        }

        if ($this->matcher->isAllowed($currentSiteAccess->name, $allowedSiteAccesses)) {
            return;
        }

        throw new NotFoundHttpException('Route is not allowed in current siteaccess');
    }
347803
public function onKernelRequest(GetResponseEvent $event)
    {
        if (!$event->getRequest()->attributes->get('is_rest_request')) {
            return;
        }

        if (!$this->csrfEnabled) {
            return;
        }

        // skip CSRF validation if no session is running
        if (!$event->getRequest()->getSession()->isStarted()) {
            return;
        }

        if ($this->isMethodSafe($event->getRequest()->getMethod())) {
            return;
        }

        if ($this->isSessionRoute($event->getRequest()->get('_route'))) {
            return;
        }

        if (!$this->checkCsrfToken($event->getRequest())) {
            throw new UnauthorizedException(
                'Missing or invalid CSRF token',
                $event->getRequest()->getMethod() . ' ' . $event->getRequest()->getPathInfo()
            );
        }

        // Dispatching event so that CSRF token intention can be injected into Legacy Stack
        $this->eventDispatcher->dispatch(RestEvents::REST_CSRF_TOKEN_VALIDATED);
    }
323549
public function onKernelRequest(GetResponseEvent $event)
    {
        $headers = $event->getRequest()->headers;

        if (!$headers->has(self::HEADER_NAME)) {
            return;
        }

        $this->requestId->set($headers->get(self::HEADER_NAME, null, true), true);
    }
541530
public function checkForRedirection(GetResponseEvent $event) {
    if ($this->routeMatch->getRouteName() != 'entity.data_policy.version_history') {
      return;
    }

    if ($this->currentUser->id() == 1 || !$this->currentUser->hasPermission('view all data policy revisions')) {
      return;
    }

    $url = Url::fromRoute('social_gdpr.data_policy.revisions');
    $response = new RedirectResponse($url->toString());
    $event->setResponse($response);
  }
980549
public function onKernelRequest(GetResponseEvent $event): void
    {
        if ('sonata_admin_dashboard' === $event->getRequest()->get('_route')) {
            $modelManager = $this->admin->getModelManager();

            $defaultDashboard = $modelManager->findOneBy($this->admin->getClass(), [
                'default' => true,
                'enabled' => true,
            ]);

            if ($defaultDashboard) {
                $url = $this->admin->generateObjectUrl('render', $defaultDashboard, ['default' => true]);
                $event->setResponse(new RedirectResponse($url));
            }
        }
    }
1354958
public function onKernelRequest(GetResponseEvent $event)
    {
        if (!$event->isMasterRequest()) {
            return;
        }

        $siteAccess = $event->getRequest()->attributes->get('siteaccess')->name;
        if (!isset($this->groupsBySiteAccess[$siteAccess])) {
            return;
        }

        if (!in_array(EzPlatformAdminUiBundle::ADMIN_GROUP_NAME, $this->groupsBySiteAccess[$siteAccess], true)) {
            return;
        }

        $this->globalVariable->setPageLayoutTemplate($this->pageLayoutTemplate);
    }
542910
public function onKernelRequest(GetResponseEvent $event)
    {
        if(!$event->isMasterRequest()){
            return;
        }

        $request = $event->getRequest();

        if (is_array($this->query)) {
            foreach ($this->query as $key => $pattern) {
                if (!empty($pattern) && preg_match('{'.$pattern.'}', $request->get($key))) {
                    return;
                }
            }
        }

        if (is_array($this->cookie)) {
            foreach ($this->cookie as $key => $pattern) {
                if (!empty($pattern) && preg_match('{'.$pattern.'}', $request->cookies->get($key))) {
                    return;
                }
            }
        }

        if (is_array($this->attributes)) {
            foreach ($this->attributes as $key => $pattern) {
                if (!empty($pattern) && preg_match('{'.$pattern.'}', $request->attributes->get($key))) {
                    return;
                }
            }
        }

        if (null !== $this->path && !empty($this->path) && preg_match('{'.$this->path.'}', rawurldecode($request->getPathInfo()))) {
            return;
        }

        if (null !== $this->host && !empty($this->host) && preg_match('{'.$this->host.'}i', $request->getHost())) {
            return;
        }

        if (count((array) $this->ips) !== 0 && $this->checkIps($request->getClientIp(), $this->ips)) {
            return;
        }

        $route = $request->get('_route');
        if (null !== $this->route && preg_match('{'.$this->route.'}', $route)  || (true === $this->debug && '_' === $route[0])) {
            return;
        }

        // Get driver class defined in your configuration
        $driver = $this->driverFactory->getDriver();

        if ($driver->decide() && HttpKernelInterface::MASTER_REQUEST === $event->getRequestType()) {
            $this->handleResponse = true;
            throw new ServiceUnavailableException($this->http_exception_message);
        }
    }