When the security token is created, populate it with user information from the service API.

@param FilterTokenEvent $event
488252
public function onFilterToken(FilterTokenEvent $event)
    {
        $token = $event->getToken();
        $service = $token->getService();
        $oauthService = $this->registry->getService($service);
        $config = $this->config[$service];

        $serviceName = OAuthServiceRegistry::getServiceName($oauthService);
        $accessToken = $oauthService->getStorage()->retrieveAccessToken($serviceName);
        $token->setAccessToken($accessToken);

        $callback = isset($config['user_callback']) && is_callable($config['user_callback']) ? $config['user_callback'] : array($this, 'defaultUserCallback');

        if (isset($config['user_endpoint'])) {
            $rawUserInfo = json_decode($oauthService->request($config['user_endpoint']), true);
        }
        call_user_func($callback, $token, $rawUserInfo, $oauthService);
    }
1249891
public function onLogin(WordpressEvent $event)
    {
        $wpUser = $event->getParameter('user');

        $user = $this->userManager->find($wpUser->data->ID);
        $user->setWordpressRoles($wpUser->roles);

        $token = new UsernamePasswordToken($user, $user->getPass(), $this->firewall, $user->getRoles());
        $this->tokenStorage->setToken($token);

        $this->session->set('_security_'.$this->firewall, serialize($token));
    }
178292
public function beforeFilter(\Cake\Event\Event $event)
    {
        parent::beforeFilter($event);

        // Auth-settings: Allows all user-related methods
        $this->Auth->allow(['resetPassword', 'forgotPassword', 'logout', 'login', 'activate', 'register']);

        // Setting up the base-theme
        if (!$this->theme) {
            $this->theme = "CakeManager";
        }

        // Setting up the base-layout
        if (!$this->layout) {
            $this->layout = "base";
        }

        $this->set('title', 'Users');
    }
1311225
public function onResponse(FilterResponseEvent $event)
    {
        if (!$event->isMasterRequest()) {
            return;
        }

        $request = $event->getRequest();
        $response = $event->getResponse();
        if (!$response->isRedirect() || !$response instanceof RedirectResponse) {
            return;
        }

        $this->handleNoBackendAccess($response);
        $this->handleLoginRetreat($request, $response);
    }
984793
public function onKernelResponse(FilterResponseEvent $event)
    {
        /**
         * @var Response $response
         */
        $response = $event->getResponse();

        // exit if not master request, uninteresting method or an error occurred
        if (!$event->isMasterRequest() || $this->isNotConcerningRequest() || !$response->isSuccessful()) {
            return;
        }

        // we can always safely call this, it doesn't need much resources.
        // only if we have subscribers, it will create more load as it persists an EventStatus
        $queueEvent = $this->createQueueEventObject();

        if (!empty($queueEvent->getStatusurl()) && !empty($queueEvent->getEvent())) {
            $linkHeader = LinkHeader::fromResponse($response);
            $linkHeader->add(
                new LinkHeaderItem(
                    $queueEvent->getStatusurl(),
                    array('rel' => 'eventStatus')
                )
            );

            $response->headers->set(
                'Link',
                (string) $linkHeader
            );
        }

        // let's send it to the queue(s) if appropriate
        if (!empty($queueEvent->getEvent())) {
            $queuesForEvent = $this->getSubscribedWorkerIds($queueEvent);

            // if needed and activated, change urls relative to workers
            if (!empty($queuesForEvent) && $this->workerRelativeUrl instanceof Uri) {
                $queueEvent = $this->getWorkerQueueEvent($queueEvent);
            }

            foreach ($queuesForEvent as $queueForEvent) {
                // declare the Queue for the Event if its not there already declared
                $this->rabbitMqProducer->getChannel()->queue_declare($queueForEvent, false, true, false, false);
                $this->rabbitMqProducer->publish(json_encode($queueEvent), $queueForEvent);
            }
        }
    }
1126318
public function onResponse(FilterResponseEvent $event)
    {
        if (!$event->isMasterRequest()) {
            return;
        }

        $request = $event->getRequest();
        if (Zone::isAsync($request) || $request->isXmlHttpRequest()) {
            return;
        }

        $response = $event->getResponse();
        if ($response->isRedirection() || $response->isEmpty() || $response->isInformational()) {
            return;
        }
        if (strpos($response->headers->get('Content-Type'), 'text/html') === false) {
            return;
        }

        $this->addSnippets();

        foreach ($this->queues as $queue) {
            $queue->process($request, $response);
        }
    }
