Handles anonymous authentication.

@param GetResponseEvent $event A GetResponseEvent instance
355319
public function handle(GetResponseEvent $event): void
    {
        if ($this->isEnabled() && $this->hasRole() && $this->isAnonymous()) {
            $this->sidManager->addSpecialRole($this->config['role']);
        }
    }
510678
public function onRequest(GetResponseEvent $event)
    {
        if (!$event->isMasterRequest()) {
            return;
        }

        $this->manager->initialize($event->getRequest());
    }
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');
    }
297940
public function onKernelRequest(GetResponseEvent $event)
    {
        if (
            HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()
            ||
            $this->routeMatcher->match($event->getRequest(), $this->exclude)
            ||
            !$this->routeMatcher->match($event->getRequest(), $this->routes)
        ) {
            return;
        }

        $value = $event->getRequest()->headers->get($this->headerName);
        if (!$value || !$this->angularCsrfTokenManager->isTokenValid($value)) {
            throw new AccessDeniedHttpException('Bad CSRF token.');
        }
    }
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;
            }
        }
    }
372494
public function handle(GetResponseEvent $event)
    {
        if (null !== $this->logger) {
            $this->logger->info('Checking for guard authentication credentials.', array('firewall_key' => $this->providerKey, 'authenticators' => count($this->guardAuthenticators)));
        }

        foreach ($this->guardAuthenticators as $key => $guardAuthenticator) {
            // get a key that's unique to *this* guard authenticator
            // this MUST be the same as GuardAuthenticationProvider
            $uniqueGuardKey = $this->providerKey.'_'.$key;

            $this->executeGuardAuthenticator($uniqueGuardKey, $guardAuthenticator, $event);
        }
    }
1158571
public function onKernelRequest(GetResponseEvent $event)
    {
        $request = $event->getRequest();
        // Ignore sub-requests, including fragments.
        if (!$this->isMasterRequest($request, $event->getRequestType())) {
            return;
        }

        $siteAccess = $request->attributes->get('siteaccess');
        if (!$siteAccess instanceof SiteAccess) {
            return;
        }

        $token = $this->tokenStorage->getToken();
        if ($token === null) {
            return;
        }

        if (
            // Leave access to login route, so that user can attempt re-authentication.
            $request->attributes->get('_route') !== 'login'
            && !$this->hasAccess($siteAccess, $token->getUsername())
        ) {
            throw new UnauthorizedSiteAccessException($siteAccess, $token->getUsername());
        }
    }
265446
public function onKernelRequest(Event\GetResponseEvent $event)
    {
        if ($event->getRequestType() === HttpKernelInterface::MASTER_REQUEST) {
            $request = $event->getRequest();
            $publicUrl = rawurldecode($request->getRequestUri());

            if ($this->isExcluded($publicUrl)) {
                // don't process urls which are marked as excluded.
                return;
            }

            if ($this->isParamsEnabled) {
                if (false !== ($queryMark = strpos($publicUrl, '?'))) {
                    $originalUrl = $publicUrl;
                    $publicUrl = substr($originalUrl, 0, $queryMark);
                    $queryString = substr($originalUrl, $queryMark);
                } else {
                    $queryString = null;
                }

                $parts = explode('/', $publicUrl);
                $params = [];
                while (false !== strpos(end($parts), '=')) {
                    array_push($params, array_pop($parts));
                }
                if ($params) {
                    $publicUrl = join('/', $parts);

                    $parser = new UriParser();
                    $request->query->add($parser->parseUri(join('/', array_reverse($params))));

                    if (!$this->aliasing->hasInternalAlias($publicUrl, false)) {
                        $this->rewriteRequest($event, $publicUrl . $queryString);

                        return;
                    }
                }
            }

            /** @var UrlAlias $url */
            if ($url = $this->aliasing->hasInternalAlias($publicUrl, true)) {
                switch ($url->getMode()) {
                    case UrlAlias::REWRITE:
                        $this->rewriteRequest($event, $url->getInternalUrl());
                        break;
                    case UrlAlias::MOVE:
                    case UrlAlias::ALIAS:
                        $event->setResponse(new RedirectResponse($url->getInternalUrl(), $url->getMode()));
                        break;
                    default:
                        throw new \UnexpectedValueException(
                            sprintf(
                                'Invalid mode %s for UrlAlias %s.',
                                $url->getMode(),
                                json_encode($url)
                            )
                        );
                }
            } elseif (strpos($publicUrl, '?') !== false) {
                // allow aliases to receive the query string.

                $publicUrl = substr($publicUrl, 0, strpos($publicUrl, '?'));
                if ($url = $this->aliasing->hasInternalAlias($publicUrl, true, UrlAlias::REWRITE)) {
                    $this->rewriteRequest($event, $url->getInternalUrl());

                    return;
                }
            }
        }
    }
