Esempio n. 1
0
 /**
  * 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.
     }
 }
 public function __construct()
 {
     parent::__construct();
     $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) {
         $this->requireLogin();
     }
     /*
     	    $this->headers = tao_helpers_Http::getHeaders();
     	    $this->files = tao_helpers_Http::getFiles();
     */
     if ($this->hasHeader("Accept")) {
         try {
             $this->responseEncoding = tao_helpers_Http::acceptHeader($this->acceptedMimeTypes, $this->getHeader("Accept"));
         } catch (common_exception_ClientException $e) {
             $this->returnFailure($e);
         }
     }
     if ($this->hasHeader("Accept-Language")) {
         try {
         } catch (common_exception_ClientException $e) {
             $this->returnFailure($e);
         }
     }
     header('Content-Type: ' . $this->responseEncoding);
     //check auth method requested
     /**/
 }
 /**
  * Action dedicated to fake roles
  */
 public function roles()
 {
     $currentSession = \common_session_SessionManager::getSession();
     if ($currentSession instanceof \common_session_RestrictedSession) {
         $this->setData('roles', $currentSession->getUserRoles());
         $this->setView('userdebug/restore.tpl');
     } else {
         $myFormContainer = new UserDebugRoles();
         $myForm = $myFormContainer->getForm();
         if ($myForm->isSubmited() && $myForm->isValid()) {
             $user = $this->userService->getCurrentUser();
             $filter = $myForm->getValue('rolefilter');
             $userUri = $myForm->getValue('user');
             if ($userUri != \common_session_SessionManager::getSession()->getUserUri()) {
                 throw new \common_exception_Error('Security exception, user to be changed is not the current user');
             }
             $session = new \common_session_RestrictedSession(\common_session_SessionManager::getSession(), $myForm->getValue('rolefilter'));
             \common_session_SessionManager::startSession($session);
             $this->setData('roles', $currentSession->getUserRoles());
             $this->setView('userdebug/restore.tpl');
         } else {
             $this->setData('formTitle', __("Restrict Roles"));
             $this->setData('myForm', $myForm->render());
             $this->setView('form.tpl', 'tao');
         }
     }
 }
 /**
  * start a session from the provided OAuth Request
  * 
  * @param common_http_Request $request
  * @throws common_user_auth_AuthFailedException
  */
 public function startLtiSession(common_http_Request $request)
 {
     $adapter = new taoLti_models_classes_LtiAuthAdapter($request);
     $user = $adapter->authenticate();
     $session = new taoLti_models_classes_TaoLtiSession($user);
     common_session_SessionManager::startSession($session);
 }
 /**
  * action to perform authwith open_ID
  */
 public function login()
 {
     try {
         # Change 'localhost' to your domain name.
         $openid = new LightOpenID('http://e-learning-22/');
         $openid_identfier = "http://192.168.0.201:8080/Sayegh-OpenID-Provider/auth";
         if (!$openid->mode) {
             if (isset($openid_identfier)) {
                 $openid->identity = $openid_identfier;
                 # The following two lines request email, full name, and a nickname
                 # from the provider. Remove them if you don't need that data.
                 $openid->required = array('contact/email', 'namePerson');
                 $openid->optional = array("role");
                 header('Location: ' . $openid->authUrl());
                 die;
             }
             ?>
             WTF you should never reached here! XO
             <?php 
         } elseif ($openid->mode == 'cancel') {
             echo 'User has canceled authentication!';
         } else {
             $res = $openid->getAttributes();
             // [contact/email] => sara@syrianep.com [namePerson] => sara lakah
             $user = new OpenIDUser(new \core_kernel_classes_Resource("http://sep.com/" . $res['contact/email']));
             $session = new \common_session_DefaultSession($user);
             \common_session_SessionManager::startSession($session);
             $this->redirect(_url('entry', 'Main', "tao"));
             //   echo 'User ' . ($openid->validate() ? $openid->identity . ' has ' : 'has not ') . 'logged in.';
             //  print_r($openid->getAttributes());
         }
     } catch (ErrorException $e) {
         echo $e->getMessage();
     }
 }
Esempio n. 7
0
 /**
  * shared methods for test initialization
  */
 public static function initTest()
 {
     //connect the API
     if (!self::$connected) {
         \common_session_SessionManager::startSession(new \common_test_TestUserSession());
         self::$connected = true;
     }
 }
 protected function _isAllowed()
 {
     $session = new taoUpdate_models_classes_Session();
     common_session_SessionManager::startSession($session);
     return true;
 }
Esempio n. 9
0
 /**
  * Short description of method startSession
  *
  * @access public
  * @author Jerome Bogaerts, <*****@*****.**>
  * @param  Resource user
  * @return boolean
  */
 public function startSession(common_user_User $user)
 {
     $session = new common_session_DefaultSession($user);
     return \common_session_SessionManager::startSession($session);
 }
Esempio n. 10
0
 /**
  * Sets the current session
  * @param common_session_Session $session
  * @return boolean
  */
 public function setSession(common_session_Session $session)
 {
     return common_session_SessionManager::startSession($session);
 }
Esempio n. 11
0
 /**
  * Revert back to the original Session
  */
 public function restoreOriginal()
 {
     common_session_SessionManager::startSession($this->internalSession);
 }