854908
public function beforeFilter(\Cake\Event\Event $event)
    {
        parent::beforeFilter($event);

        // get the type-string
        $type = $this->PostTypes->postTypeFinder($this->request);
        $this->_type = $type;

        // check if the string exists. Will throw an exception
        $this->PostTypes->check($type, ['exception' => true]);

        // intialize the settings
        $this->Settings = $this->PostTypes->get($type);

        // lets initialize the model too
        $this->Model = $this->loadModel($this->Settings['model']);
    }
1066285
public function emailOnRegistration(FilterUserResponseEvent $event)
    {
        $template = '@XMSecurity/Mail/user_registered.html.twig';
        $mailParams = [
            'user' => $event->getUser(),
        ];

        $this->mailManager->getSender()
            ->setTemplate($template, $mailParams)
            ->send($this->adminEmail);
    }
950845
public function preCreate(CreateEvent $event)
    {
        $organization = $event->getObject();
        $user = $this->tokenStorage->getToken()->getUser();

        if ($user instanceof User) {
            $organization->addAdministrator($user);
        }
    }
1245293
public function beforeFilter($event)
    {
        $this->setController($event->subject());

        if ($this->Controller->Manager->prefix('admin')) {
            if (method_exists($this->Controller, 'initPostTypes')) {
                $this->Controller->initPostTypes($event);
            }
        }
    }
8691
public function onKernelRequest(GetResponseEvent $event)
    {
        $url = $event->getRequest()->getRequestUri();
        $token = $this->tokenStorage->getToken();

        if ($token && $this->isAdminToken($this->providerKey, $token) && $this->adminRouteHelper->isAdminRoute($url)) {
            $locale = $token->getUser()->getAdminLocale();

            if (!$locale) {
                $locale = $this->defaultAdminLocale;
            }

            $this->translator->setLocale($locale);
        }
    }
679349
public function onKernelResponse(FilterResponseEvent $event)
    {
        if (!$event->isMasterRequest()) {
            return;
        }

        $request = $event->getRequest();

        if (!$request->hasSession()) {
            return;
        }

        $this->dispatcher->removeListener(KernelEvents::RESPONSE, [$this, 'onKernelResponse']);
        $this->registered = false;
        $session = $request->getSession();

        if ((null === $token = $this->tokenStorage->getToken()) || $this->trustResolver->isAnonymous($token)) {
            if ($request->hasPreviousSession()) {
                $session->remove($this->sessionKey);
            }
        } else {
            $session->set($this->sessionKey, serialize($token));

            if (null !== $this->logger) {
                $this->logger->debug('Stored the security token in the session.', ['key' => $this->sessionKey]);
            }
        }
    }
1100837
public function onKernelResponse(FilterResponseEvent $event)
    {
        if ($this->editor->isEnabled()) {
            $event
                ->getResponse()
                ->setSharedMaxAge(0)
                ->setMaxAge(0)
                ->setExpires(null)
                ->setLastModified(null)
                ->setPrivate();
        }
    }
619395
public function filterAutocomplete(GetFilterConditionEvent $event): void
    {
        $expr = $event->getFilterQuery()->getExpr();
        $values = $event->getValues();

        if ('' !== $values['value'] && null !== $values['value']) {
            $paramName = str_replace('.', '_', $event->getField());
            $event->setCondition(
                $expr->eq($event->getField(), ':'.$paramName),
                [$paramName => $values['value']]
            );
        }
    }
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);
            });
    }
747638
public function onResponse(FilterResponseEvent $event)
    {
        $request = $event->getRequest();
        $debug = $request->query->get('debug');
        $response = $event->getResponse();

        //this is for debug purpose
        if ($response instanceof JsonResponse && $debug) {
            $new = new Response();
            $new->setContent('<body>'.$response->getContent().'</body>');
            $event->setResponse($new);
        }
    }
1063724
public function onKernelRequest(GetResponseEvent $event): void
    {
        $event->getRequest()->attributes->set(
            'csrf_enabled',
            $this->csrfTokenManager instanceof CsrfTokenManager
        );
    }