Sign the response with a session token

@param DispatcherContext $context   A dispatcher context object
497576
public function challengeResponse(DispatcherContext $context)
    {
        if($context->request->isGet())
        {
            $token = $context->user->getSession()->getToken();

            $context->response->headers->addCookie($this->getObject('lib:http.cookie', array(
                'name'   => 'csrf_token',
                'value'  => $token,
                'path'   => $context->request->getBaseUrl()->getPath(),
            )));

            $context->response->headers->set('X-CSRF-Token', $token);
        }

        parent::challengeResponse($context);
    }
199726
protected function proxy() {
        if (!$this->context) {
            $this->context = new SigningKeyContext(
                $this->version,
                $this->solution['accountSid'],
                $this->solution['sid']
            );
        }

        return $this->context;
    }
641728
protected function _actionDelete(AnCommandContext $context)
    {
        $this->getResponse()->status = AnHttpResponse::NO_CONTENT;

        $token = $this->getService('repos:connect.session')->fetchSet(array(
                        'owner' => $this->actor,
                        'api' => $this->getAPI()->getName(),
                    ));

        $token->delete()->save();
    }
791866
public function setContext(RequestContext $context)
    {
        if (null !== $this->generator) {
            $this->getGenerator()->setContext($context);
        }
        $this->context = $context;
    }
561667
protected function _actionDispatch(AnCommandContext $context)
    {
        if ($this->action === 'confirm' && $this->token) {
            $context->data->append(array(
               '_action' => 'confirm',
               'token' => $this->token,
            ));

            return $this->execute('post', $context);
        }

        return parent::_actionDispatch($context);
    }
1084964
protected function doExecute(AssertionContext $context)
    {
        $profileContext = $context->getProfileContext();
        $inboundMessage = $profileContext->getInboundContext()->getMessage();
        $endpoint = $profileContext->getEndpoint();

        $data = new SubjectConfirmationData();
        if ($inboundMessage) {
            $data->setInResponseTo($inboundMessage->getID());
        }
        $data->setAddress($profileContext->getHttpRequest()->getClientIp());
        $data->setNotOnOrAfter($this->timeProvider->getTimestamp() + $this->expirationSeconds);
        $data->setRecipient($endpoint->getLocation());

        $subjectConfirmation = new SubjectConfirmation();
        $subjectConfirmation->setMethod(SamlConstants::CONFIRMATION_METHOD_BEARER);
        $subjectConfirmation->setSubjectConfirmationData($data);

        if (null === $context->getAssertion()->getSubject()) {
            $context->getAssertion()->setSubject(new Subject());
        }

        $context->getAssertion()->getSubject()->addSubjectConfirmation($subjectConfirmation);
    }
215916
protected function _actionGetaccesstoken(AnCommandContext $context)
    {
        $data = $context->data;

        $this->getBehavior('oauthorizable')->execute('action.getaccesstoken', $context);
        $user = $this->getAPI()->getUser();
        $session = $this->getService('repos:connect.session')
                        ->findOrAddNew(array(
                            'profileId' => $user->id,
                            'api' => $this->getAPI()->getName(),
                          ));

        $token = $this->getAPI()->getToken();

        if (!empty($token)) {
            $session->setData(array(
                'component' => 'com_connect',
                'owner' => $this->actor,
            ))->setToken($token)->save();
        }

        $route = route($this->actor->getURL().'&get=settings&edit=connect');

        if ($data->return) {
            $route = base64_decode($data->return);
        }

        $context->response->setRedirect($route);
    }
319783
public function triggerContextBound(ExpressContext $context)
	{
		if($this->eventDispatcher)
		{
			$this->eventDispatcher->notify(new ExpressContextBoundEvent($context));
		}
	}
