Resume the session if it has been started previously or debugging is enabled.

@param GetResponseEvent $event

@throws \Bolt\Exception\PagerOverrideException
510678
public function onRequest(GetResponseEvent $event)
    {
        if (!$event->isMasterRequest()) {
            return;
        }

        $this->manager->initialize($event->getRequest());
    }
448804
public function onKernelRequest(GetResponseEvent $event): void
    {
        if (!$event->isMasterRequest()) {
            return;
        }

        $request = $event->getRequest();
        $route = $request->attributes->get('_route');

        if ($route !== null && !$request->attributes->get('requires_license')) {
            return;
        }

        if ($request->get('lic') === 'active' || $this->kernel->getEnvironment() !== 'prod') {
            return;
        }

        // Checking for whitelisted users
        try {
            /** @noinspection NullPointerExceptionInspection */
            $user = $this->tokenStorage->getToken()->getUser();
            if ($user instanceof TenantInterface) {
                if ($user->isWhiteListed()) {
                    return;
                }

                $today = \date('Y-m-d');
                $whitelist = $this->kernel->getContainer()->getParameter('license_whitelist');
                /** @noinspection ForeachSourceInspection */
                foreach ($whitelist as $allowed) {
                    if ($today <= $allowed['valid_till'] && $allowed['client_key'] === $user->getClientKey()) {
                        return;
                    }
                }
            }
        } catch (\Throwable $e) {
            // Do nothing
        }

        $url = $this->router->generate('atlassian_connect_unlicensed', $request->query->all());
        $response = new RedirectResponse($url);
        $event->setResponse($response);
    }
1053781
public function onKernelRequest(GetResponseEvent $event)
    {
        if (!$event->isMasterRequest()) {
            return;
        }

        if (!$this->csrfTokenManager instanceof CsrfTokenManagerInterface) {
            return;
        }

        $request = $event->getRequest();

        if ($request->isMethodCacheable()) {
            return;
        }

        if ($request->attributes->get('_route') !== $this->routeName) {
            return;
        }

        $session = $event->getRequest()->getSession();
        if (!$session->isStarted()) {
            return;
        }

        if ($request->headers->get('X-CSRF-Token') !== null) {
            return;
        }

        $csrfToken = $this->csrfTokenManager->getToken($this->csrfTokenId)->getValue();

        $request->headers->set('X-CSRF-Token', $csrfToken);
    }
1041144
public function handle(GetResponseEvent $event)
    {
        $request = $event->getRequest();

        if ($request->getMethod() !== 'POST') {
            throw new MethodNotAllowedHttpException(['POST']);
        }

        $data = json_decode($request->getContent(), true);

        if (null === $token = $this->createToken($data)) {
            throw new AuthenticationServiceException('Invalid JSON!');
        }

        if (null !== $this->logger) {
            $this->logger->info(
                sprintf('Post Authentication body found using passwordCredentials for user "%s"', $token->getUsername())
            );
        }

        try {
            $token = $this->authenticationManager->authenticate($token);
            $this->tokenStorage->setToken($token);
        } catch (AuthenticationException $failed) {
            $this->tokenStorage->setToken(null);

            if (null !== $this->logger) {
                $this->logger->info(
                    sprintf(
                        'Authentication request failed for user "%s" using POST and data: %s',
                        json_encode($data),
                        $failed->getMessage()
                    )
                );
            }

            throw $failed;
        }
    }
490047
public function handle(GetResponseEvent $event): void
    {
        if ($this->isEnabled()) {
            $hostRole = $this->getHostRole($event);

            if (null !== $hostRole) {
                $this->sidManager->addSpecialRole($hostRole);
            }
        }
    }
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);
  }
327205
public function onKernelRequest(GetResponseEvent $event)
    {
        if (!$event->isMasterRequest()) {
            return;
        }

        if (!$this->isPlatformUIRequest($event->getRequest())) {
            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);
        }
    }
997148
public function onKernelExceptionView(GetResponseForExceptionEvent $event)
    {
        if (!$event->getRequest()->attributes->get('is_rest_request')) {
            return;
        }

        $event->setResponse(
            $this->viewDispatcher->dispatch(
                $event->getRequest(),
                $event->getException()
            )
        );
        $event->stopPropagation();
    }
