Exemplo n.º 1
0
 /**
  * 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');
         }
     }
 }
Exemplo n.º 2
0
 /**
  * Constructor performs initializations actions
  */
 public function __construct()
 {
     //initialize user service
     $this->passwordRecoveryService = PasswordRecoveryService::singleton();
     $this->userService = \tao_models_classes_UserService::singleton();
     $this->defaultData();
 }
 /**
  *
  * @author Patrick Plichart, patrick@taotesting.com
  * @param  array $propertiesValues
  * @throws \common_exception_MissingParameter
  * @throws \common_exception_PreConditionFailure
  * @return \core_kernel_classes_Resource
  */
 public function createFromArray($propertiesValues = array())
 {
     // mandatory parameters
     if (!isset($propertiesValues[PROPERTY_USER_LOGIN])) {
         throw new \common_exception_MissingParameter("login");
     }
     if (!isset($propertiesValues[PROPERTY_USER_PASSWORD])) {
         throw new \common_exception_MissingParameter("password");
     }
     // default values
     if (!isset($propertiesValues[PROPERTY_USER_UILG])) {
         $propertiesValues[PROPERTY_USER_UILG] = \tao_helpers_I18n::getLangResourceByCode(DEFAULT_LANG);
     }
     if (!isset($propertiesValues[PROPERTY_USER_DEFLG])) {
         $propertiesValues[PROPERTY_USER_DEFLG] = \tao_helpers_I18n::getLangResourceByCode(DEFAULT_LANG);
     }
     if (!isset($propertiesValues[RDFS_LABEL])) {
         $propertiesValues[RDFS_LABEL] = "";
     }
     // check if login already exists
     $userService = \tao_models_classes_UserService::singleton();
     if ($userService->loginExists($propertiesValues[PROPERTY_USER_LOGIN])) {
         throw new \common_exception_PreConditionFailure("login already exists");
     }
     $propertiesValues[PROPERTY_USER_PASSWORD] = \core_kernel_users_Service::getPasswordHash()->encrypt($propertiesValues[PROPERTY_USER_PASSWORD]);
     $type = isset($propertiesValues[RDF_TYPE]) ? $propertiesValues[RDF_TYPE] : $this->getRootClass();
     $label = $propertiesValues[RDFS_LABEL];
     // hmmm
     unset($propertiesValues[RDFS_LABEL]);
     unset($propertiesValues[RDF_TYPE]);
     $resource = parent::create($label, $type, $propertiesValues);
     $this->getClassService()->setTestTakerRole($resource);
     return $resource;
 }
Exemplo n.º 4
0
 /**
  * test the user authentication to TAO and to the API
  */
 public function testAuth()
 {
     //is the user in the db
     $this->assertFalse($this->userService->loginAvailable($this->testUserData[PROPERTY_USER_LOGIN]));
     if (tao_models_classes_UserService::singleton()->isASessionOpened()) {
         tao_models_classes_UserService::singleton()->logout();
     }
     //no other user session
     $this->assertFalse(tao_models_classes_UserService::singleton()->isASessionOpened());
     //check user login
     $this->assertTrue($this->userService->loginUser($this->testUserData[PROPERTY_USER_LOGIN], $this->clearPassword));
     //check session
     $this->assertTrue(tao_models_classes_UserService::singleton()->isASessionOpened());
     $currentUser = $this->userService->getCurrentUser();
     $this->assertIsA($currentUser, 'core_kernel_classes_Resource');
     foreach ($this->testUserData as $prop => $value) {
         try {
             $property = new core_kernel_classes_Property($prop);
             $v = $currentUser->getUniquePropertyValue(new core_kernel_classes_Property($prop));
             $v = $v instanceof core_kernel_classes_Resource ? $v->getUri() : $v->literal;
             $this->assertEquals($value, $v);
         } catch (common_Exception $ce) {
             $this->fail($ce);
         }
     }
 }
