This method validates CSRF token if CSRF protection is enabled.

@param \Symfony\Component\HttpKernel\Event\GetResponseEvent $event

@throws \eZ\Publish\Core\Base\Exceptions\UnauthorizedException
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);
    }
510678
public function onRequest(GetResponseEvent $event)
    {
        if (!$event->isMasterRequest()) {
            return;
        }

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

        $currentClient = Hub::getCurrent()->getClient();
        if (null === $currentClient || ! $currentClient->getOptions()->shouldSendDefaultPii()) {
            return;
        }

        $token = null;

        if ($this->tokenStorage instanceof TokenStorageInterface) {
            $token = $this->tokenStorage->getToken();
        }

        if (
            null !== $token
            && null !== $this->authorizationChecker
            && $token->isAuthenticated()
            && $this->authorizationChecker->isGranted(AuthenticatedVoter::IS_AUTHENTICATED_REMEMBERED)
        ) {
            $userData = $this->getUserData($token->getUser());
        }

        $userData['ip_address'] = $event->getRequest()->getClientIp();

        Hub::getCurrent()
            ->configureScope(function (Scope $scope) use ($userData): void {
                $scope->setUser($userData);
            });
    }
8691
public function onKernelRequest(GetResponseEvent $event)
    {
        $url = $event->getRequest()->getRequestUri();
        $token = $this->tokenStorage->getToken();

        if ($token && $this->isAdminToken($this->providerKey, $token) && $this->adminRouteHelper->isAdminRoute($url)) {
            $locale = $token->getUser()->getAdminLocale();

            if (!$locale) {
                $locale = $this->defaultAdminLocale;
            }

            $this->translator->setLocale($locale);
        }
    }
415616
public function checkSessionActivity(GetResponseEvent $event)
    {
        $request = $event->getRequest();

        if ($request->request->has('oauth_token')
            || $request->query->has('oauth_token')
            || $request->query->has('LOG')
            || null === $moduleId = $this->getModuleId($request->getPathInfo())
        ) {
            return;
        }

        if ($this->isAdminJsPolledRoute($moduleId, $request)) {
            return;
        }

        if ($moduleId === self::$modulesIds['prod'] && $this->isFlashUploadRequest($request)) {
            return;
        }

        // if we are already disconnected (ex. from another window), quit immediately
        if (!($this->app->getAuthenticator()->isAuthenticated())) {
            $this->setDisconnectResponse($event);

            return;
        }

        /** @var Session $session */
        $session = $this->app['repo.sessions']->find($this->app['session']->get('session_id'));

        $idle = 0;

        if (isset($this->app['phraseanet.configuration']['session']['idle'])) {
            $idle = (int)$this->app['phraseanet.configuration']['session']['idle'];
        }

        $now = new \DateTime();

        if ($idle > 0 && $now->getTimestamp() > $session->getUpdated()->getTimestamp() + $idle) {
            // we must disconnect due to idle time
            $this->app->getAuthenticator()->closeAccount();
            $this->setDisconnectResponse($event);

            return;
        }

        $entityManager = $this->app['orm.em'];

        $module = $this->addOrUpdateSessionModule($session, $moduleId, $now);

        $entityManager->persist($module);
        $entityManager->persist($session);
        $entityManager->flush();
    }
1022682
public function handle(GetResponseEvent $event)
    {
        if (!$event->isMasterRequest()) {
            return;
        }

        if (!$this->authorizationChecker->isGranted(self::ATTRIBUTE, $event->getRequest())) {
            throw new AccessDeniedException();
        }
    }
963458
public function handle(GetResponseEvent $event)
    {
        if (!$this->registered && null !== $this->dispatcher && $event->isMasterRequest()) {
            $this->dispatcher->addListener(KernelEvents::RESPONSE, array($this, 'onKernelResponse'));
            $this->registered = true;
        }

        $request = $event->getRequest();
        $session = $request->getSession();
        /*$sessionId = $session->getId();
        if(empty($sessionId))
        {
            $session = null;
        }*/

        if (null === $session || null === $token = $session->get('_security_'.$this->contextKey)) {
            $this->context->setToken(null);

            return;
        }

        $token = unserialize($token);

        if (null !== $this->logger) {
            $this->logger->debug('Read SecurityContext from the session');
        }

        if ($token instanceof TokenInterface) {
            $token = $this->refreshUser($token);
        } elseif (null !== $token) {
            if (null !== $this->logger) {
                $this->logger->warning(sprintf('Session includes a "%s" where a security token is expected', is_object($token) ? get_class($token) : gettype($token)));
            }

            $token = null;
        }

        $this->context->setToken($token);
    }
