/** * Authenticate using the cookie session id * * If a session cookie is found and the session session is not active it will be auto-started. * * @param DispatcherContext $context A dispatcher context object * @return boolean Returns TRUE if the authentication explicitly succeeded. */ public function authenticateRequest(DispatcherContext $context) { $session = $context->getUser()->getSession(); $request = $context->getRequest(); if (!$session->isActive()) { if ($request->getCookies()->has($this->getConfig()->cookie_name)) { //Logging the user by auto-start the session $this->loginUser(); //Perform CSRF authentication parent::authenticateRequest($context); return true; } } }
/** * Load the language * * @param ViewContextInterface $context A view context object * @return void */ protected function _beforeDispatch(DispatcherContext $context) { $context->getSubject()->loadLanguage(); }
/** * Get the controller context * * @param ControllerContextInterface $context Context to cast to a local context * @return DispatcherContext */ public function getContext(ControllerContextInterface $context = null) { $context = new DispatcherContext($context); $context->setRequest($this->getRequest()); $context->setUser($this->getUser()); $context->setResponse($this->getResponse()); return $context; }
/** * Render the decorators * * This method will also add the 'decorator' filter to the view and add following default parameters * * - component: The name of the component being dispatched * - language: The language of the response * - status: The status code of the response * * @param DispatcherContext $context The active command context * @return void */ protected function _beforeSend(DispatcherContext $context) { $response = $context->getResponse(); if (!$response->isDownloadable()) { foreach ($this->getDecorators() as $decorator) { //Get the decorator $config = array('response' => array('content' => $response->getContent())); $controller = $this->getObject($decorator, $config); if (!$controller instanceof ControllerViewable) { throw new \UnexpectedValueException('Decorator ' . get_class($controller) . ' does not implement ControllerViewable'); } //Set the view $parameters = array('language' => $this->getLanguage()); if ($response->isError()) { $parameters['status'] = $response->getStatusCode(); } else { $parameters['component'] = $this->getController()->getIdentifier()->package; } $controller->getView()->setParameters($parameters)->getTemplate()->addFilter('decorator'); //Set the response $response->setContent($controller->render()); } } }
/** * Challenge the response * * @param DispatcherContext $context A dispatcher context object * @return bool Returns TRUE if the response could be signed, FALSE otherwise. */ public function challengeResponse(DispatcherContext $context) { $response = $context->getResponse(); //The response MUST include a WWW-Authenticate header field. if ($response->getStatusCode() == HttpResponse::UNAUTHORIZED) { $response->headers->set('Www-Authenticate', ucfirst($this->getScheme()) . ' realm="' . $this->getRealm() . '"', false); } }