Exemplo n.º 5
0
 /**
  * Form to edit a user
  * User login must be set in parameter
  * @return  void
  */
 public function edit()
 {
     if (!$this->hasRequestParameter('uri')) {
         throw new Exception('Please set the user uri in request parameter');
     }
     $user = new core_kernel_classes_Resource(tao_helpers_Uri::decode($this->getRequestParameter('uri')));
     $myFormContainer = new tao_actions_form_Users($this->userService->getClass($user), $user);
     $myForm = $myFormContainer->getForm();
     if ($myForm->isSubmited()) {
         if ($myForm->isValid()) {
             $values = $myForm->getValues();
             if (!empty($values['password2']) && !empty($values['password3'])) {
                 $values[PROPERTY_USER_PASSWORD] = core_kernel_users_Service::getPasswordHash()->encrypt($values['password2']);
             }
             unset($values['password2']);
             unset($values['password3']);
             if (!preg_match("/[A-Z]{2,4}\$/", trim($values[PROPERTY_USER_UILG]))) {
                 unset($values[PROPERTY_USER_UILG]);
             }
             if (!preg_match("/[A-Z]{2,4}\$/", trim($values[PROPERTY_USER_DEFLG]))) {
                 unset($values[PROPERTY_USER_DEFLG]);
             }
             $binder = new tao_models_classes_dataBinding_GenerisFormDataBinder($user);
             if ($binder->bind($values)) {
                 $this->setData('message', __('User saved'));
             }
         }
     }
     $this->setData('formTitle', __('Edit a user'));
     $this->setData('myForm', $myForm->render());
     $this->setView('user/form.tpl');
 }
Exemplo n.º 6
0
 /**
  *
  * @author "Lionel Lecaque, <*****@*****.**>"
  */
 public static function isSysAdmin()
 {
     $userService = tao_models_classes_UserService::singleton();
     $currentUser = $userService->getCurrentUser();
     $sysAdminRole = new core_kernel_classes_Resource(INSTANCE_ROLE_SYSADMIN);
     $returnValues = $currentUser != null ? $userService->userHasRoles($currentUser, $sysAdminRole) : false;
     return $returnValues;
 }
Exemplo n.º 7
0
 /**
  * Clearing up ( in case if delete test was not executed )
  */
 public function __destruct()
 {
     if ($this->testUser) {
         $this->userService->removeUser($this->testUser);
     }
     if ($this->testUserUtf8) {
         $this->userService->removeUser($this->testUserUtf8);
     }
 }
 /**
  * Check if login is valid
  *  - not empty
  *  - exists in TAO ACL -OR- match with regex
  * @throws InvalidLoginException
  */
 public function validateLogin($login = null)
 {
     if (empty($login)) {
         throw new InvalidLoginException('No login found');
     }
     if (\tao_models_classes_UserService::singleton()->loginExists($login) || $this->hasOption('regexValidator') && preg_match($this->getOption('regexValidator'), $login) === 1) {
         return true;
     }
     throw new InvalidLoginException('This login does not exist');
 }
Exemplo n.º 9
0
 protected function setUp()
 {
     $this->disableCache();
     $pass = md5(rand());
     $taoManagerRole = new core_kernel_classes_Resource(INSTANCE_ROLE_BACKOFFICE);
     $this->testUser = tao_models_classes_UserService::singleton()->addUser('testUser', $pass, $taoManagerRole);
     $this->credentials = array('loginForm_sent' => 1, 'login' => 'testUser', 'password' => $pass);
     $this->assertIsA($this->testUser, 'core_kernel_classes_Resource');
     parent::setUp();
 }
Exemplo n.º 10
0
 /**
  * Test user removing
  * @see tao_models_classes_UserService::removeUser
  */
 public function testDelete()
 {
     $this->testUser = $this->getUserByLogin($this->testUserData[PROPERTY_USER_LOGIN]);
     $this->assertIsA($this->testUser, 'core_kernel_classes_Resource');
     $this->assertTrue($this->userService->removeUser($this->testUser));
     $this->assertTrue($this->userService->loginAvailable($this->testUserData[PROPERTY_USER_LOGIN]));
     $this->testUserUtf8 = $this->getUserByLogin($this->testUserUtf8Data[PROPERTY_USER_LOGIN]);
     $this->assertIsA($this->testUserUtf8, 'core_kernel_classes_Resource');
     $this->assertTrue($this->userService->removeUser($this->testUserUtf8));
     $this->assertTrue($this->userService->loginAvailable($this->testUserUtf8Data[PROPERTY_USER_LOGIN]));
 }
