@param GetResponseEvent $event

@throws \Exception
352536
public function onKernelRequest(GetResponseEvent $event)
    {
        if (!$event->isMasterRequest()) {
            return;
        }

        $request = $event->getRequest();

        // /app_dev.php/contacts?5454
        $requestUri = $request->getRequestUri();

        // /contacts
        $pathInfo = $request->getPathInfo();

        // /app_dev.php
        $baseUrl = $request->getBaseUrl();

        $uri = str_replace($baseUrl, '', $requestUri);

        $em = $this->doctrine->getManager();

        /** @var RedirectRepository $redirectRepository */
        $redirectRepository = $em->getRepository('CompoRedirectBundle:Redirect');

        /** @var Redirect $redirect */
        $redirect = $redirectRepository->findOneBy(
            [
                'urIn' => array_unique([$uri, $pathInfo]),
                'enabled' => true,
            ]
        );

        if ($redirect) {
            $event->setResponse(new RedirectResponse($baseUrl . $redirect->getUrOut(), 301));
            $event->stopPropagation();
        }

        $pageRepository = $em->getRepository(Page::class);

        $lastSlash = mb_substr($pathInfo, -1);

        if ('/' !== $lastSlash) {
            $page = $pageRepository->findOneBy(
                [
                    'url' => [$pathInfo . '/'],
                ]
            );

            if ($page) {
                $event->setResponse(new RedirectResponse($baseUrl . $pathInfo . '/', 301));
                $event->stopPropagation();
            }
        }
    }
294304
public function handle(GetResponseEvent $event)
    {
        if (null !== $this->tokenStorage->getToken()) {
            // user is already authenticated, there is nothing to do.
            return;
        }

        // creates an anonymous token with a dedicated role.
        $this->tokenStorage->setToken(
            new AnonymousToken($this->secret, 'anon.', ['ROLE_ANONYMOUS'])
        );

        if (null !== $this->logger) {
            $this->logger->info(sprintf('Populated SecurityContext with an anonymous Token'));
        }
    }
70155
public function onKernelRequest(GetResponseEvent $event)
    {
        if ('sonata_admin_dashboard' === $event->getRequest()->get('_route')) {
            $settingsManager = $this->container->get('sylius.settings_manager');

            $settings = $settingsManager->load('compo_dashboard');

            $admin = $this->container->get('sonata.dashboard.admin.dashboard');

            $modelManager = $admin->getModelManager();

            if (!$settings['default']) {
                return;
            }

            $defaultDashboard = $modelManager->findOneBy(
                $admin->getClass(),
                ['id' => $settings['default']]
            );

            if (!$defaultDashboard) {
                return;
            }

            if ($defaultDashboard) {
                $url = $admin->generateObjectUrl('render', $defaultDashboard);
                $event->setResponse(new RedirectResponse($url));
            }
        }
    }
1012761
public function onKernelRequest(GetResponseEvent $event)
    {
        $request = $event->getRequest();

        if (!$request) {
            return;
        }

        if (!$request->hasSession()) {
            return;
        }

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

        $adminCode = $request->get('_sonata_admin');

        if (!is_null($adminCode)) {
            $this->admin = $this->adminPool->getAdminByAdminCode($adminCode);
            $this->admin->setRequest($request);
            if (!$this->admin) {
                throw new \RuntimeException(sprintf(
                    'Unable to find the admin class related to the current controller (%s)',
                    get_class($this)
                ));
            }

            foreach ($this->admin->getExtensions() as $extension) {
                $this->setTrackedAction($extension);
            }
            $this->setTrackedAction($this->admin);
        }
    }
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.');
            }
        }
    }
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);
    }
250752
public function onKernelRequest(GetResponseEvent $event)
    {
        $request = $event->getRequest();

        if (!$locale = $this->determineLocale($event)) {
            return;
        }

        $this->chooser->setLocale($locale);

        if (self::FALLBACK_HARDCODED === $this->fallback) {
            return;
        }

        // expand language list to include base locales
        // copy-pasted from Request::getPreferredLanguage
        $preferredLanguages = $request->getLanguages();
        $extendedPreferredLanguages = [];
        foreach ($preferredLanguages as $language) {
            $extendedPreferredLanguages[] = $language;
            if (false !== $position = strpos($language, '_')) {
                $superLanguage = substr($language, 0, $position);
                if (!in_array($superLanguage, $preferredLanguages)) {
                    $extendedPreferredLanguages[] = $superLanguage;
                }
            }
        }
        $order = array_intersect($this->allowedLocales, $extendedPreferredLanguages);
        $this->chooser->setFallbackLocales($locale, $order, self::FALLBACK_REPLACE === $this->fallback);
    }
