Redirect requests for challenge go to custom module controller route.

@param \Symfony\Component\HttpKernel\Event\GetResponseEvent $event
491220
public function redirectMyContentTypeNode(GetResponseEvent $event) {
    $request = $event->getRequest();
    $language = $this->languageManager->getCurrentLanguage()->getId();

    if ($request->attributes->get('_route') !== 'entity.node.canonical') {
      return;
    }

    if ($request->attributes->get('node')->getType() !== 'challenge') {
      return;
    }

    // $redirect_url = Url::fromUri('entity:node/123');.
    $node = $request->attributes->get('node');
    if ($language == 'fr') {
      $redirect_url = '/fr/defis/' . $node->getTranslation('fr')->get('field_friendly_url')->getValue()[0]['value'];
    }
    else {
      $redirect_url = '/en/challenges/' . $node->get('field_friendly_url')->getValue()[0]['value'];
    }

    $response = new RedirectResponse($redirect_url, 301);
    $event->setResponse($response);
  }
761363
public function handle(GetResponseEvent $event)
    {
        $this->joomla->getApplication();
        $user = \JFactory::getUser();

        if ($user instanceof UserInterface && $user->getUsername() !== null) {

            $token = new JoomlaToken(
                $user,
                $user->getPassword(),
                $this->providerKey,
                $user->getRoles()
            );

            try {
                $authToken = $this->authenticationManager->authenticate($token);
                $this->securityContext->setToken($authToken);

                return;
            } catch (AuthenticationException $failed) {
                // TODO logging
            }
        } else {
            $this->securityContext->setToken(null);
        }
    }
786399
public function onEarlyKernelRequest(GetResponseEvent $event)
    {
        $request = $event->getRequest();
        foreach ($this->customFormats as $name => $mimeTypes) {
            $request->setFormat($name, $mimeTypes);
        }
    }
567470
public function handle(GetResponseEvent $event)
    {
        $request = $event->getRequest();

        if ($request->getMethod() === Request::METHOD_OPTIONS) {
            $this->getTokenStorage()->setToken(new AnonymousToken('', 'anonymous', []));
            return;
        }

        if (
            !$request->headers->has('Authorization') ||
            !preg_match('/Bearer (.*)/', $request->headers->get('Authorization'))
        ) {
            $token = new AnonymousToken('', 'anonymous');
            $this->getTokenStorage()->setToken($token);
            return;
        }

        $this->doHandle($event);
    }
391514
public function onKernelRequest(GetResponseEvent $event)
    {
        $request = $event->getRequest();

        if ($this->fragmentPath !== rawurldecode($request->getPathInfo())) {
            return;
        }

        if ($request->attributes->has('_controller')) {
            // Is a sub-request: no need to parse _path but it should still be removed from query parameters as below.
            $request->query->remove('_path');

            return;
        }

        if ($event->isMasterRequest()) {
            $this->validateRequest($request);
        }

        parse_str($request->query->get('_path', ''), $attributes);
        $request->attributes->add($attributes);
        $request->attributes->set('_route_params', array_replace($request->attributes->get('_route_params', []), $attributes));
        $request->query->remove('_path');
    }
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);
        }
    }
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);
  }
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();
        }
    }
768940
public function onKernelRequest(GetResponseEvent $event): void
    {
        $request = $event->getRequest();
        if (
            'html' !== $request->getRequestFormat('') ||
            !($request->attributes->has('_api_resource_class') || $request->attributes->getBoolean('_api_respond', false))
        ) {
            return;
        }

        $request->attributes->set('_controller', 'api_platform.swagger.action.ui');
    }
820770
public function profileLandingPage(GetResponseEvent $event) {
    // First check if the current route is the group canonical.
    $routeMatch = $this->currentRoute->getRouteName();
    // Not group canonical, then we leave.
    if ($routeMatch !== 'entity.user.canonical') {
      return;
    }

    // Fetch the user parameter and check if's an actual user.
    $user = $this->currentRoute->getParameter('user');
    // Not user, then we leave.
    if (!$user instanceof User) {
      return;
    }

    // Set the already default redirect route.
    $defaultRoute = 'social_user.stream';

    // Fetch the settings.
    $settings = $this->configFactory->get('social_user.settings');

    // Check there is a custom route set.
    if ($this->currentUser->id() !== $user->id()) {
      $route = $settings->get('social_user_profile_landingpage');
    }

    // Still no route here? Then we use the normal default.
    if (!isset($route)) {
      $route = $defaultRoute;
    }

    // Determine the URL we want to redirect to.
    $url = Url::fromRoute($route, ['user' => $user->id()]);

    // If it's not set, set to canonical, or the current user has no access.
    if (!isset($route) || ($route === $routeMatch) || $url->access($this->currentUser) === FALSE) {
      // This basically means that the normal flow remains intact.
      return;
    }
    // Redirect.
    $event->setResponse(new RedirectResponse($url->toString()));
  }
411409
public function onKernelRequest(GetResponseEvent $event)
    {
        $request = $event->getRequest();
        if (Zone::get($request)) {
            return;
        }

        $this->setZone($request);
    }
12669
public function handle(GetResponseEvent $event)
    {
        $request = BridgeRequest::createFromRequest($event->getRequest());
        $response = new BridgeResponse;

        if (!$this->oauth2Server->verifyResourceRequest($request, $response)) {
            return;
        }

        try {
            $token = $this->oauth2Server->getAccessTokenData($request);
            $token = $this->authenticationManager->authenticate(
                new OAuth2Token(
                    $token['client_id'],
                    $token['user_id'],
                    $token['access_token'],
                    $this->providerKey,
                    [],
                    explode(" ", $token['scope'])
                )
            );
            $this->tokenStorage->setToken($token);
        } catch (AuthenticationException $failed) {
            $this->handleAuthenticationError($event, $request, $failed);
        }
    }
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));
            }
        }
    }
161034
public function onKernelRequest(GetResponseEvent $event)
    {
        $request = $event->getRequest();

        foreach ($this->requestMatchers as $requestMatcher) {
            if ($requestMatcher->matches($request)) {
                $request->attributes->set(FOSRestBundle::ZONE_ATTRIBUTE, true);

                return;
            }
        }

        $request->attributes->set(FOSRestBundle::ZONE_ATTRIBUTE, false);
    }
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);
        }
    }
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);
    }
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;
        }
    }