Exemplo n.º 11
0
 /**
  * action used to check if a login can be used
  * @return void
  */
 public function checkLogin()
 {
     if (!tao_helpers_Request::isAjax()) {
         throw new Exception("wrong request mode");
     }
     $data = array('available' => false);
     if ($this->hasRequestParameter('login')) {
         $data['available'] = $this->userService->loginAvailable($this->getRequestParameter('login'));
     }
     $this->returnJson($data);
 }
Exemplo n.º 12
0
 /**
  * Get the settings of the current user. This method returns an associative array with the following keys:
  * 
  * - 'ui_lang': The value associated to this key is a core_kernel_classes_Resource object which represents the language
  * selected for the Graphical User Interface.
  * - 'data_lang': The value associated to this key is a core_kernel_classes_Resource object which respresents the language
  * selected to access the data in persistent memory.
  * - 'timezone': The value associated to this key is a core_kernel_classes_Resource object which respresents the timezone
  * selected to display times and dates.
  * 
  * @return array The URIs of the languages.
  */
 private function getUserSettings()
 {
     $currentUser = $this->userService->getCurrentUser();
     $props = $currentUser->getPropertiesValues(array(new core_kernel_classes_Property(PROPERTY_USER_UILG), new core_kernel_classes_Property(PROPERTY_USER_DEFLG), new core_kernel_classes_Property(PROPERTY_USER_TIMEZONE)));
     $langs = array();
     if (!empty($props[PROPERTY_USER_UILG])) {
         $langs['ui_lang'] = current($props[PROPERTY_USER_UILG])->getUri();
     }
     if (!empty($props[PROPERTY_USER_DEFLG])) {
         $langs['data_lang'] = current($props[PROPERTY_USER_DEFLG])->getUri();
     }
     $langs['timezone'] = !empty($props[PROPERTY_USER_TIMEZONE]) ? current($props[PROPERTY_USER_TIMEZONE]) : TIME_ZONE;
     return $langs;
 }
 protected static function generateUsers($count, $class, $role, $label, $prefix)
 {
     $userExists = \tao_models_classes_UserService::singleton()->loginExists($prefix . '0');
     if ($userExists) {
         throw new \common_exception_Error($label . ' 0 already exists, Generator already run?');
     }
     $generationId = NameGenerator::generateRandomString(4);
     $subClass = $class->createSubClass('Generation ' . $generationId);
     helpers_TimeOutHelper::setTimeOutLimit(helpers_TimeOutHelper::LONG);
     for ($i = 0; $i < $count; $i++) {
         $tt = $subClass->createInstanceWithProperties(array(RDFS_LABEL => $label . ' ' . $i, PROPERTY_USER_UILG => 'http://www.tao.lu/Ontologies/TAO.rdf#Langen-US', PROPERTY_USER_DEFLG => 'http://www.tao.lu/Ontologies/TAO.rdf#Langen-US', PROPERTY_USER_LOGIN => $prefix . $i, PROPERTY_USER_PASSWORD => \core_kernel_users_Service::getPasswordHash()->encrypt('pass' . $i), PROPERTY_USER_ROLES => $role, PROPERTY_USER_FIRSTNAME => $label . ' ' . $i, PROPERTY_USER_LASTNAME => 'Family ' . $generationId));
     }
     helpers_TimeOutHelper::reset();
     return $subClass;
 }
 /**
  * Short description of method initElements
  *
  * @access public
  * @author Joel Bout, <*****@*****.**>
  * @return mixed
  */
 public function initElements()
 {
     $pass1Element = tao_helpers_form_FormFactory::getElement('oldpassword', 'Hiddenbox');
     $pass1Element->setDescription(__('Old Password'));
     $pass1Element->addValidator(tao_helpers_form_FormFactory::getValidator('Callback', array('message' => __('Passwords are not matching'), 'object' => tao_models_classes_UserService::singleton(), 'method' => 'isPasswordValid', 'param' => tao_models_classes_UserService::singleton()->getCurrentUser())));
     $this->form->addElement($pass1Element);
     $pass2Element = tao_helpers_form_FormFactory::getElement('newpassword', 'Hiddenbox');
     $pass2Element->setDescription(__('New password'));
     $pass2Element->addValidators(array(tao_helpers_form_FormFactory::getValidator('Length', array('min' => 3))));
     $this->form->addElement($pass2Element);
     $pass3Element = tao_helpers_form_FormFactory::getElement('newpassword2', 'Hiddenbox');
     $pass3Element->setDescription(__('Repeat new password'));
     $pass3Element->addValidators(array(tao_helpers_form_FormFactory::getValidator('Password', array('password2_ref' => $pass2Element))));
     $this->form->addElement($pass3Element);
 }
