Handles basic authentication.

@param GetResponseEvent $event A GetResponseEvent instance
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);
        }
    }
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');
    }
1053455
public function onGetUser(GetUserForTokenEvent $event)
    {
        $userProvider = $event->getUserProvider();

        if (!$userProvider instanceof OAuthUserProviderInterface) {
            return;
        }

        $token = $event->getToken();

        if ($user = $userProvider->loadUserByOAuthCredentials($token)) {
            $token->setUser($user);
        }
    }
1138897
public function onKernelRequest(GetResponseEvent $event): void
    {
        if (!$event->isMasterRequest()) {
            return;
        }

        $request = $event->getRequest();
        $attributes = $request->attributes;
        if ($attributes->get(SetIsApiRequestListener::API_FLAG_NAME) !== true) {
            return;
        }

        if (!$attributes->has('itemType')) {
            return;
        }

        $config = $this->loadConfig($attributes->get('itemType'));

        $customParams = $request->query->get('customParams', []);
        if (!is_array($customParams)) {
            throw new RuntimeException(
                sprintf(
                    'Invalid custom parameters specification for "%s" item type.',
                    $attributes->get('itemType')
                )
            );
        }

        $config->addParameters($customParams);

        $configLoadEvent = new ConfigLoadEvent($config);

        Kernel::VERSION_ID >= 40300 ?
            $this->eventDispatcher->dispatch($configLoadEvent, ContentBrowserEvents::CONFIG_LOAD) :
            $this->eventDispatcher->dispatch(ContentBrowserEvents::CONFIG_LOAD, $configLoadEvent);

        $this->container->set('netgen_content_browser.current_config', $config);
    }
53938
public function onKernelRequest(GetResponseEvent $event): void
    {
        if (!$event->isMasterRequest()) {
            return;
        }

        $request = $event->getRequest();
        if ($request->attributes->has('ngbmContext')) {
            $context = $request->attributes->get('ngbmContext');
            $context = is_array($context) ? $context : [];

            $this->context->add($context);

            return;
        }

        if ($request->query->has('ngbmContext')) {
            $this->context->add($this->getUriContext($request));

            return;
        }

        $this->contextBuilder->buildContext($this->context);
    }
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();
    }
1053781
public function onKernelRequest(GetResponseEvent $event)
    {
        if (!$event->isMasterRequest()) {
            return;
        }

        if (!$this->csrfTokenManager instanceof CsrfTokenManagerInterface) {
            return;
        }

        $request = $event->getRequest();

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

        if ($request->attributes->get('_route') !== $this->routeName) {
            return;
        }

        $session = $event->getRequest()->getSession();
        if (!$session->isStarted()) {
            return;
        }

        if ($request->headers->get('X-CSRF-Token') !== null) {
            return;
        }

        $csrfToken = $this->csrfTokenManager->getToken($this->csrfTokenId)->getValue();

        $request->headers->set('X-CSRF-Token', $csrfToken);
    }
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.');
        }
    }
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'));
        }
    }
536940
public function onKernelRequest(GetResponseEvent $event)
    {
        $request = $event->getRequest();
        $route = $this->router->getRouteCollection()->get(
            $request->attributes->get('_route')
        );
        if (!$route || !$themeOptions = $route->getOption('synapse_theme')) {
            return;
        }

        $request->attributes->set('synapse_theme', $this->match(
            $themeOptions,
            new ThemeMatchingContext(array(
                'host' => $request->server->get('HTTP_HOST'),
            ))
        ));
    }
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);
    }
566098
public function handle(Authenticating $event)
    {
        $username = $this->getPrefix().$event->username.$this->getSuffix();

        Log::info("User '{$event->user->getCommonName()}' is authenticating with username: '{$username}'");
    }
917553
public function onKernelRequest(GetResponseEvent $event)
    {
        if (!$event->isMasterRequest()) {
            return;
        }
        if ($this->debug) {
            $this->logRequest($event->getRequest());
        }
    }
402084
public function onKernelRequest(GetResponseEvent $event)
    {
        /** @var \eZ\Publish\Core\MVC\ConfigResolverInterface $configResolver */
        $request = $event->getRequest();
        $session = $request->getSession();
        if (
            $event->getRequestType() !== HttpKernelInterface::MASTER_REQUEST
            || !$this->configResolver->getParameter('legacy_mode')
            || !($session->isStarted() && $session->has('eZUserLoggedInID'))
        ) {
            return;
        }

        try {
            $apiUser = $this->repository->getUserService()->loadUser($session->get('eZUserLoggedInID'));
            $this->repository->setCurrentUser($apiUser);

            $token = $this->tokenStorage->getToken();
            if ($token instanceof TokenInterface) {
                $token->setUser(new User($apiUser));
                // Don't embed if we already have a LegacyToken, to avoid nested session storage.
                if (!$token instanceof LegacyToken) {
                    $this->tokenStorage->setToken(new LegacyToken($token));
                }
            }
        } catch (NotFoundException $e) {
            // Invalid user ID, the user may have been removed => invalidate the token and the session.
            $this->tokenStorage->setToken(null);
            $session->invalidate();
        }
    }
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
        }
    }
1205881
public function onKernelRequest(GetResponseEvent $event)
    {
        if (!in_array($event->getRequest()->attributes->get('_route'), $this->allowedRoutes, true)) {
            return;
        }

        $this->requestListener->onKernelRequest($event);
    }
1111032
public function onKernelRequest(GetResponseEvent $event)
    {
        $this->setUpRequiredFolders();
        $this->setUpPageTree();
        $this->checkTemplatesSlots();
        $this->setupBootstrapVersion();
        $this->setupConfiguration();
    }