bundle/EventListener/SecurityListener.php
public function onKernelBuilt(PostBuildKernelEvent $event)
    {
        $currentRequest = $this->requestStack->getCurrentRequest();

        // Ignore if not in web context, if legacy_mode is active or if user is not authenticated
        if (
            $currentRequest === null
            || !$event->getKernelHandler() instanceof ezpWebBasedKernelHandler
            || $this->configResolver->getParameter('legacy_mode') === true
            || !$this->isUserAuthenticated()
        ) {
            return;
        }

        /*
        Siteaccesses running with legacy_mode=false and RequireUserLogin=true have issues with
        login redirects when protected legacy views are accessed via URL before the user is logged in.
        This is because RequireUserLogin specific code in legacy kernel checks for existence of
        'eZUserLoggedInID' DURING the legacy kernel initialization process. Since 'eZUserLoggedInID'
        session variable can only be set AFTER the legacy kernel is built and initialized,
        via runCallback method, the code always fails, causing repeated login screens.

        This is a workaround to set the session variable after the kernel is built, but before
        it's initialized, so the RequireUserLogin code should work fine.
        */

        $currentRequest->getSession()->set(
            'eZUserLoggedInID',
            $this->repository->getCurrentUser()->id
        );
    }
public function onKernelBuilt(PostBuildKernelEvent $event)
    {
        $currentRequest = $this->requestStack->getCurrentRequest();

        // Ignore if not in web context, if legacy_mode is active or if user is not authenticated
        if (
            $currentRequest === null
            || !$event->getKernelHandler() instanceof ezpWebBasedKernelHandler
            || $this->configResolver->getParameter('legacy_mode') === true
            || !$this->isUserAuthenticated()
        ) {
            return;
        }

        /*
        Siteaccesses running with legacy_mode=false and RequireUserLogin=true have issues with
        login redirects when protected legacy views are accessed via URL before the user is logged in.
        This is because RequireUserLogin specific code in legacy kernel checks for existence of
        'eZUserLoggedInID' DURING the legacy kernel initialization process. Since 'eZUserLoggedInID'
        session variable can only be set AFTER the legacy kernel is built and initialized,
        via runCallback method, the code always fails, causing repeated login screens.

        This is a workaround to set the session variable after the kernel is built, but before
        it's initialized, so the RequireUserLogin code should work fine.
        */

        $currentRequest->getSession()->set(
            'eZUserLoggedInID',
            $this->repository->getCurrentUser()->id
        );
    }
Performs actions related to security once the legacy kernel has been built.

@param \eZ\Publish\Core\MVC\Legacy\Event\PostBuildKernelEvent $event