Exemplo n.º 15
0
 /**
  * Searches for the user with the provided username and verifies his password 
  * 
  * @throws common_Exception
  * @return core_kernel_classes_Resource the logged in user or null
  */
 protected function doLogin()
 {
     if (!$this->hasRequestParameter('username') || !$this->hasRequestParameter('password')) {
         throw new common_Exception('Missing paramteres');
     }
     $userService = tao_models_classes_UserService::singleton();
     $user = $userService->getOneUser($this->getRequestParameter('username'));
     if (is_null($user)) {
         return false;
     }
     if ($userService->isPasswordValid($this->getRequestParameter('password'), $user)) {
         $this->currentUser = $user;
         return $user;
     } else {
         common_Logger::w('API login failed for user ' . $this->getRequestParameter('username'));
         return false;
     }
 }
Exemplo n.º 16
0
 /**
  * The main action, load the layout
  *
  * @return void
  */
 public function index()
 {
     $user = $this->userService->getCurrentUser();
     $extension = $this->getRequestParameter('ext');
     $structure = $this->getRequestParameter('structure');
     if ($this->hasRequestParameter('structure')) {
         // structured mode
         // @todo stop using session to manage uri/classUri
         $this->removeSessionAttribute('uri');
         $this->removeSessionAttribute('classUri');
         $this->removeSessionAttribute('showNodeUri');
         TaoCe::setLastVisitedUrl(_url('index', 'Main', 'tao', array('structure' => $structure, 'ext' => $extension)));
         $sections = $this->getSections($extension, $structure);
         if (count($sections) > 0) {
             $this->setData('sections', $sections);
         } else {
             common_Logger::w('no sections');
         }
     } else {
         //check if the user is a noob, otherwise redirect him to his last visited extension.
         $firstTime = TaoCe::isFirstTimeInTao();
         if ($firstTime == false) {
             $lastVisited = TaoCe::getLastVisitedUrl();
             if (!is_null($lastVisited)) {
                 $this->redirect($lastVisited);
             }
         }
     }
     $perspectiveTypes = array(Perspective::GROUP_DEFAULT, 'settings');
     foreach ($perspectiveTypes as $perspectiveType) {
         $this->setData($perspectiveType . '-menu', $this->getNavigationElementsByGroup($perspectiveType));
     }
     $this->setData('user_lang', \common_session_SessionManager::getSession()->getDataLanguage());
     $this->setData('userLabel', \common_session_SessionManager::getSession()->getUserLabel());
     // re-added to highlight selected extension in menu
     $this->setData('shownExtension', $extension);
     $this->setData('shownStructure', $structure);
     $this->setData('current-section', $this->getRequestParameter('section'));
     //creates the URL of the action used to configure the client side
     $clientConfigParams = array('shownExtension' => $extension, 'shownStructure' => $structure);
     $this->setData('client_config_url', $this->getClientConfigUrl($clientConfigParams));
     $this->setData('content-template', array('blocks/sections.tpl', 'tao'));
     $this->setView('layout.tpl', 'tao');
 }
