Reads the SecurityContext from the session.

@param GetResponseEvent $event A GetResponseEvent instance
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);
    }
213732
public function onKernelRequest(GetResponseEvent $event)
  {
      $currentLocale = $this->getCurrentLocale();
      $requestedLocale = $this->getRequestedLocale();

      if ($requestedLocale && $currentLocale != $requestedLocale) {
          $request = $event->getRequest();
          // ugly backwards compatibility fix for symfony 2.0 (start)
          if (!method_exists($request, 'setLocale')) {
              $request = $request->getSession();
          }
          // ugly backwards compatibility fix for symfony 2.0 (end)
          if (!setlocale(LC_MESSAGES, $requestedLocale.'.UTF-8', $requestedLocale.'.utf8', $requestedLocale.'.utf-8', $requestedLocale.'UTF8')) {
              $request->setLocale(null);
              throw new InvalidParameterException("Requested locale '$requestedLocale' could not be set. Is this locale installed? Hint: Execute 'locale -a' on the Linux command line to list installed locales.");
          }
          $request->setLocale($requestedLocale);
      }

      $this->setupGetText();
  }
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()));
        }
      }
    }
  }
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;
        }
    }
396076
public function onKernelRequest(GetResponseEvent $event)
    {
        $request = $event->getRequest();
        foreach ($this->firewalls as $firewall) {
            //firewalls returns true for an exemption, so skip others
            if (true === $firewall->check($request)) {
                return;
            }
        }
    }
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');
    }
827225
public function onKernelRequest(GetResponseEvent $event): void
    {
        $request = $event->getRequest();
        if (
            !($attributes = RequestAttributesExtractor::extractAttributes($request))
            || !$attributes['receive']
        ) {
            return;
        }

        if (null === $filters = $request->attributes->get('_api_filters')) {
            $queryString = RequestParser::getQueryString($request);
            $filters = $queryString ? RequestParser::parseRequestParams($queryString) : null;
        }

        $context = null === $filters ? [] : ['filters' => $filters];
        if ($this->serializerContextBuilder) {
            // Builtin data providers are able to use the serialization context to automatically add join clauses
            $context += $normalizationContext = $this->serializerContextBuilder->createFromRequest($request, true, $attributes);
            $request->attributes->set('_api_normalization_context', $normalizationContext);
        }

        if (isset($attributes['collection_operation_name'])) {
            $request->attributes->set('data', $request->isMethod('POST') ? null : $this->getCollectionData($attributes, $context));

            return;
        }

        $data = [];

        if ($this->identifierConverter) {
            $context[IdentifierConverterInterface::HAS_IDENTIFIER_CONVERTER] = true;
        }

        try {
            $identifiers = $this->extractIdentifiers($request->attributes->all(), $attributes);

            if (isset($attributes['item_operation_name'])) {
                $data = $this->getItemData($identifiers, $attributes, $context);
            } elseif (isset($attributes['subresource_operation_name'])) {
                // Legacy
                if (null === $this->subresourceDataProvider) {
                    throw new RuntimeException('No subresource data provider.');
                }

                $data = $this->getSubresourceData($identifiers, $attributes, $context);
            }
        } catch (InvalidIdentifierException $e) {
            throw new NotFoundHttpException('Not found, because of an invalid identifier configuration', $e);
        }

        if (null === $data) {
            throw new NotFoundHttpException('Not Found');
        }

        $request->attributes->set('data', $data);
    }
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);
    }
135763
public function onKernelRequest(GetResponseEvent $event)
    {
        $request = $event->getRequest();
        foreach ($this->formats as $format => $mimeTypes) {
            $request->setFormat($format, $mimeTypes);
        }
    }
810688
public function handle(GetResponseEvent $event)
    {
        $request = $event->getRequest();
        $application = $event->getKernel()->getApplication();

        if (null !== $application && false === $request->hasSession()) {
            $container = $application->getContainer();
            $event->getRequest()->setSession($container->get('bb_session'));
        }

        parent::handle($event);
    }
836651
public function copyUserLocaleToRequest(GetResponseEvent $event)
    {
        $token = $this->tokenStorage->getToken();
        if (!$token) {
            return;
        }

        $user = $token->getUser();
        if (!$user instanceof UserInterface) {
            return;
        }

        $locale = $user->getLocale();
        $event->getRequest()->setLocale($locale);
        $this->translator->setLocale($locale);
    }
510678
public function onRequest(GetResponseEvent $event)
    {
        if (!$event->isMasterRequest()) {
            return;
        }

        $this->manager->initialize($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));
                }
            }
        }
    }
413984
public function handle(GetResponseEvent $event)
    {
        $request = $event->getRequest();
        $session = $request->getSession();

        if (null === $session || null === $token = $this->securityContext->getToken()) {
            return;
        }

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

        if (null !== $this->logger) {
            $this->logger->info(sprintf("Expired session detected for user named '%s'", $token->getUsername()));
        }

        $this->removeSessionData($session);

        if (null === $this->targetUrl) {
            throw new SessionExpiredException();
        }

        $response = $this->httpUtils->createRedirectResponse($request, $this->targetUrl);
        $event->setResponse($response);
    }
1078820
public function onKernelResponse(FilterResponseEvent $event)
    {
        if ($this->encryptionService->isPerUserEncryptionEnabled()) {
            $request = $event->getRequest();

            // Check if this is one of the security_check routes
            $securityCheckRoutes = $this->settings['security_check_routes'];
            $route = $request->attributes->get('_route');
            if ($route && in_array($route, $securityCheckRoutes)) {
                $user = $this->getUser();

                if ($user) {
                    $password = $request->request->get('_password');
                    $privateKey = $this->keyManager->getUserPrivateKey($user, array('password' => $password));
                    if ($privateKey) {
                        $request->getSession()->set(KeyManager::SESSION_PRIVATE_KEY_PARAM, $privateKey);
                    }
                    else {
                        throw new EncryptionException('Could not load user\'s key');
                    }
                }
            }
        }
    }
1343274
public function onRequestEarly(GetResponseEvent $event)
    {
        $validator = $this->app['config.validator'];
        $response = $validator->checks();
        if ($response instanceof Response) {
            $event->setResponse($response);
        }
    }
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();
                }
            }
        }
    }