284741
public function onKernelRequest(GetResponseEvent $event)
    {
        if ($event->getRequestType() !== HttpKernelInterface::MASTER_REQUEST) {
            return;
        }

        $request = $event->getRequest();

        if (1 === intval($request->query->get('cms-editor-enable', 0))) {
            $this->editor->setEnabled(true);
        }
        if (0 < intval($width = $request->request->get('cms_viewport_width', 0))) {
            $this->editor->setViewportWidth($width);
        }

        if (null !== $page = $this->pageHelper->init($request)) {
            if (!$page->isEnabled()) {
                if ($this->authorizationChecker->isGranted('ROLE_ADMIN')) {
                    $this->session->getFlashBag()->add('warning', 'ekyna_cms.page.alert.disabled.allow_as_admin');

                    return;
                }

                $this->session->getFlashBag()->add('warning', 'ekyna_cms.page.alert.disabled.temporary_redirect');
                throw new NotFoundHttpException('Disabled page.');
            }
        }
    }
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);
        }
    }
838955
public function onRequest(GetResponseEvent $event)
    {
        if (Zone::isBackend($event->getRequest())) {
            $this->setVersionChangeNotice();
        }

        // Twig globals
        $this->setGlobals();

        // Only cache if the config passes checks
        if ($this->app['config']->checkConfig() === false) {
            return;
        }

        // Final thing we do, if we're still standing, is to save our
        // configuration to cache
        if (!$this->app['config']->get('general/caching/config')) {
            return;
        }

        $this->app['config']->cacheConfig();
    }
1350675
public function onKernelRequest(GetResponseEvent $event): void
    {
        $request = $event->getRequest();
        $method = $request->getMethod();

        if (
            'DELETE' === $method
            || $request->isMethodSafe(false)
            || !($attributes = RequestAttributesExtractor::extractAttributes($request))
            || !$attributes['receive']
            || (
                    '' === ($requestContent = $request->getContent())
                    && ('POST' === $method || 'PUT' === $method)
               )
        ) {
            return;
        }

        $context = $this->serializerContextBuilder->createFromRequest($request, false, $attributes);
        if (isset($context['input']) && \array_key_exists('class', $context['input']) && null === $context['input']['class']) {
            return;
        }

        // BC check to be removed in 3.0
        if (null !== $this->formatsProvider) {
            $this->formats = $this->formatsProvider->getFormatsFromAttributes($attributes);
        }
        $this->formatMatcher = new FormatMatcher($this->formats);
        $format = $this->getFormat($request);

        $data = $request->attributes->get('data');
        if (null !== $data) {
            $context[AbstractNormalizer::OBJECT_TO_POPULATE] = $data;
        }

        $request->attributes->set(
            'data',
            $this->serializer->deserialize(
                $requestContent, $context['resource_class'], $format, $context
            )
        );
    }
390602
public function onCoreRequest(GetResponseEvent $event)
    {
        $request = $event->getRequest();

        $cms = $this->cmsSelector->retrieve();
        if (!$cms) {
            throw new InternalErrorException('No CMS Manager available');
        }

        // true cms page
        if (PageInterface::PAGE_ROUTE_CMS_NAME === $request->get('_route')) {
            return;
        }

        if (!$this->decoratorStrategy->isRequestDecorable($request)) {
            return;
        }

        $site = $this->siteSelector->retrieve();

        if (!$site) {
            throw new InternalErrorException('No site available for the current request with uri '.htmlspecialchars($request->getUri(), ENT_QUOTES));
        }

        if ($site->getLocale() && $site->getLocale() !== $request->get('_locale')) {
            throw new PageNotFoundException(sprintf('Invalid locale - site.locale=%s - request._locale=%s', $site->getLocale(), $request->get('_locale')));
        }

        try {
            $page = $cms->getPageByRouteName($site, $request->get('_route'));

            if (!$page->getEnabled() && !$this->cmsSelector->isEditor()) {
                throw new PageNotFoundException(sprintf('The page is not enabled : id=%s', $page->getId()));
            }

            $cms->setCurrentPage($page);
        } catch (PageNotFoundException $e) {
            return;
        }
    }
658764
public function onKernelRequest(GetResponseEvent $event): void
    {
        if (!$event->isMasterRequest()) {
            return;
        }

        $attributes = $event->getRequest()->attributes;
        if ($attributes->get(SetIsApiRequestListener::API_FLAG_NAME) !== true) {
            return;
        }

        if (!$attributes->has('itemType')) {
            return;
        }

        $backend = $this->backendRegistry->getBackend($attributes->get('itemType'));
        $this->container->set('netgen_content_browser.current_backend', $backend);
    }
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);
        }
    }
1059469
public function onKernelRequest(GetResponseEvent $event): void
    {
        if (!$event->isMasterRequest()) {
            return;
        }

        $request = $event->getRequest();

        if ($request->attributes->get(SetIsAdminRequestListener::ADMIN_FLAG_NAME) !== true) {
            return;
        }

        if ($this->csrfTokenValidator->validateCsrfToken($request, $this->csrfTokenId)) {
            return;
        }

        throw new AccessDeniedHttpException('Missing or invalid CSRF token');
    }