Exemplo n.º 17
0
 /**
  * Enbales you to authenticate a communication based on the token
  * @param string $token
  * @return boolean
  */
 protected function authenticate($token)
 {
     if (!empty($token)) {
         $session = PHPSession::singleton();
         $currentUser = $this->userService->getCurrentUser();
         if (!is_null($currentUser)) {
             $sessionKey = self::ENV_VAR_NAME . '_' . tao_helpers_Uri::encode($currentUser->getUri());
             if ($session->hasAttribute($sessionKey)) {
                 $executionData = $session->getAttribute($sessionKey);
                 if (isset($executionData['token'])) {
                     if ($executionData['token'] == $token) {
                         return true;
                     }
                 }
             }
         }
     }
     return false;
 }
Exemplo n.º 18
0
 /**
  * Short description of method run
  *
  * @access public
  * @author Jerome Bogaerts, <*****@*****.**>
  * @return void
  */
 public function run()
 {
     $userService = tao_models_classes_UserService::singleton();
     $this->outVerbose("Connecting to TAO as '" . $this->options['user'] . "' ...");
     if ($userService->loginUser($this->options['user'], $this->options['password'])) {
         $this->outVerbose("Connected to TAO as '" . $this->options['user'] . "'.");
         $filename = $this->options['input'];
         $action = new ImportRdf();
         $params = array($filename);
         if (!empty($this->options['model'])) {
             $nameSpace = common_ext_NamespaceManager::singleton()->getNamespace($this->options['model']);
             $params[] = $nameSpace->getModelId();
         }
         $report = $action->__invoke($params);
         $string = helpers_Report::renderToCommandline($report);
         foreach (explode(PHP_EOL, $string) as $line) {
             $this->out($line);
         }
     } else {
         $this->err("Unable to connect to TAO as '" . $this->options['user'] . "'.", true);
     }
 }
 /**
  * Check if the login is valid or not
  * @param $login
  * @return bool
  */
 private function isLoginValid($login)
 {
     // For now there is no simple loginExists method for RDF, redis ...
     // We just use a regex to see if it match a pattern
     $pattern = '/^[0-9]{7}[A-Z]$/';
     return \tao_models_classes_UserService::singleton()->loginExists($login) || preg_match($pattern, $login) === 1 ? true : false;
 }
 /**
  * @param \core_kernel_classes_Resource $user
  * @return string
  */
 private function getUserRole(\core_kernel_classes_Resource $user)
 {
     $userService = \tao_models_classes_UserService::singleton();
     if (!isset($this->authorRoles[$user->getUri()])) {
         $this->authorRoles[$user->getUri()] = $userService->userHasRoles($user, $this->proctorRole) ? __('Proctor') : __('Test-Taker');
     }
     return $this->authorRoles[$user->getUri()];
 }
Exemplo n.º 21
0
 /**
  * assign a role to a set of users
  *
  * @access public
  * @author Joel Bout, <*****@*****.**>
  * @param  Resource role
  * @param  array users
  * @return boolean
  */
 public function setRoleToUsers(core_kernel_classes_Resource $role, $users = array())
 {
     $returnValue = (bool) false;
     $userService = tao_models_classes_UserService::singleton();
     $rolesProperty = new core_kernel_classes_Property(PROPERTY_USER_ROLES);
     foreach ($users as $u) {
         $u = $u instanceof core_kernel_classes_Resource ? $u : new core_kernel_classes_Resource($u);
         // just in case of ...
         $userService->unnatachRole($u, $role);
         // assign the new role.
         $u->setPropertyValue($rolesProperty, $role);
         if (common_session_SessionManager::getSession()->getUserUri() == $u->getUri()) {
             common_session_SessionManager::getSession()->refresh();
         }
     }
     $returnValue = true;
     return (bool) $returnValue;
 }
 /**
  * Short description of method cloneInstance
  *
  * @access public
  * @author Joel Bout, <*****@*****.**>
  * @param \core_kernel_classes_Resource $instance
  * @param \core_kernel_classes_Class $clazz
  * @throws \common_Exception
  * @throws \core_kernel_classes_EmptyProperty
  * @return core_kernel_classes_Resource
  */
 public function cloneInstance(\core_kernel_classes_Resource $instance, \core_kernel_classes_Class $clazz = null)
 {
     $loginProperty = new \core_kernel_classes_Property(PROPERTY_USER_LOGIN);
     $login = $instance->getUniquePropertyValue($loginProperty);
     $returnValue = parent::cloneInstance($instance, $clazz);
     $userService = \tao_models_classes_UserService::singleton();
     try {
         while ($userService->loginExists($login)) {
             $login .= (string) rand(0, 9);
         }
         $returnValue->editPropertyValues($loginProperty, $login);
     } catch (common_Exception $ce) {
         // empty
     }
     return $returnValue;
 }