490047
public function handle(GetResponseEvent $event): void
    {
        if ($this->isEnabled()) {
            $hostRole = $this->getHostRole($event);

            if (null !== $hostRole) {
                $this->sidManager->addSpecialRole($hostRole);
            }
        }
    }
752222
public function handle(GetResponseEvent $event)
    {
        $symfonyRequest = $event->getRequest();
        $request = $this->requestTransformer->transform($symfonyRequest);

        try {
            $tokenType = $this->tokenTypeResolver->resolve($request);
        } catch(UnsupportedTokenTypeException $e) {
            // this is not an OAuth2 request or is using not supported token type
            return;
        }

        $token = new OAuth2Token();
        $token->setRequest($request);

        try {
            $authToken = $this->authenticationManager->authenticate($token);
            $this->tokenStorage->setToken($authToken);
            return;
        } catch (AuthenticationException $e) {
            $event->setResponse(
                $this->authenticationEntryPoint->start(
                    $symfonyRequest, $e
                )
            );
        }
    }
414994
public function onRequest(GetResponseEvent $event)
    {
        if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) {
            return;
        }
        $patterns = $this->provider->getPatterns();
        if ($patterns) {
            foreach ($patterns as $pattern) {
                if ($pattern['matcher']->matches($event->getRequest())) {
                   $firewall = $this->provider->getFirewall($pattern['config']);
                   $firewall->handle();
                }
            }
        }
    }
175466
public function onKernelRequest(GetResponseEvent $event): void
    {
        $request = $event->getRequest();
        if (!$attributes = RequestAttributesExtractor::extractAttributes($request)) {
            return;
        }

        $resourceMetadata = $this->resourceMetadataFactory->create($attributes['resource_class']);

        $isGranted = $resourceMetadata->getOperationAttribute($attributes, 'access_control', null, true);

        if (null === $isGranted) {
            return;
        }

        $extraVariables = $request->attributes->all();
        $extraVariables['object'] = $request->attributes->get('data');
        $extraVariables['request'] = $request;

        if (!$this->resourceAccessChecker->isGranted($attributes['resource_class'], $isGranted, $extraVariables)) {
            throw new AccessDeniedException($resourceMetadata->getOperationAttribute($attributes, 'access_control_message', 'Access Denied.', true));
        }
    }
42425
public function onKernelRequest(GetResponseEvent $event)
    {
        $request = $event->getRequest();

        // Loads Wordpress source code in order to allow use of WordPress functions in Symfony.
        if ('ekino_wordpress_catchall' !== $request->attributes->get('_route')) {
            $this->wordpress->loadWordpress();
        }

        $this->checkAuthentication($request);
    }
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));
            }
        }
    }
881850
public function onKernelRequest(GetResponseEvent $event)
    {
        $request = $event->getRequest();

        if (!$request->attributes->get(FOSRestBundle::ZONE_ATTRIBUTE, true)) {
            return;
        }

        try {
            $format = $request->getRequestFormat(null);
            if (null === $format) {
                $accept = $this->formatNegotiator->getBest('');
                if (null !== $accept && 0.0 < $accept->getQuality()) {
                    $format = $request->getFormat($accept->getValue());
                    if (null !== $format) {
                        $request->attributes->set('media_type', $accept->getValue());
                    }
                }
            }

            if (null === $format) {
                if (HttpKernelInterface::MASTER_REQUEST === $event->getRequestType()) {
                    throw new NotAcceptableHttpException('No matching accepted Response format could be determined');
                }

                return;
            }

            $request->setRequestFormat($format);
        } catch (StopFormatListenerException $e) {
            // nothing to do
        }
    }
886989
public function onKernelRequest(GetResponseEvent $event) {
		if (HttpKernel::MASTER_REQUEST != $event->getRequestType()) {
			return;
		}

		if ($event->getRequest()->headers->has('x-amz-sns-message-type')) {
			$result = $this->handleSnsNotifications($event);
			$event->setResponse(new Response($result, 200));
		}

		if ($event->getRequest()->headers->has('iron-message-id')) {
			$result = $this->handleIronMqNotifications($event);
			$event->setResponse(new Response($result, 200));
		}
	}
652940
public function onKernelRequest(GetResponseEvent $event)
    {
        if ($event->getRequestType() !== HttpKernelInterface::MASTER_REQUEST) {
            return;
        }

        $this->client->setFallbackType('HTTP');

        $this->resolver->set($event->getRequest());
    }
1343274
public function onRequestEarly(GetResponseEvent $event)
    {
        $validator = $this->app['config.validator'];
        $response = $validator->checks();
        if ($response instanceof Response) {
            $event->setResponse($response);
        }
    }