public function setUp() { TaoPhpUnitTestRunner::initTest(); $this->disableCache(); // creates a user using remote script from joel $testUserData = array(PROPERTY_USER_LOGIN => 'tjdoe', PROPERTY_USER_PASSWORD => 'test123', PROPERTY_USER_LASTNAME => 'Doe', PROPERTY_USER_FIRSTNAME => 'John', PROPERTY_USER_MAIL => '*****@*****.**', PROPERTY_USER_DEFLG => \tao_models_classes_LanguageService::singleton()->getLanguageByCode(DEFAULT_LANG)->getUri(), PROPERTY_USER_UILG => \tao_models_classes_LanguageService::singleton()->getLanguageByCode(DEFAULT_LANG)->getUri(), PROPERTY_USER_ROLES => array(INSTANCE_ROLE_GLOBALMANAGER)); $testUserData[PROPERTY_USER_PASSWORD] = 'test' . rand(); $data = $testUserData; $data[PROPERTY_USER_PASSWORD] = \core_kernel_users_Service::getPasswordHash()->encrypt($data[PROPERTY_USER_PASSWORD]); $tmclass = new \core_kernel_classes_Class(CLASS_TAO_USER); $user = $tmclass->createInstanceWithProperties($data); \common_Logger::i('Created user ' . $user->getUri()); // prepare a lookup table of languages and values $usage = new \core_kernel_classes_Resource(INSTANCE_LANGUAGE_USAGE_GUI); $propValue = new \core_kernel_classes_Property(RDF_VALUE); $langService = \tao_models_classes_LanguageService::singleton(); $lookup = array(); foreach ($langService->getAvailableLanguagesByUsage($usage) as $lang) { $lookup[$lang->getUri()] = (string) $lang->getUniquePropertyValue($propValue); } $data = array('rootUrl' => ROOT_URL, 'userUri' => $user->getUri(), 'userData' => $testUserData, 'lang' => $lookup); $this->login = $data['userData'][PROPERTY_USER_LOGIN]; $this->password = $data['userData'][PROPERTY_USER_PASSWORD]; $this->userUri = $data['userUri']; }
/** * returns the md5 hash of the password * * @access public * @author Joel Bout, <*****@*****.**> * @return mixed */ public function getEvaluatedValue() { $returnValue = null; $arr = $this->getRawValue(); $returnValue = core_kernel_users_Service::getPasswordHash()->encrypt(array_shift($arr)); return $returnValue; }
public function __invoke($params) { // recreate languages $modelCreator = new \tao_install_utils_ModelCreator(LOCAL_NAMESPACE); $models = $modelCreator->getLanguageModels(); foreach ($models as $ns => $modelFiles) { foreach ($modelFiles as $file) { $modelCreator->insertLocalModel($file); } } OntologyUpdater::syncModels(); // reapply access rights $exts = \common_ext_ExtensionsManager::singleton()->getInstalledExtensions(); foreach ($exts as $ext) { $installer = new \tao_install_ExtensionInstaller($ext); $installer->installManagementRole(); $installer->applyAccessRules(); } // recreate admin if (count($params) >= 2) { $login = array_shift($params); $password = array_shift($params); $sysAdmin = $this->getResource(INSTANCE_ROLE_SYSADMIN); $userClass = $this->getClass(CLASS_TAO_USER); \core_kernel_users_Service::singleton()->addUser($login, $password, $sysAdmin, $userClass); } // empty cache \common_cache_FileCache::singleton()->purge(); return \common_report_Report::createSuccess('All done'); }
/** * tests initialization */ public function setUp() { TaoPhpUnitTestRunner::initTest(); $this->userService = tao_models_classes_UserService::singleton(); $this->testUserData[PROPERTY_USER_PASSWORD] = core_kernel_users_Service::getPasswordHash()->encrypt($this->testUserData[PROPERTY_USER_PASSWORD]); $this->testUserUtf8Data[PROPERTY_USER_PASSWORD] = core_kernel_users_Service::getPasswordHash()->encrypt($this->testUserUtf8Data[PROPERTY_USER_PASSWORD]); }
/** * tests initialization */ public function setUp() { TaoPhpUnitTestRunner::initTest(); $this->clearPassword = $this->testUserData[PROPERTY_USER_PASSWORD]; $this->testUserData[PROPERTY_USER_PASSWORD] = core_kernel_users_Service::getPasswordHash()->encrypt($this->testUserData[PROPERTY_USER_PASSWORD]); $this->userService = tao_models_classes_UserService::singleton(); $class = new core_kernel_classes_Class(CLASS_GENERIS_USER); $this->testUser = $class->createInstance(); $this->assertNotNull($this->testUser); $this->userService->bindProperties($this->testUser, $this->testUserData); }
/** * Extends the users explizit roles with the implizit rules * of the local system * * @return array the identifiers of the roles: */ public function getRoles() { $returnValue = array(); // We use a Depth First Search approach to flatten the Roles Graph. foreach ($this->getPropertyValues(PROPERTY_USER_ROLES) as $roleUri) { $returnValue[] = $roleUri; foreach (core_kernel_users_Service::singleton()->getIncludedRoles(new core_kernel_classes_Resource($roleUri)) as $role) { $returnValue[] = $role->getUri(); } } return array_unique($returnValue); }
protected function createUser($login) { $userData = array(PROPERTY_USER_LOGIN => $login, PROPERTY_USER_PASSWORD => core_kernel_users_Service::getPasswordHash()->encrypt($this->userPassword), PROPERTY_USER_DEFLG => 'http://www.tao.lu/Ontologies/TAO.rdf#Lang' . DEFAULT_LANG, PROPERTY_USER_UILG => 'http://www.tao.lu/Ontologies/TAO.rdf#Lang' . DEFAULT_LANG, PROPERTY_USER_ROLES => INSTANCE_ROLE_WORKFLOW); if (!$this->userService->loginAvailable($login)) { $this->fail('test login already taken'); } $userClass = new core_kernel_classes_Class(CLASS_WORKFLOWUSER); $user = $userClass->createInstanceWithProperties($userData); if (is_null($user)) { throw new Exception('cannot get the user with login ' . $login); } return $user; }
/** * initialize a test method */ public function setUp() { parent::setUp(); $login = '******'; $userData = array(PROPERTY_USER_LOGIN => $login, PROPERTY_USER_PASSWORD => core_kernel_users_Service::getPasswordHash()->encrypt($this->userPassword), PROPERTY_USER_DEFLG => 'http://www.tao.lu/Ontologies/TAO.rdf#Lang' . DEFAULT_LANG, PROPERTY_USER_UILG => 'http://www.tao.lu/Ontologies/TAO.rdf#Lang' . DEFAULT_LANG, PROPERTY_USER_ROLES => INSTANCE_ROLE_WORKFLOW); if (!$this->userService->loginAvailable($login)) { $this->fail('test login already taken'); } $userClass = new core_kernel_classes_Class(CLASS_WORKFLOWUSER); $this->currentUser = $userClass->createInstanceWithProperties($userData); $this->currentUser0 = $this->currentUser; $this->service = wfEngine_models_classes_ActivityExecutionService::singleton(); }
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; }
public function setUp() { TaoPhpUnitTestRunner::initTest(); $this->disableCache(); // creates a user using remote script from joel $userdata = $this->getUserData(); $password = $userdata[PROPERTY_USER_PASSWORD]; $userdata[PROPERTY_USER_PASSWORD] = \core_kernel_users_Service::getPasswordHash()->encrypt($userdata[PROPERTY_USER_PASSWORD]); $tmclass = new \core_kernel_classes_Class(CLASS_TAO_USER); $user = $tmclass->createInstanceWithProperties($userdata); \common_Logger::i('Created user ' . $user->getUri()); $this->login = $userdata[PROPERTY_USER_LOGIN]; $this->password = $password; $this->userUri = $user->getUri(); }
/** * initialize a test method */ public function setUp() { TaoPhpUnitTestRunner::initTest(); error_reporting(E_ALL); if (is_null($this->userService)) { $this->userService = wfEngine_models_classes_UserService::singleton(); } $login = '******'; $pass = '******'; $langResource = tao_models_classes_LanguageService::singleton()->getLanguageByCode(DEFAULT_LANG); $userData = array(PROPERTY_USER_LOGIN => $login, PROPERTY_USER_PASSWORD => core_kernel_users_Service::getPasswordHash()->encrypt($pass), PROPERTY_USER_DEFLG => $langResource, PROPERTY_USER_MAIL => '*****@*****.**', PROPERTY_USER_FIRSTNAME => 'Sammy', PROPERTY_USER_LASTNAME => 'Norville Rogers', PROPERTY_USER_ROLES => INSTANCE_ROLE_WORKFLOW); if (!$this->userService->loginAvailable($login)) { $this->fail('test login already taken'); } $userClass = new core_kernel_classes_Class(CLASS_WORKFLOWUSER); $this->currentUser = $userClass->createInstanceWithProperties($userData); $this->assertTrue($this->userService->loginUser($login, $pass)); $this->service = wfEngine_models_classes_NotificationService::singleton(); }
public function run() { $dbWrapper = core_kernel_classes_DbWrapper::singleton(); $sth = $dbWrapper->prepare('SELECT DISTINCT "author" FROM statements'); $result = $sth->execute(); $updateQuery = $dbWrapper->prepare('UPDATE statements SET "author" = ? WHERE "author" = ?;'); foreach ($sth->fetchAll() as $data) { if (!empty($data['author'])) { $login = $data['author']; $user = core_kernel_users_Service::singleton()->getOneUser($login); if (is_null($user)) { $this->out('User with login ' . $login . ' not found, skipping'); } else { if (!$updateQuery->execute(array($user->getUri(), $login))) { $this->err('Unable to replace ' . $login . ' with ' . $user->getUri()); } } } } }
/** * (non-PHPdoc) * @see tao_models_classes_CrudService::update() */ public function update($uri = null, $propertiesValues = array()) { if (is_null($uri)) { throw new \common_exception_MissingParameter("uri"); } if (isset($propertiesValues[PROPERTY_USER_LOGIN])) { throw new \common_exception_PreConditionFailure("login update not allowed"); } if (isset($propertiesValues[PROPERTY_USER_PASSWORD])) { $propertiesValues[PROPERTY_USER_PASSWORD] = \core_kernel_users_Service::getPasswordHash()->encrypt($propertiesValues[PROPERTY_USER_PASSWORD]); } parent::update($uri, $propertiesValues); // throw new common_exception_NotImplemented(); }
$userService = new AuthKeyValueUserService(); $row = 1; if (($handle = fopen($csvfile, "r")) !== false) { while (($data = fgetcsv($handle, 1000, ";")) !== false) { if ($row === 1) { // if (json_encode($data) != json_encode(array_keys($expected))) { // echo 'Expected data in the format "'.implode('","', $expected).'".'.PHP_EOL; // die(1); // } } else { $toAdd = array(GroupsService::PROPERTY_MEMBERS_URI => array($groupUri)); foreach ($data as $pos => $value) { $toAdd[$expected[$keys[$pos]]] = $value; } // encode password $toAdd[PROPERTY_USER_PASSWORD] = core_kernel_users_Service::getPasswordHash()->encrypt($toAdd[PROPERTY_USER_PASSWORD]); if ($userService->getUserData($toAdd[PROPERTY_USER_LOGIN]) != false) { echo 'User "' . $toAdd[PROPERTY_USER_LOGIN] . '" already exists.' . PHP_EOL; } else { $userData = DataGeneration::createUser($toAdd, $lang); try { $persistence->insert('redis', array('subject' => $userData['uri'], 'predicate' => PROPERTY_USER_LOGIN, 'object' => $userData[PROPERTY_USER_LOGIN])); } catch (PDOException $e) { echo 'please make sure that called redis exists with subject,predicate,object' . "\n"; echo 'insert as first line : ' . $userData['uri'] . " , " . PROPERTY_USER_LOGIN . " , " . $userData[PROPERTY_USER_LOGIN]; die(1); } } } $row++; }
public function testLogout() { $this->assertTrue($this->service->isASessionOpened()); $this->service->logout(); $this->assertFalse($this->service->isASessionOpened()); }
/** * Returns the whole collection of Roles stored into TAO. * * @return array An associative array where keys are Role URIs and values are core_kernel_classes_Resource instances. */ public function getAllRoles() { return $this->generisUserService->getAllRoles(); }
/** * Test the tokens into a parallel process */ public function testVirtualParallelJoinProcess() { error_reporting(E_ALL); $t_start = microtime(true); //init services $activityService = wfEngine_models_classes_ActivityService::singleton(); $processVariableService = wfEngine_models_classes_VariableService::singleton(); $authoringService = wfAuthoring_models_classes_ProcessService::singleton(); $activityExecutionService = wfEngine_models_classes_ActivityExecutionService::singleton(); $activityExecutionService->cache = (bool) self::SERVICE_CACHE; //process definition $processDefinitionClass = new core_kernel_classes_Class(CLASS_PROCESS); $processDefinition = $processDefinitionClass->createInstance('PJ processForUnitTest_' . date(DATE_ISO8601), 'created for the unit test of process execution'); $this->assertNotNull($processDefinition); /* +---------------+ | activity 0 | +-------+-------+ | +---v---+ | c 0 | split +--+-+--+ | | 3 +---------+ +---------+ unit_var_12345678 | | +-------v--------+ +-------v------+ | activity 1 | | activity 2 | +-------+--------+ +--------+-----+ | | +--------+ +--------+ +--v----v--+ | c 2 | join +----+-----+ | +-------v--------+ | activity 3 | +----------------+ */ //activities definitions $activity0 = $authoringService->createActivity($processDefinition, 'activity0'); $this->assertNotNull($activity0); $connector0 = null; $authoringService->setFirstActivity($processDefinition, $activity0); $connector0 = $authoringService->createConnector($activity0); $connectorParallele = new core_kernel_classes_Resource(INSTANCE_TYPEOFCONNECTORS_PARALLEL); $authoringService->setConnectorType($connector0, $connectorParallele); $this->assertNotNull($connector0); $parallelActivity1 = $authoringService->createActivity($processDefinition, 'activity1'); $this->assertNotNull($parallelActivity1); $roleRestrictedUser = new core_kernel_classes_Resource(INSTANCE_ACL_ROLE_RESTRICTED_USER); $activityService->setAcl($parallelActivity1, $roleRestrictedUser, $this->testUserRole); //!!! it is mendatory to set the role restricted user ACL mode to make this parallel process test case work $connector1 = null; $connector1 = $authoringService->createConnector($parallelActivity1); $this->assertNotNull($connector1); $parallelActivity2 = $authoringService->createActivity($processDefinition, 'activity2'); $this->assertNotNull($parallelActivity2); $activityService->setAcl($parallelActivity2, $roleRestrictedUser, $this->testUserRole); //!!! it is mendatory to set the role restricted user ACL mode to make this parallel process test case work $connector2 = null; $connector2 = $authoringService->createConnector($parallelActivity2); $this->assertNotNull($connector2); //define parallel activities, first branch with constant cardinality value, while the second listens to a process variable: $parallelCount1 = 3; $parallelCount2 = 5; $parallelCount2_processVar_key = 'unit_var_' . time(); $parallelCount2_processVar = $processVariableService->createProcessVariable('Var for unit test', $parallelCount2_processVar_key); $prallelActivitiesArray = array($parallelActivity1->getUri() => $parallelCount1, $parallelActivity2->getUri() => $parallelCount2_processVar); $result = $authoringService->setParallelActivities($connector0, $prallelActivitiesArray); $this->assertTrue($result); //set several split variables: $splitVariable1_key = 'unit_split_var1_' . time(); $splitVariable1 = $processVariableService->createProcessVariable('Split Var1 for unit test', $splitVariable1_key); $splitVariable2_key = 'unit_split_var2_' . time(); $splitVariable2 = $processVariableService->createProcessVariable('Split Var2 for unit test', $splitVariable2_key); $splitVariablesArray = array($parallelActivity1->getUri() => array($splitVariable1), $parallelActivity2->getUri() => array($splitVariable1, $splitVariable2)); $connectorService = wfAuthoring_models_classes_ConnectorService::singleton(); $connectorService->setSplitVariables($connector0, $splitVariablesArray); $prallelActivitiesArray[$parallelActivity2->getUri()] = $parallelCount2; $joinActivity = $authoringService->createActivity($processDefinition, 'activity3'); //join parallel Activity 1 and 2 to "joinActivity" $connector1 = wfAuthoring_models_classes_ConnectorService::singleton()->createJoin(array($parallelActivity1, $parallelActivity2), $joinActivity); /* $authoringService->createJoinActivity($connector1, $joinActivity, '', $parallelActivity1); $authoringService->createJoinActivity($connector2, $joinActivity, '', $parallelActivity2); */ //run the process $processExecName = 'Test Parallel Process Execution'; $processExecComment = 'created for processExecustionService test case by ' . __METHOD__; $processInstance = $this->service->createProcessExecution($processDefinition, $processExecName, $processExecComment); $this->assertTrue($this->service->checkStatus($processInstance, 'started')); $this->out(__METHOD__, true); $this->out("<strong>Forward transitions:</strong>", true); $previousActivityExecution = null; $numberActivities = 2 + $parallelCount1 + $parallelCount2; $createdUsers = array(); $loginProperty = new core_kernel_classes_Property(PROPERTY_USER_LOGIN); for ($i = 1; $i <= $numberActivities; $i++) { $activitieExecs = $this->service->getCurrentActivityExecutions($processInstance); $countActivities = count($activitieExecs); $activity = null; $activityExecution = null; if ($countActivities > 1) { //select one of the available activities in the parallel branch: foreach ($activitieExecs as $activityExecUri => $activityExec) { if (!$activityExecutionService->isFinished($activityExec)) { $activityDefinition = $activityExecutionService->getExecutionOf($activityExec); $activityUri = $activityDefinition->getUri(); if (isset($prallelActivitiesArray[$activityUri])) { if ($prallelActivitiesArray[$activityUri] > 0) { $prallelActivitiesArray[$activityUri]--; $activityExecution = $activityExec; $activity = $activityDefinition; break; } } } } } else { if ($countActivities == 1) { $activityExecution = reset($activitieExecs); $activity = $activityExecutionService->getExecutionOf($activityExecution); } else { $this->fail('no current activity definition found for the iteration ' . $i); } } $this->out("<strong> Iteration {$i} :</strong>", true); $this->out("<strong>" . (is_null($activity) ? 'null' : $activity->getLabel()) . "</strong> (among {$countActivities})"); //issue : no activity found for the last iteration... //init execution $activityExecution = $this->service->initCurrentActivityExecution($processInstance, $activityExecution, $this->currentUser); $this->assertNotNull($activityExecution); if ($i == 1) { //set value of the parallel thread: $processVariableService->push($parallelCount2_processVar_key, $parallelCount2); //set some values to the split variables: $values1 = array(); for ($j = 1; $j <= $parallelCount1; $j++) { $values1[] = 'A' . $j; } $values2 = array(); for ($j = 1; $j <= $parallelCount2; $j++) { $values2[] = 'B' . $j; } $processVariableService->push($splitVariable1_key, serialize($values1)); $processVariableService->push($splitVariable2_key, serialize($values2)); } else { //check dispatched value: // $value1 = $processVariableService->get($splitVariable1_key); // $value2 = $processVariableService->get($splitVariable2_key); // var_dump($value1, $value2); } $activityExecStatus = $activityExecutionService->getStatus($activityExecution); $this->assertNotNull($activityExecStatus); $this->assertEquals($activityExecStatus->getUri(), INSTANCE_PROCESSSTATUS_STARTED); //transition to next activity $this->out("current user: "******"' . $this->currentUser->getUri() . '"'); $this->out("performing transition ..."); //transition to next activity $performed = $this->service->performTransition($processInstance, $activityExecution); if (!$performed) { $this->out('transition failed.'); } $this->out("activity status: " . $activityExecutionService->getStatus($activityExecution)->getLabel()); $this->out("process status: " . $this->service->getStatus($processInstance)->getLabel()); //try undoing the transition: switch ($i) { case 1: $this->assertTrue($this->service->undoForwardTransition($processInstance, $activityExecution)); $activitieExecs = $this->service->getCurrentActivityExecutions($processInstance); $this->assertEquals(count($activitieExecs), 1); $activityBis = $activityExecutionService->getExecutionOf(reset($activitieExecs)); $this->assertTrue($activity->getUri() == $activityBis->getUri()); $transitionResult = $this->service->performTransition($processInstance, $activityExecution); break; case 1 + $parallelCount1: $this->assertFalse($this->service->undoForwardTransition($processInstance, $activityExecution)); $history = $this->service->getExecutionHistory($processInstance); $this->assertEquals(count($history), 2 * ($parallelCount1 + $parallelCount2) + 1); //activity 1, 2(closed), 2, 3 and 4 $this->assertFalse($this->service->undoForwardTransition($processInstance, new core_kernel_classes_Resource(reset($history)))); $this->assertNotNull($previousActivityExecution); $this->assertFalse($this->service->undoForwardTransition($processInstance, $previousActivityExecution)); break; case 1 + $parallelCount1 + $parallelCount2: $this->assertTrue($this->service->undoForwardTransition($processInstance, $activityExecution)); $activitieExecs = $this->service->getCurrentActivityExecutions($processInstance); $this->assertEquals(count($activitieExecs), $parallelCount1 + $parallelCount2); $transitionResult = $this->service->performTransition($processInstance, $activityExecution); break; } $previousActivityExecution = $activityExecution; if ($this->service->isPaused($processInstance)) { //Login another user to execute parallel branch $this->userService->logout(); $this->out("logout " . $this->currentUser->getOnePropertyValue($loginProperty) . ' "' . $this->currentUser->getUri() . '"', true); list($usec, $sec) = explode(" ", microtime()); $login = '******' . $i . '-' . $usec; $pass = '******'; $userData = array(PROPERTY_USER_LOGIN => $login, PROPERTY_USER_PASSWORD => core_kernel_users_Service::getPasswordHash()->encrypt($pass), PROPERTY_USER_DEFLG => 'http://www.tao.lu/Ontologies/TAO.rdf#Lang' . DEFAULT_LANG, PROPERTY_USER_UILG => 'http://www.tao.lu/Ontologies/TAO.rdf#Lang' . DEFAULT_LANG, PROPERTY_USER_ROLES => INSTANCE_ROLE_WORKFLOW, RDFS_LABEL => $login); if (!$this->userService->loginAvailable($login)) { $this->fail('test login already taken'); } $otherUser = $this->testUserClass->createInstanceWithProperties($userData); $createdUsers[$otherUser->getUri()] = $otherUser; if ($this->userService->loginUser($login, $pass)) { $this->currentUser = $this->userService->getCurrentUser(); $this->out("new user logged in: " . $this->currentUser->getOnePropertyValue($loginProperty) . ' "' . $this->currentUser->getUri() . '"'); } else { $this->fail("unable to login user {$login}"); } } } $this->assertTrue($this->service->isFinished($processInstance)); $this->assertTrue($this->service->resume($processInstance)); $this->out("<strong>Backward transitions:</strong>", true); // var_dump($this->service->getAllActivityExecutions($processInstance)); $j = 0; $iterationNumber = 2; while ($j < $iterationNumber) { $activitieExecs = $this->service->getCurrentActivityExecutions($processInstance); $activityExecution = null; $activity = null; switch ($j) { case 0: $this->assertEquals(count($activitieExecs), 1); //check $activityExecution = reset($activitieExecs); $activity = $activityExecutionService->getExecutionOf($activityExecution); break; case 1: $this->assertEquals(count($activitieExecs), $parallelCount1 + $parallelCount2); //check $activity = $parallelActivity2; foreach ($this->service->getCurrentActivityExecutions($processInstance, $activity) as $activityExec) { if ($activityExecutionService->getActivityExecutionUser($activityExec)->getUri() == $this->currentUser->getUri()) { $activityExecution = $activityExec; } } if (is_null($activityExecution)) { $activity = $parallelActivity1; foreach ($this->service->getCurrentActivityExecutions($processInstance, $activity) as $activityExec) { if ($activityExecutionService->getActivityExecutionUser($activityExec)->getUri() == $this->currentUser->getUri()) { $activityExecution = $activityExec; } } } $this->assertNotNull($activityExecution); break; } $this->out("<strong>" . $activity->getLabel() . "</strong>", true); //init execution $activityExecution = $this->service->initCurrentActivityExecution($processInstance, $activityExecution, $this->currentUser); $this->assertNotNull($activityExecution); $activityExecStatus = $activityExecutionService->getStatus($activityExecution); $this->assertNotNull($activityExecStatus); $this->assertEquals($activityExecStatus->getUri(), INSTANCE_PROCESSSTATUS_RESUMED); $this->out("current user: "******"' . $this->currentUser->getUri() . '"'); $this->out("performing transition ..."); //transition to next activity $transitionResult = $this->service->performBackwardTransition($processInstance, $activityExecution); if ($j == 0) { $this->assertTrue(count($transitionResult) > 0); } else { if ($j == $iterationNumber - 1) { //var_dump($transitionResult); $this->assertFalse($transitionResult); } } $processStatus = $this->service->getStatus($processInstance); $this->assertNotNull($processStatus); $this->out("activity status: " . $activityExecutionService->getStatus($activityExecution)->getLabel()); $this->out("process status: " . $processStatus->getLabel()); $this->assertEquals($processStatus->getUri(), INSTANCE_PROCESSSTATUS_PAUSED); $j++; } $this->out("<strong>Forward transitions again:</strong>", true); $currentActivityExecutions = $this->service->getCurrentActivityExecutions($processInstance); $currentActivityExecutionsCount = count($currentActivityExecutions); $this->assertEquals($currentActivityExecutionsCount, $parallelCount1 + $parallelCount2); for ($i = 0; $i < $currentActivityExecutionsCount; $i++) { $currentActivityExecution = array_pop($currentActivityExecutions); $user = $activityExecutionService->getActivityExecutionUser($currentActivityExecution); $activityDefinition = $activityExecutionService->getExecutionOf($currentActivityExecution); $this->assertNotNull($user); $this->assertNotNull($activityDefinition); if (!is_null($user) && !is_null($activityDefinition)) { $this->userService->logout(); $this->out("logout " . $this->currentUser->getOnePropertyValue($loginProperty) . ' "' . $this->currentUser->getUri() . '"', true); $login = (string) $user->getUniquePropertyValue($loginProperty); $pass = '******'; if ($this->userService->loginUser($login, $pass)) { $this->currentUser = $this->userService->getCurrentUser(); $this->out("new user logged in: " . $this->currentUser->getOnePropertyValue($loginProperty) . ' "' . $this->currentUser->getUri() . '"'); } else { $this->fail("unable to login user {$login}<br>"); } $iterationNo = $i + 1; $this->out("<strong>Iteration {$iterationNo}: " . $activityDefinition->getLabel() . "</strong>", true); //execute activity: $activityExecution = $this->service->initCurrentActivityExecution($processInstance, $currentActivityExecution, $this->currentUser); $this->assertNotNull($activityExecution); $activityExecStatus = $activityExecutionService->getStatus($activityExecution); $this->assertNotNull($activityExecStatus); $this->assertEquals($activityExecStatus->getUri(), INSTANCE_PROCESSSTATUS_RESUMED); //transition to next activity $this->out("current user: "******"' . $this->currentUser->getUri() . '"'); $this->out("performing transition ..."); //transition to next activity $this->service->performTransition($processInstance, $activityExecution); $this->out("activity status: " . $activityExecutionService->getStatus($activityExecution)->getLabel()); $this->out("process status: " . $this->service->getStatus($processInstance)->getLabel()); //try undoing the transition: if ($i < $currentActivityExecutionsCount - 1) { $this->assertFalse($this->service->undoForwardTransition($processInstance, $activityExecution)); } } } //try undoing the transition: $this->assertTrue($this->service->undoForwardTransition($processInstance, $activityExecution)); $activitieExecs = $this->service->getCurrentActivityExecutions($processInstance); $this->assertEquals(count($activitieExecs), $parallelCount1 + $parallelCount2); $transitionResult = $this->service->performTransition($processInstance, $activityExecution); $this->assertEquals(count($transitionResult), 1); $activitieExecs = $this->service->getCurrentActivityExecutions($processInstance); $this->assertEquals(count($activitieExecs), 1); $activityExecution = reset($activitieExecs); $activity = $activityExecutionService->getExecutionOf($activityExecution); $this->assertEquals($activity->getUri(), $joinActivity->getUri()); $this->out("<strong>Executing last activity: " . $activity->getLabel() . "</strong>", true); //init execution $activityExecution = $this->service->initCurrentActivityExecution($processInstance, $activityExecution, $this->currentUser); $this->assertNotNull($activityExecution); $activityExecStatus = $activityExecutionService->getStatus($activityExecution); $this->assertNotNull($activityExecStatus); $this->assertEquals($activityExecStatus->getUri(), INSTANCE_PROCESSSTATUS_STARTED); //transition to next activity $this->out("current user: "******"' . $this->currentUser->getUri() . '"'); $this->out("performing transition ..."); //transition to next activity $this->service->performTransition($processInstance, $activityExecution); $this->out("activity status: " . $activityExecutionService->getStatus($activityExecution)->getLabel()); $this->out("process status: " . $this->service->getStatus($processInstance)->getLabel()); $this->assertTrue($this->service->isFinished($processInstance)); $t_end = microtime(true); $duration = $t_end - $t_start; $this->out('Elapsed time: ' . $duration . 's', true); $this->out('deleting created resources:', true); //delete process exec: $this->assertTrue($this->service->deleteProcessExecution($processInstance)); //delete processdef: $this->assertTrue($authoringService->deleteProcess($processDefinition)); $parallelCount2_processVar->delete(); //delete created users: foreach ($createdUsers as $createdUser) { $this->out('deleting ' . $createdUser->getLabel() . ' "' . $createdUser->getUri() . '"'); $this->assertTrue($this->userService->removeUser($createdUser)); } if (!is_null($this->currentUser)) { $this->userService->logout(); $this->userService->removeUser($this->currentUser); } }
protected function createUser() { $class = new core_kernel_classes_Class(CLASS_GENERIS_USER); return $class->createInstanceWithProperties(array(PROPERTY_USER_LOGIN => 'john.doe', PROPERTY_USER_PASSWORD => core_kernel_users_Service::getPasswordHash()->encrypt('secure'), PROPERTY_USER_LASTNAME => 'Doe', PROPERTY_USER_FIRSTNAME => 'John', PROPERTY_USER_MAIL => '*****@*****.**', PROPERTY_USER_DEFLG => 'http://www.tao.lu/Ontologies/TAO.rdf#Langen-US', PROPERTY_USER_UILG => 'http://www.tao.lu/Ontologies/TAO.rdf#Langen-US', PROPERTY_USER_ROLES => INSTANCE_ROLE_BACKOFFICE)); }
private function determinTaoRoles() { $roles = array(); if ($this->getLaunchData()->hasVariable(taoLti_models_classes_LtiLaunchData::ROLES)) { foreach ($this->getLaunchData()->getUserRoles() as $role) { $taoRole = taoLti_models_classes_LtiUtils::mapLTIRole2TaoRole($role); if (!is_null($taoRole)) { $roles[] = $taoRole; foreach (core_kernel_users_Service::singleton()->getIncludedRoles(new core_kernel_classes_Resource($taoRole)) as $includedRole) { $roles[] = $includedRole->getUri(); } } } $roles = array_unique($roles); } else { return array(INSTANCE_ROLE_LTI_BASE); } return $roles; }
/** * Run the TAO install from the given data * @throws tao_install_utils_Exception * @param $installData data coming from the install form * @see tao_install_form_Settings */ public function install(array $installData) { try { /* * 0 - Check input parameters. */ $this->log('i', "Checking install data"); self::checkInstallData($installData); $this->log('i', "Starting TAO install", 'INSTALL'); // Sanitize $installData if needed. if (!preg_match("/\\/\$/", $installData['module_url'])) { $installData['module_url'] .= '/'; } if (isset($installData['extensions'])) { $extensionIDs = is_array($installData['extensions']) ? $installData['extensions'] : explode(',', $installData['extensions']); } else { $extensionIDs = array('taoCe'); } $installData['file_path'] = rtrim($installData['file_path'], DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR; /* * 1 - Check configuration with checks described in the manifest. */ $configChecker = tao_install_utils_ChecksHelper::getConfigChecker($extensionIDs); // Silence checks to have to be escaped. foreach ($configChecker->getComponents() as $c) { if (method_exists($c, 'getName') && in_array($c->getName(), $this->getEscapedChecks())) { $configChecker->silent($c); } } $reports = $configChecker->check(); foreach ($reports as $r) { $msg = $r->getMessage(); $component = $r->getComponent(); $this->log('i', $msg); if ($r->getStatus() !== common_configuration_Report::VALID && !$component->isOptional()) { throw new tao_install_utils_Exception($msg); } } /* * 2 - Test DB connection (done by the constructor) */ $this->log('i', "Spawning DbCreator", 'INSTALL'); $dbName = $installData['db_name']; if ($installData['db_driver'] == 'pdo_oci') { $installData['db_name'] = $installData['db_host']; $installData['db_host'] = ''; } $dbConfiguration = array('driver' => $installData['db_driver'], 'host' => $installData['db_host'], 'dbname' => $installData['db_name'], 'user' => $installData['db_user'], 'password' => $installData['db_pass']); $hostParts = explode(':', $installData['db_host']); if (count($hostParts) == 2) { $dbConfiguration['host'] = $hostParts[0]; $dbConfiguration['port'] = $hostParts[1]; } if ($installData['db_driver'] == 'pdo_mysql') { $dbConfiguration['dbname'] = ''; } if ($installData['db_driver'] == 'pdo_oci') { $dbConfiguration['wrapperClass'] = 'Doctrine\\DBAL\\Portability\\Connection'; $dbConfiguration['portability'] = \Doctrine\DBAL\Portability\Connection::PORTABILITY_ALL; $dbConfiguration['fetch_case'] = PDO::CASE_LOWER; } $dbCreator = new tao_install_utils_DbalDbCreator($dbConfiguration); $this->log('d', "DbCreator spawned", 'INSTALL'); /* * 3 - Load the database schema */ // If the database already exists, drop all tables if ($dbCreator->dbExists($dbName)) { try { //If the target Sgbd is mysql select the database after creating it if ($installData['db_driver'] == 'pdo_mysql') { $dbCreator->setDatabase($installData['db_name']); } $dbCreator->cleanDb($dbName); } catch (Exception $e) { $this->log('i', 'Problem cleaning db will try to erase the whole db: ' . $e->getMessage()); try { $dbCreator->destroyTaoDatabase($dbName); } catch (Exception $e) { $this->log('i', 'isssue during db cleaning : ' . $e->getMessage()); } } $this->log('i', "Dropped all tables", 'INSTALL'); } else { try { $dbCreator->createDatabase($installData['db_name']); $this->log('i', "Created database " . $installData['db_name'], 'INSTALL'); } catch (Exception $e) { throw new tao_install_utils_Exception('Unable to create the database, make sure that ' . $installData['db_user'] . ' is granted to create databases. Otherwise create the database with your super user and give to ' . $installData['db_user'] . ' the right to use it.'); } //If the target Sgbd is mysql select the database after creating it if ($installData['db_driver'] == 'pdo_mysql') { $dbCreator->setDatabase($installData['db_name']); } } // reset db name for mysql if ($installData['db_driver'] == 'pdo_mysql') { $dbConfiguration['dbname'] = $installData['db_name']; } // Create tao tables $dbCreator->initTaoDataBase(); $this->log('i', 'Created tables', 'INSTALL'); $storedProcedureFile = $this->options['install_path'] . 'db/tao_stored_procedures_' . str_replace('pdo_', '', $installData['db_driver']) . '.sql'; if (file_exists($storedProcedureFile) && is_readable($storedProcedureFile)) { $this->log('i', 'Installing stored procedures for ' . $installData['db_driver'], 'INSTALL'); $dbCreator->loadProc($storedProcedureFile); } else { $this->log('e', 'Could not find storefile : ' . $storedProcedureFile); } /* * 4 - Create the local namespace */ // $this->log('i', 'Creating local namespace', 'INSTALL'); // $dbCreator->addLocalModel('8',$installData['module_namespace']); // $dbCreator->addModels(); /* * 5 - Create the generis config files */ $this->log('d', 'Removing old config', 'INSTALL'); if (!helpers_File::emptyDirectory($this->options['root_path'] . 'config/', true)) { throw new common_exception_Error('Unable to empty ' . $this->options['root_path'] . 'config/ folder.'); } $this->log('d', 'Writing generis config', 'INSTALL'); $generisConfigWriter = new tao_install_utils_ConfigWriter($this->options['root_path'] . 'generis/config/sample/generis.conf.php', $this->options['root_path'] . 'config/generis.conf.php'); $generisConfigWriter->createConfig(); $generisConfigWriter->writeConstants(array('LOCAL_NAMESPACE' => $installData['module_namespace'], 'GENERIS_INSTANCE_NAME' => $installData['instance_name'], 'GENERIS_SESSION_NAME' => self::generateSessionName(), 'ROOT_PATH' => $this->options['root_path'], 'FILES_PATH' => $installData['file_path'], 'ROOT_URL' => $installData['module_url'], 'DEFAULT_LANG' => $installData['module_lang'], 'DEBUG_MODE' => $installData['module_mode'] == 'debug' ? true : false, 'TIME_ZONE' => $installData['timezone'])); /* * 5b - Prepare the file/cache folder (FILES_PATH) not yet defined) * @todo solve this more elegantly */ $file_path = $installData['file_path']; if (is_dir($file_path)) { $this->log('i', 'Data from previous install found and will be removed'); if (!helpers_File::emptyDirectory($installData['file_path'], true)) { throw new common_exception_Error('Unable to empty ' . $installData['file_path'] . ' folder.'); } } else { mkdir($installData['file_path'], 0700, true); } $cachePath = $installData['file_path'] . 'generis' . DIRECTORY_SEPARATOR . 'cache'; mkdir($cachePath, 0700, true); /* * 6 - Run the extensions bootstrap */ $this->log('d', 'Running the extensions bootstrap', 'INSTALL'); require_once $this->options['root_path'] . 'generis/common/inc.extension.php'; /* * 6b - Create cache persistence */ common_persistence_Manager::addPersistence('cache', array('driver' => 'phpfile')); common_persistence_KeyValuePersistence::getPersistence('cache')->purge(); /* * 6c - Create generis persistence */ common_persistence_Manager::addPersistence('default', $dbConfiguration); /* * 6d - Create generis user */ // Init model creator and create the Generis User. $modelCreator = new tao_install_utils_ModelCreator(LOCAL_NAMESPACE); $modelCreator->insertGenerisUser(helpers_Random::generateString(8)); /* * 7 - Add languages */ $models = $modelCreator->getLanguageModels(); foreach ($models as $ns => $modelFiles) { foreach ($modelFiles as $file) { $this->log('d', "Inserting language description model '" . $file . "'", 'INSTALL'); $modelCreator->insertLocalModel($file); } } /* * 8 - Finish Generis Install */ $generis = common_ext_ExtensionsManager::singleton()->getExtensionById('generis'); $generisInstaller = new common_ext_GenerisInstaller($generis); $generisInstaller->install(); /* * 9 - Install the extensions */ $toInstall = array(); foreach ($extensionIDs as $id) { try { $ext = common_ext_ExtensionsManager::singleton()->getExtensionById($id); if (!common_ext_ExtensionsManager::singleton()->isInstalled($ext->getId())) { $this->log('d', 'Extension ' . $id . ' needs to be installed'); $toInstall[$id] = $ext; } } catch (common_ext_ExtensionException $e) { $this->log('w', 'Extension ' . $id . ' not found'); } } while (!empty($toInstall)) { $modified = false; foreach ($toInstall as $key => $extension) { // if all dependencies are installed $this->log('d', 'Considering extension ' . $key); $installed = array_keys(common_ext_extensionsmanager::singleton()->getinstalledextensions()); $missing = array_diff(array_keys($extension->getDependencies()), $installed); if (count($missing) == 0) { try { $importLocalData = $installData['import_local'] == true; $extinstaller = new tao_install_ExtensionInstaller($extension, $importLocalData); set_time_limit(300); $extinstaller->install(); $this->log('ext', $key); $this->log('i', 'Extension ' . $key . ' installed'); } catch (common_ext_ExtensionException $e) { $this->log('w', 'Exception(' . $e->getMessage() . ') during install for extension "' . $extension->getId() . '"'); throw new tao_install_utils_Exception("An error occured during the installation of extension '" . $extension->getId() . "'."); } unset($toInstall[$key]); $modified = true; } else { $missing = array_diff($missing, array_keys($toInstall)); foreach ($missing as $extID) { $this->log('d', 'Extension ' . $extID . ' is required but missing, added to install list'); $toInstall[$extID] = common_ext_ExtensionsManager::singleton()->getExtensionById($extID); $modified = true; } } } // no extension could be installed, and no new requirements was added if (!$modified) { throw new common_exception_Error('Unfulfilable/Cyclic reference found in extensions'); } } /* * 9bis - Generates client side translation bundles (depends on extension install) */ $this->log('i', 'Generates client side translation bundles', 'INSTALL'); // $files = tao_models_classes_LanguageService::singleton()->generateClientBundles(); /* * 10 - Insert Super User */ $this->log('i', 'Spawning SuperUser ' . $installData['user_login'], 'INSTALL'); $modelCreator->insertSuperUser(array('login' => $installData['user_login'], 'password' => core_kernel_users_Service::getPasswordHash()->encrypt($installData['user_pass1']), 'userLastName' => $installData['user_lastname'], 'userFirstName' => $installData['user_firstname'], 'userMail' => $installData['user_email'], 'userDefLg' => 'http://www.tao.lu/Ontologies/TAO.rdf#Lang' . $installData['module_lang'], 'userUILg' => 'http://www.tao.lu/Ontologies/TAO.rdf#Lang' . $installData['module_lang'], 'userTimezone' => TIME_ZONE)); /* * 11 - Secure the install for production mode */ if ($installData['module_mode'] == 'production') { $extensions = common_ext_ExtensionsManager::singleton()->getInstalledExtensions(); $this->log('i', 'Securing tao for production', 'INSTALL'); // 11.1 Remove Generis User $dbCreator->removeGenerisUser(); // 11.2 Protect TAO dist $shield = new tao_install_utils_Shield(array_keys($extensions)); $shield->disableRewritePattern(array("!/test/", "!/doc/")); $shield->denyAccessTo(array('views/sass', 'views/js/test', 'views/build')); $shield->protectInstall(); } /* * 12 - Create the version file */ $this->log('d', 'Creating TAO version file', 'INSTALL'); file_put_contents($installData['file_path'] . 'version', TAO_VERSION); } catch (Exception $e) { if ($this->retryInstallation($e)) { return; } // In any case, we transmit a single exception type (at the moment) // for a clearer API for client code. $this->log('e', 'Error Occurs : ' . $e->getMessage() . $e->getTraceAsString(), 'INSTALL'); throw new tao_install_utils_Exception($e->getMessage(), 0, $e); } }
/** * Unnatach a Role from a given TAO User. * * @access public * @author Jerome Bogaerts, <*****@*****.**> * @param Resource user A TAO user from which you want to unnattach the Role. * @param Resource role The Role you want to Unnatach from the TAO User. * @throws core_kernel_users_Exception If an error occurs. */ public function unnatachRole(core_kernel_classes_Resource $user, core_kernel_classes_Resource $role) { $this->generisUserService->unnatachRole($user, $role); }
<?php /** * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; under version 2 * of the License (non-upgradable). * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * Copyright (c) 2015 (original work) Open Assessment Technologies SA; * * */ require_once dirname(__FILE__) . '/../includes/raw_start.php'; $user = new core_kernel_classes_Resource(LOCAL_NAMESPACE . DEFAULT_USER_URI_SUFFIX); $login = $user->getUniquePropertyValue(new core_kernel_classes_Property(PROPERTY_USER_LOGIN)); $password = readline("Enter new password for user '" . $login . "': "); $success = false; if (!empty($password)) { $hash = core_kernel_users_Service::getPasswordHash(); $success = $user->editPropertyValues(new core_kernel_classes_Property(PROPERTY_USER_PASSWORD), $hash->encrypt($password)); } die($success ? 0 : 1);
/** * Wrapper for password hash * * @param string $value * @return string */ public static function taoSubjectsPasswordEncode($value) { return \core_kernel_users_Service::getPasswordHash()->encrypt($value); }
/** * 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'); }
/** * 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'))); $this->checkUser($user->getUri()); $types = $user->getTypes(); $myFormContainer = new tao_actions_form_Users(reset($types), $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->getEventManager()->trigger(new UserUpdatedEvent($user, $values)); $this->setData('message', __('User saved')); } } } $this->setData('formTitle', __('Edit a user')); $this->setData('myForm', $myForm->render()); $this->setView('user/form.tpl'); }
/** * (non-PHPdoc) * @see common_user_auth_Adapter::authenticate() */ public function authenticate() { $userClass = new core_kernel_classes_Class(CLASS_GENERIS_USER); $filters = array(PROPERTY_USER_LOGIN => $this->username); $options = array('like' => false, 'recursive' => true); $users = $userClass->searchInstances($filters, $options); if (count($users) > 1) { // Multiple users matching throw new common_exception_InconsistentData("Multiple Users found with the same login '" . $this->username . "'."); } if (empty($users)) { // fake code execution to prevent timing attacks $label = new core_kernel_classes_Property(RDFS_LABEL); $hash = $label->getUniquePropertyValue($label); if (!core_kernel_users_Service::getPasswordHash()->verify($this->password, $hash)) { throw new core_kernel_users_InvalidLoginException(); } // should never happen, added for integrity throw new core_kernel_users_InvalidLoginException(); } $userResource = current($users); $hash = $userResource->getUniquePropertyValue(new core_kernel_classes_Property(PROPERTY_USER_PASSWORD)); if (!core_kernel_users_Service::getPasswordHash()->verify($this->password, $hash)) { throw new core_kernel_users_InvalidLoginException(); } return new core_kernel_users_GenerisUser($userResource); }
/** * Get a unique instance of the UserService. * * @access public * @author Jerome Bogaerts, <*****@*****.**> * @return core_kernel_users_Service */ public static function singleton() { $returnValue = null; if (!isset(self::$instance)) { $c = __CLASS__; self::$instance = new $c(); } $returnValue = self::$instance; return $returnValue; }
/** * Returns the proctor creation form */ public function createProctorForm() { $myFormContainer = new AddProctor(); $myForm = $myFormContainer->getForm(); $valid = false; $created = false; $form = ''; if ($myForm->isSubmited()) { $valid = $myForm->isValid(); if ($valid) { $values = $myForm->getValues(); $values[PROPERTY_USER_PASSWORD] = \core_kernel_users_Service::getPasswordHash()->encrypt($values['password1']); unset($values['password1']); unset($values['password2']); //force the new user role to be proctorRole $values[PROPERTY_USER_ROLES] = array('http://www.tao.lu/Ontologies/TAOProctor.rdf#ProctorRole'); //@todo use a constant instead $proctor = $myFormContainer->getUser(); $binder = new \tao_models_classes_dataBinding_GenerisFormDataBinder($proctor); $created = $binder->bind($values); if ($created) { //assign then authorize the new proctor to the selected test centers ProctorManagementService::singleton()->assignProctors(array($proctor->getUri()), SessionManager::getSession()->getUserUri()); $testCenters = $this->getRequestTestCenters(); if (!empty($testCenters)) { ProctorManagementService::singleton()->authorizeProctors(array($proctor->getUri()), $testCenters); } } } else { $form = $myForm->render(); } } else { $form = $myForm->render(); } $this->returnJson(array('form' => $form, 'valid' => $valid, 'created' => $created, 'loginId' => tao_helpers_Uri::encode(PROPERTY_USER_LOGIN), 'debug' => array('values' => $myForm->getValues()))); }
/** * Short description of method logOut * * @access public * @author Bertrand Chevrier, <*****@*****.**> * @return boolean */ public function logOut() { $returnValue = (bool) false; core_kernel_users_Service::singleton()->logout(); return (bool) $returnValue; }
/** * @depends testCreateTestTaker */ public function testUpdateTestTaker($uriSubject) { // modifying the login of a subject is not allowed : 412 $returnedData = $this->curl($this->getUrl(), CURLOPT_PUT, CURLINFO_HTTP_CODE, array('uri: ' . $uriSubject, 'login: blabla')); $this->assertEquals($returnedData, 412); // modifying the password of a subject is allowed : 200 $returnedData = $this->curl($this->getUrl(), CURLOPT_PUT, CURLINFO_HTTP_CODE, array('uri: ' . $uriSubject, 'password: blabla')); $this->assertEquals($returnedData, 200); // edit this test taker $returnedData = $this->curl($this->getUrl(), CURLOPT_PUT, "data", array('uri: ' . $uriSubject, 'firstName: patrick', 'password: blabla')); $returnedData = $this->curl($this->getUrl(), CURLOPT_HTTPGET, "data", array('uri: ' . $uriSubject)); $data = json_decode($returnedData, true); $this->assertEquals($data["success"], true); $this->assertEquals($data["data"]["uri"], $uriSubject); $this->checkPropertyValues($data["data"]["properties"], PROPERTY_USER_LOGIN, "literal", 'dummy_login'); foreach ($data["data"]["properties"] as $propertyValue) { if ($propertyValue["predicateUri"] == PROPERTY_USER_PASSWORD) { $this->assertTrue(\core_kernel_users_Service::getPasswordHash()->verify('blabla', $propertyValue["values"][0]["value"])); } } $this->checkPropertyValues($data["data"]["properties"], PROPERTY_USER_LASTNAME, "literal", 'patrick'); }