Exemplo n.º 23
0
 /**
  * edit an subject instance
  * 
  */
 public function editSubject()
 {
     $clazz = $this->getCurrentClass();
     // get the subject to edit
     $subject = $this->getCurrentInstance();
     $addMode = false;
     $login = (string) $subject->getOnePropertyValue(new \core_kernel_classes_Property(PROPERTY_USER_LOGIN));
     if (empty($login)) {
         $addMode = true;
         $this->setData('loginUri', \tao_helpers_Uri::encode(PROPERTY_USER_LOGIN));
     }
     if ($this->hasRequestParameter('reload')) {
         $this->setData('reload', true);
     }
     $myFormContainer = new TestTakerForm($clazz, $subject, $addMode, false);
     $myForm = $myFormContainer->getForm();
     if ($myForm->isSubmited()) {
         if ($myForm->isValid()) {
             $this->setData('reload', false);
             $values = $myForm->getValues();
             if ($addMode) {
                 $values[PROPERTY_USER_PASSWORD] = \core_kernel_users_Service::getPasswordHash()->encrypt($values['password1']);
                 unset($values['password1']);
                 unset($values['password2']);
             } else {
                 if (!empty($values['password2'])) {
                     $values[PROPERTY_USER_PASSWORD] = \core_kernel_users_Service::getPasswordHash()->encrypt($values['password2']);
                 }
                 unset($values['password2']);
                 unset($values['password3']);
             }
             $binder = new \tao_models_classes_dataBinding_GenerisFormDataBinder($subject);
             $subject = $binder->bind($values);
             $this->getEventManager()->trigger(new TestTakerUpdatedEvent($subject->getUri(), $values));
             if ($addMode) {
                 // force default subject roles to be the Delivery Role:
                 $this->service->setTestTakerRole($subject);
             }
             // force the data language to be the same as the gui language
             $userService = \tao_models_classes_UserService::singleton();
             $lang = new \core_kernel_classes_Resource($values[PROPERTY_USER_UILG]);
             $userService->bindProperties($subject, array(PROPERTY_USER_DEFLG => $lang->getUri()));
             $message = __('Test taker saved');
             if ($addMode) {
                 $params = array('uri' => \tao_helpers_Uri::encode($subject->getUri()), 'classUri' => \tao_helpers_Uri::encode($clazz->getUri()), 'reload' => true, 'message' => $message);
                 $this->redirect(_url('editSubject', null, null, $params));
             }
             $this->setData("selectNode", \tao_helpers_Uri::encode($subject->getUri()));
             $this->setData('message', $message);
             $this->setData('reload', true);
         }
     }
     if (\common_ext_ExtensionsManager::singleton()->isEnabled('taoGroups')) {
         $this->setData('groupForm', GroupForm::renderGroupTreeForm($subject));
     }
     $this->setData('checkLogin', $addMode);
     $this->setData('formTitle', __('Edit subject'));
     $this->setData('myForm', $myForm->render());
     $this->setView('form_subjects.tpl');
 }
 /**
  * action used to check if a login can be used
  * @throws \Exception
  */
 public function checkLogin()
 {
     if (!tao_helpers_Request::isAjax()) {
         throw new \Exception("wrong request mode");
     }
     $available = false;
     if ($this->hasRequestParameter('login')) {
         $available = \tao_models_classes_UserService::singleton()->loginAvailable($this->getRequestParameter('login'));
     }
     $this->returnJson(array('available' => $available));
 }