925649
protected function _actionXpayment($context)
    {
        $data = $context->data;
        $package = $this->getItem();
        $gateway = $this->getService('com:subscriptions.controller.subscription')->getGateway();

        try {

            $payload = $this->order->getPayload();
            $confirm = route('option=com_subscriptions&view=signup&action=confirm&xpayment=true&id='.$package->id, true);
            $cancel = route('option=com_subscriptions&view=signup&action=cancel&xpayment=true&id='.$package->id, true);
            $url = $gateway->getAuthorizationURL($payload, $confirm, $cancel);
            $context->response->setRedirect($url, AnHttpResponse::SEE_OTHER);

        } catch (Exception $error) {
            throw new RuntimeException($error->getMessage());
        }
    }
1246711
protected function _lockReferrer(KControllerContextInterface $context)
    {
        $cookie = $this->getObject('lib:http.cookie', array(
            'name'   => $this->_cookie_name.'_locked',
            'value'  => true,
            'path'   => $this->_cookie_path
        ));

        $context->response->headers->addCookie($cookie);
    }
885641
protected function _resolveRequest(DispatcherContext $context)
    {
        //Resolve the controller
        if($context->request->query->has('view')) {
            $this->setController($context->request->query->get('view', 'cmd'));
        }

        //Resolve the controller action
        if($context->request->data->has('_action')) {
            $this->setControllerAction($context->request->data->get('_action', 'cmd'));
        }
    }
50382
protected function _beforeDispatch(DispatcherContext $context)
    {
        $view = $context->request->query->get('view', 'cmd');

        //Redirect if no view information can be found in the request
        if(empty($view))
        {
            $url = clone($context->request->getUrl());
            $url->query['view'] = $this->getController()->getView()->getName();

            $this->redirect($url);

            return false;
        }

        return true;
    }
516322
public function authenticateRequest(DispatcherContext $context)
    {
        $request = $context->request;

        if($request->headers->has('Authorization'))
        {
            $authorization = $request->headers->get('Authorization');

            if(stripos($authorization, 'basic') === 0)
            {
                $exploded = explode(':', base64_decode(substr($authorization , 6)));
                if (count($exploded) == 2) {
                    list($username, $password) = $exploded;
                }

                if($username)
                {
                    $user = $this->getObject('user.provider')->getUser($username);

                    if($user->getId())
                    {
                        //Check user password
                        if (!$user->verifyPassword($password)) {
                            throw new ControllerExceptionRequestNotAuthenticated('Wrong password');
                        }

                        //Check user enabled
                        if (!$user->isEnabled()) {
                            throw new ControllerExceptionRequestNotAuthenticated('Account disabled');
                        }

                        //Login the user
                        $this->loginUser($user->getId());

                        return true;
                    }
                    else throw new ControllerExceptionRequestNotAuthenticated('Wrong username');
                }
                else throw new ControllerExceptionRequestNotAuthenticated('Invalid username');
            }
        }
    }
213680
public function updateUserContext(UserContext $context): void
    {
        if ($this->session->isStarted()) {
            $context->addParameter('sessionId', $this->session->getId());
        }
    }
704970
public function bind(Context $context)
    {
        if (! isset($context->__UBID)) {
            $context->__UBID = 0;
        }
        $context->__UBID ++;
        
        return spl_object_hash($context) . $context->__UBID;
    }
1090176
public function authenticate(SecurityContextInterface &$context) {

        $token = $this->generateEmptyToken($this->getSession());

        try {
            $this->userAuthenticationProvider->loadClientByCredentials($token->getClient()->getCredentials());
        } catch (ClientCredentialsNotFoundException $e) {

            $this->logger->addAlert('Client not found ' . $e->getMessage());
            throw $e;
        }

        //validate the client, if good then add to the context
        if (true) {
            $context->setToken($token);
        }
    }
143433
protected function _resolveRequest(DispatcherContext $context)
    {
        if($controller = ObjectConfig::unbox($context->param))
        {
            $url = $this->getObject('lib:http.url', array('url' => $controller));

            //Set the request query
            $context->request->query->clear()->add($url->getQuery(true));

            //Set the controller
            $identifier = $url->toString(HttpUrl::BASE);
            $identifier = $this->getIdentifier($identifier);

            $this->setController($identifier);
        }

        parent::_resolveRequest($context);
    }