/** * Run the controller * * @param common_http_Request $pRequest * @throws \ActionEnforcingException * @throws \Exception * @throws \common_exception_Error * @throws \common_ext_ExtensionException */ public function legacy(common_http_Request $pRequest) { $resolver = new Resolver($pRequest); // load the responsible extension $ext = common_ext_ExtensionsManager::singleton()->getExtensionById($resolver->getExtensionId()); \Context::getInstance()->setExtensionName($resolver->getExtensionId()); // load translations $uiLang = \common_session_SessionManager::getSession()->getInterfaceLanguage(); \tao_helpers_I18n::init($ext, $uiLang); //if the controller is a rest controller we try to authenticate the user $controllerClass = $resolver->getControllerClass(); if (is_subclass_of($controllerClass, \tao_actions_RestController::class)) { $authAdapter = new \tao_models_classes_HttpBasicAuthAdapter(common_http_Request::currentRequest()); try { $user = $authAdapter->authenticate(); $session = new \common_session_RestSession($user); \common_session_SessionManager::startSession($session); } catch (\common_user_auth_AuthFailedException $e) { $data['success'] = false; $data['errorCode'] = '401'; $data['errorMsg'] = 'You are not authorized to access this functionality.'; $data['version'] = TAO_VERSION; header('HTTP/1.0 401 Unauthorized'); header('WWW-Authenticate: Basic realm="' . GENERIS_INSTANCE_NAME . '"'); echo json_encode($data); exit(0); } } try { $enforcer = new ActionEnforcer($resolver->getExtensionId(), $resolver->getControllerClass(), $resolver->getMethodName(), $pRequest->getParams()); $enforcer->execute(); } catch (InterruptedActionException $iE) { // Nothing to do here. } }
/** * (non-PHPdoc) * @see FrontController::loadModule() */ public function loadModule() { $resolver = new Resolver($this->getRequest()); // load the responsible extension common_ext_ExtensionsManager::singleton()->getExtensionById($resolver->getExtensionId()); \Context::getInstance()->setExtensionName($resolver->getExtensionId()); //if the controller is a rest controller we try to authenticate the user $controllerClass = $resolver->getControllerClass(); if (is_subclass_of($controllerClass, 'tao_actions_CommonRestModule')) { $authAdapter = new \tao_models_classes_HttpBasicAuthAdapter(common_http_Request::currentRequest()); try { $user = $authAdapter->authenticate(); $session = new \common_session_RestSession($user); \common_session_SessionManager::startSession($session); } catch (\common_user_auth_AuthFailedException $e) { $class = new $controllerClass(); $class->requireLogin(); } } try { $enforcer = new ActionEnforcer($resolver->getExtensionId(), $resolver->getControllerClass(), $resolver->getMethodName(), $this->getRequest()->getParams()); $enforcer->execute(); } catch (InterruptedActionException $iE) { // Nothing to do here. } }
/** * Forward the action to execute reqarding a URL * The forward runs into tha same HTTP request unlike redirect. * @param string $url the url to forward to */ public function forwardUrl($url) { //get the current request $request = common_http_Request::currentRequest(); $params = $request->getParams(); //parse the given URL $parsedUrl = parse_url($url); //if new parameters are given, then merge them if (isset($parsedUrl['query']) && strlen($parsedUrl['query']) > 0) { $newParams = array(); parse_str($parsedUrl['query'], $newParams); if (count($newParams) > 0) { $params = array_merge($params, $newParams); } } //resolve the given URL for routing $resolver = new Resolver(new common_http_Request($parsedUrl['path'], $request->getMethod(), $params)); $context = Context::getInstance(); // load the responsible extension common_ext_ExtensionsManager::singleton()->getExtensionById($resolver->getExtensionId()); //update the context to the new route $context->setExtensionName($resolver->getExtensionId()); $context->setModuleName($resolver->getControllerShortName()); $context->setActionName($resolver->getMethodName()); if (count($params) > 0) { $context->getRequest()->addParameters($params); } //add a custom header so the client knows where the route ends header(self::FORWARD_HEADER . ': ' . $resolver->getExtensionId() . '/' . $resolver->getControllerShortName() . '/' . $resolver->getMethodName()); //execite the new action $enforcer = new ActionEnforcer($resolver->getExtensionId(), $resolver->getControllerClass(), $resolver->getMethodName(), $params); $enforcer->execute(); //should not be reached throw new InterruptedActionException('Interrupted action after a forward', $context->getModuleName(), $context->getActionName()); }