Exemplo n.º 25
0
 /**
  * This action returns the roles of the user 'userid' in JSON.
  * 
  * example:
  * 
  * {
  * 		"roles": [
  * 			"http://www.tao.lu/Ontologies/TAO.rdf#userRole1",
  * 			"http://www.tao.lu/Ontologies/TAO.rdf#userRole2"
  * 		]
  * }
  * 
  * @throws common_Exception If the 'userid' parameter is missing.
  */
 public function getUserRoles()
 {
     if (!$this->hasRequestParameter('userid')) {
         throw new common_Exception("Missing parameter 'userid'");
     }
     $user = new core_kernel_classes_Resource($this->getRequestParameter('userid'));
     $uris = array();
     foreach (tao_models_classes_UserService::singleton()->getUserRoles($user) as $role) {
         $uris[] = $role->getUri();
     }
     return $this->returnSuccess(array('roles' => $uris));
 }
 /**
  * Short description of method checkAcl
  *
  * @access public
  * @author Joel Bout, <*****@*****.**>
  * @param  Resource processDefinition
  * @param  Resource currentUser
  * @return boolean
  */
 public function checkAcl(core_kernel_classes_Resource $processDefinition, core_kernel_classes_Resource $currentUser)
 {
     $returnValue = (bool) false;
     if (!is_null($processDefinition)) {
         $processModeProp = new core_kernel_classes_Property(PROPERTY_PROCESS_INIT_ACL_MODE);
         $restrictedUserProp = new core_kernel_classes_Property(PROPERTY_PROCESS_INIT_RESTRICTED_USER);
         $restrictedRoleProp = new core_kernel_classes_Property(PROPERTY_PROCESS_INIT_RESTRICTED_ROLE);
         //process and current must be set to the activty execution otherwise a common Exception is thrown
         $modeUri = $processDefinition->getOnePropertyValue($processModeProp);
         if (is_null($modeUri) || $modeUri instanceof core_kernel_classes_Literal) {
             $returnValue = true;
             //if no mode defined, the process is allowed
         } else {
             switch ($modeUri->getUri()) {
                 //check if th current user is the restricted user
                 case INSTANCE_ACL_USER:
                     $processUser = $processDefinition->getOnePropertyValue($restrictedUserProp);
                     if (!is_null($processUser)) {
                         if ($processUser->getUri() == $currentUser->getUri()) {
                             $returnValue = true;
                         }
                     }
                     break;
                     //check if the current user has the restricted role
                 //check if the current user has the restricted role
                 case INSTANCE_ACL_ROLE:
                     $processRole = $processDefinition->getOnePropertyValue($restrictedRoleProp);
                     $userService = tao_models_classes_UserService::singleton();
                     $returnValue = $userService->userHasRoles($currentUser, $processRole);
                     break;
                 default:
                     $returnValue = true;
             }
         }
     }
     return (bool) $returnValue;
 }
Exemplo n.º 27
0
 public function getUsers()
 {
     if (!tao_helpers_Request::isAjax()) {
         throw new Exception("wrong request mode");
     } else {
         $userService = tao_models_classes_UserService::singleton();
         echo json_encode($userService->toTree(new core_kernel_classes_Class(CLASS_TAO_USER), array()));
     }
 }
Exemplo n.º 28
0
 /**
  * Disconnect the currently connected user.
  *
  * @access public
  * @author Jerome Bogaerts, <*****@*****.**>
  * @return mixed
  */
 public function disconnect()
 {
     if ($this->isConnected()) {
         $this->outVerbose("Disconnecting user...");
         $userService = tao_models_classes_UserService::singleton();
         if ($userService->logout() == true) {
             $this->outVerbose("User gracefully disconnected from TAO API.");
             $this->setConnected(false);
         } else {
             $this->error("User could not be disconnected from TAO API.");
         }
     }
 }