1047499
public function onKernelRequest(GetResponseEvent $event): void
    {
        $request = $event->getRequest();

        if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType() || !$this->isAdminSiteAccess($request)) {
            return;
        }

        $additionalTranslations = $this->configResolver->getParameter('user_preferences.additional_translations');
        $preferableLocales = $this->userLanguagePreferenceProvider->getPreferredLocales($request);
        $locale = null;

        foreach ($preferableLocales as $preferableLocale) {
            if (\in_array($preferableLocale, $this->availableTranslations, true)
                || \in_array($preferableLocale, $additionalTranslations, true)
            ) {
                $locale = $preferableLocale;
                break;
            }
        }
        $locale = $locale ?? reset($preferableLocales);
        $request->setLocale($locale);
        $request->attributes->set('_locale', $locale);
        // Set of the current locale on the translator service is needed because RequestLocaleListener has lower
        // priority than LocaleListener and messages are not translated on login, forgot and reset password pages.
        $this->translator->setLocale($locale);
    }
652940
public function onKernelRequest(GetResponseEvent $event)
    {
        if ($event->getRequestType() !== HttpKernelInterface::MASTER_REQUEST) {
            return;
        }

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

        $this->resolver->set($event->getRequest());
    }
184976
public function onKernelException(GetResponseForExceptionEvent $event)
    {
        $request = $event->getRequest();
        $exception = $event->getException();

        if ($request->isXmlHttpRequest()) {
            if ($exception instanceof AccessDeniedException) {
                $token = $this->context->getToken();
                if (!$this->authenticationTrustResolver->isAnonymous($token)) {
                    $event->setResponse(new Response('You haven\'t enough privileges to perform the required action', 403));
                }
            }
        }
    }
649736
public function checkForRedirection(GetResponseEvent $event) {
    // Check if there is a group object on the current route.
    $group = _social_group_get_current_group();
    // Get the current route name for the checks being performed below.
    $routeMatch = \Drupal::routeMatch()->getRouteName();
    // Get the current user.
    $user = \Drupal::currentUser();
    // The array of forbidden routes.
    $routes = [
      'entity.group.canonical',
      'entity.group.join',
      'view.group_events.page_group_events',
      'view.group_topics.page_group_topics',
    ];
    // If a group is set, and the type is closed_group.
    if ($group && $group->getGroupType()->id() == 'closed_group') {
      if ($user->id() != 1) {
        if ($user->hasPermission('manage all groups')) {
          return;
        }
        // If the user is not an member of this group.
        elseif (!$group->getMember($user) && in_array($routeMatch, $routes)) {
          $event->setResponse(new RedirectResponse(Url::fromRoute('view.group_information.page_group_about', ['group' => $group->id()])
            ->toString()));
        }
      }
    }
  }
454770
public function onKernelRequest(GetResponseEvent $event)
    {
        $request = $event->getRequest();
        $theme = $this->activeTheme->getName();
        $controllers = $request->attributes->get(static::ATTRIBUTE_KEY);
        if (isset($controllers[$theme])) {
            $request->attributes->set('_controller', $controllers[$theme]);
        }

        // Get rid of the attribute in the request to avoid it showing up in generated URLs
        $request->attributes->remove(static::ATTRIBUTE_KEY);
        $routeParams = $request->attributes->get('_route_params');
        if (null !== $routeParams) {
            unset($routeParams[static::ATTRIBUTE_KEY]);
            $request->attributes->set('_route_params', $routeParams);
        }
    }
460840
public function onKernelRequest(GetResponseEvent $event) {

        $this->setRequest($event->getRequest());

        // Register the theme providers.
        $this->getThemeManager()->addGlobal();

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

            if (null !== $hostRole) {
                $this->sidManager->addSpecialRole($hostRole);
            }
        }
    }
594529
public function onKernelResponse(FilterResponseEvent $event)
    {
        $event->getResponse()->headers->set(self::HEADER_NAME, $this->requestId->get());
    }
197073
public function onKernelRequest(GetResponseEvent $event)
	{
		if (!$event->isMasterRequest()) {
			return;
		}
		
		$request = $event->getRequest();
		if ($this->reverseProxies) {
			$request->setTrustedProxies($this->reverseProxies);
		}
		if ($this->xForwardedFor) {
			$request->setTrustedHeaderName(Request::HEADER_CLIENT_IP, $this->xForwardedFor);
		}
		
		$ip = $request->getClientIp();
		$start = microtime(true);

		$this->key=$this->prefix.'_'.$ip;
		
		$this->memcache->add($this->key,0,false,$this->lockMaxWait);
		while (true) {
			$this->incremented = true;
			if ($this->memcache->increment($this->key)<=$this->concurrency) {
				break;
			}
			$this->incremented = false;
			$this->memcache->decrement($this->key);
			if (!$this->spinLockWait || microtime(true)-$start>$this->lockMaxWait) {
				throw new TooManyRequestsHttpException();
			}
			usleep($this->spinLockWait);
		}
	}