504828
public function onKernelRequest(GetResponseEvent $event)
    {
        $isRestRequest = true;

        if (!$this->hasRestPrefix($event->getRequest())) {
            $isRestRequest = false;
        }

        $event->getRequest()->attributes->set('is_rest_request', $isRestRequest);
    }
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);
    }
1159159
public function onKernelRequest(GetResponseEvent $event): void
    {
        if (!$event->isMasterRequest()) {
            return;
        }

        $request = $event->getRequest();
        $currentRoute = $request->attributes->get('_route', '');
        if (mb_stripos($currentRoute, self::API_ROUTE_PREFIX) !== 0) {
            return;
        }

        $request->attributes->set(self::API_FLAG_NAME, true);
    }
330744
public function onCoreException(GetResponseForExceptionEvent $event)
	{
	    $exception = $event->getException();
	    $request = $event->getRequest();

    	if ($request->isXmlHttpRequest()) {
    		$msg = "";
    		if($exception instanceof AccessDeniedException ) {
    			$msg = "User Not Authenticated";
    		} elseif($exception instanceof AuthenticationCredentialsNotFoundException) {
    			$msg = "User Not Allowed";
    		} elseif($exception instanceof AuthenticationException) {
    			// Change this
    			$msg = "User Not Authenticated";
    		}

    		if($msg) {
    			$responseData = array('status' => 403, 'reason' => $msg);
    			$response = new JsonResponse();
    			$response->setData($responseData);
    			$response->setStatusCode($responseData['status']);
    			$event->setResponse($response);
    		}
	    }
	}
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);
            });
    }
355369
public function redirect(GetResponseEvent $event)
    {
        $isAdmin = false;
        $connected = false;

        if ($token = $this->tokenStorage->getToken()) {
            foreach ($this->tokenStorage->getToken()->getRoles() as $role) {
                if ('ROLE_ADMIN' === $role->getRole()) {
                    $isAdmin = true;
                }
            }

            if ($token instanceof UsernamePasswordToken) {
                $connected = true;
            }
        }
        $currentUri = $this->requestStack->getMasterRequest()->getUri();
        $url = $this->router->generate('claroline_maintenance_alert');

        if (!$isAdmin && $connected && $this->config->getParameter('maintenance.enable') && !strpos($currentUri, $url)) {
            $response = new RedirectResponse($url);

            $event->setResponse($response);
        }
    }
1322387
public function onKernelRequest(GetResponseEvent $event)
    {
        if (!$event->isMasterRequest()) {
            return;
        }
        $request = $event->getRequest();

        if ($request::getTrustedProxies()) {
            $request->getClientIps();
        }

        $request->getHost();
    }
1002135
public function handle(GetResponseEvent $event)
    {
        $request = $event->getRequest();

        if (!$this->keyExtractor->hasKey($request)) {
            $response = new Response();
            $response->setStatusCode(401);
            $event->setResponse($response);
            return ;
        }

        $apiKey = $this->keyExtractor->extractKey($request);

        $token = new ApiKeyUserToken();
        $token->setApiKey($apiKey);

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

            return;
        } catch (AuthenticationException $failed) {
            $token = $this->tokenStorage->getToken();
            if ($token instanceof ApiKeyUserToken && $token->getCredentials() == $apiKey) {
                $this->tokenStorage->setToken(null);
            }

            $message = $failed->getMessage();
        }

        $response = new Response();
        $response->setContent($message);
        $response->setStatusCode(403);
        $event->setResponse($response);
    }
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));
                }
            }
        }
    }