Exemplo n.º 29
0
 public function testFuncACL()
 {
     $baseRole = $this->testrole;
     $srv = tao_models_classes_UserService::singleton();
     $generisUser = new core_kernel_users_GenerisUser($this->user);
     $this->assertTrue(LoginService::startSession($generisUser));
     // -- Test uri creation
     $emauri = FUNCACL_NS . '#a_tao_Users_add';
     $emaurimod = FUNCACL_NS . '#m_tao_Users';
     $makeemauri = funcAcl_models_classes_AccessService::singleton()->makeEMAUri('tao', 'Users', 'add');
     $makeemaurimod = funcAcl_models_classes_AccessService::singleton()->makeEMAUri('tao', 'Users');
     $this->assertEquals($emauri, $makeemauri);
     $this->assertEquals($emaurimod, $makeemaurimod);
     $funcAclImp = new funcAcl_models_classes_FuncAcl();
     // -- Try to access a restricted action
     $this->assertFalse($funcAclImp->hasAccess('add', 'Users', 'tao'));
     // -- Try to access a unrestricted action
     // (BACKOFFICE has access to the backend login action because it includes the TAO Role)
     $this->assertTrue($funcAclImp->hasAccess('login', 'Main', 'tao'));
     // -- Try to access an action that does not exist.
     $this->assertFalse($funcAclImp->hasAccess('action', 'Unknown', 'tao'));
     // -- Try to access a unrestricted action
     // Add access for this action to the Manager role.
     funcAcl_models_classes_ActionAccessService::singleton()->add($this->testRole->getUri(), $makeemauri);
     // Add the Manager role the the currently tested user
     tao_models_classes_UserService::singleton()->attachRole($this->user, $this->testRole);
     // Logoff/login, to refresh roles cache
     $this->assertTrue(LoginService::startSession($generisUser));
     // Ask for access
     $this->assertTrue($funcAclImp->hasAccess('add', 'Users', 'tao'));
     // Remove the access to this action from the Manager role
     funcAcl_models_classes_ActionAccessService::singleton()->remove($this->testRole->getUri(), $makeemauri);
     // We should not have access anymore to this action with the Manager role
     $this->assertFalse($funcAclImp->hasAccess('add', 'Users', 'tao'));
     // -- Give access to the entire module and try to access the previously tested action
     funcAcl_models_classes_ModuleAccessService::singleton()->add($this->testRole->getUri(), $makeemaurimod);
     $this->assertTrue($funcAclImp->hasAccess('add', 'Users', 'tao'));
     // -- Remove the entire module access and try again
     funcAcl_models_classes_ModuleAccessService::singleton()->remove($this->testRole->getUri(), $makeemaurimod);
     $this->assertFalse($funcAclImp->hasAccess('add', 'Users', 'tao'));
     // reset
     funcAcl_models_classes_ModuleAccessService::singleton()->add($this->testRole->getUri(), $makeemaurimod);
     // Unattach role from user
     tao_models_classes_UserService::singleton()->unnatachRole($this->user, $this->testRole);
 }
require_once dirname(__FILE__) . '/../../taoResultServer/includes/raw_start.php';
if (!common_ext_ExtensionsManager::singleton()->isEnabled('taoProctoring')) {
    echo 'extension taoProctoring needs to be installed and enabled in order to run this script !';
    die;
}
foreach ($todefine as $contant => $value) {
    define($contant, $value);
}
$params = $argv;
array_shift($params);
$totalTtNum = isset($params[0]) ? $params[0] : 500;
$ttByProctor = isset($params[1]) && is_numeric($params[1]) && $params[1] !== 0 ? $params[1] : 20;
$totalProctorNum = $totalTtNum / $ttByProctor;
$totalProctorNum = $totalProctorNum < 1 ? 1 : $totalProctorNum;
$testTakerCrudService = oat\taoTestTaker\models\CrudService::singleton();
$userService = \tao_models_classes_UserService::singleton();
$testCenterService = \oat\taoProctoring\model\TestCenterService::singleton();
$proctorManagementService = \oat\taoProctoring\model\ProctorManagementService::singleton();
$testTakerService = \oat\taoTestTaker\models\TestTakerService::singleton();
$userClass = new \core_kernel_classes_Class(CLASS_TAO_USER);
//create delivery
$tests = [];
$testClazz = new core_kernel_classes_Class(TAO_TEST_CLASS);
foreach ($testClazz->getInstances(true) as $instance) {
    $tests[$instance->getUri()] = $instance->getLabel();
}
$testUris = array_keys($tests);
if (!empty($testUris)) {
    $i = 0;
    $delivery = null;
    $deliveryClass = new \core_kernel_classes_Class('http://www.tao.lu/Ontologies/TAODelivery.rdf#AssembledDelivery');