Exemple #1
0
 /**
  * Constructor performs initializations actions
  * @return void
  */
 public function __construct()
 {
     parent::__construct();
     $this->userService = tao_models_classes_UserService::singleton();
     $this->defaultData();
     $extManager = common_ext_ExtensionsManager::singleton();
 }
 /**
  *
  * @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;
 }
 /**
  * Constructor performs initializations actions
  */
 public function __construct()
 {
     //initialize user service
     $this->passwordRecoveryService = PasswordRecoveryService::singleton();
     $this->userService = \tao_models_classes_UserService::singleton();
     $this->defaultData();
 }
Exemple #4
0
 /**
  * Constructor performs initializations actions
  */
 public function __construct()
 {
     //initialize service
     $this->service = tao_models_classes_TaoService::singleton();
     $this->userService = \tao_models_classes_UserService::singleton();
     $this->defaultData();
 }
Exemple #5
0
 /**
  * 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]);
 }
Exemple #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;
 }
 /**
  * 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');
 }
Exemple #8
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();
 }
 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);
 }
 /**
  * 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;
     }
 }
 /**
  * Action dedicated to change the password of the user currently connected.
  */
 public function password()
 {
     $this->setData('formTitle', __("Change password"));
     if (helpers_PlatformInstance::isDemo()) {
         $this->setData('myForm', __('Unable to change passwords in demo mode'));
     } else {
         $myFormContainer = new tao_actions_form_UserPassword();
         $myForm = $myFormContainer->getForm();
         if ($myForm->isSubmited()) {
             if ($myForm->isValid()) {
                 $user = $this->userService->getCurrentUser();
                 tao_models_classes_UserService::singleton()->setPassword($user, $myForm->getValue('newpassword'));
                 $this->setData('message', __('Password changed'));
             }
         }
         $this->setData('myForm', $myForm->render());
     }
     $this->setView('form/settings_user.tpl');
 }
 /**
  * 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);
     }
 }
 /**
  * Implementation of the 'disable' action. When this action is called, a
  * Language Description ('language' param) is removed from the Knowledge
  * The language is at this time not available anymore to end-users. However,
  * Triples that had a corresponding language tag are not remove from the
  * If the language is enabled again via the 'enable' action of this script,
  * having corresponding languages will be reachable again.
  *
  * @access public
  * @author Joel Bout, <*****@*****.**>
  * @return void
  */
 public function actionDisable()
 {
     $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'] . "'.");
         $this->removeLanguageFromOntology();
         $userService->logout();
         $this->outVerbose("Disconnected from TAO.");
     } else {
         $this->err("Unable to connect to TAO as '" . $this->options['user'] . "'. Please check user name and password.", true);
     }
 }
Exemple #15
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()));
     }
 }
 /**
  * @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()];
 }
 /**
  * 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;
 }
 /**
  * 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;
 }
Exemple #19
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;
 }
 /**
  * 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));
 }
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');
Exemple #22
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);
         }
     }
 }
Exemple #23
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.");
         }
     }
 }
 /**
  * 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');
 }
 /**
  * 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));
 }
 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);
 }
 /**
  * get the list of users
  * @param array $resourceIds
  * @return array key => value with key = user Uri and value = user Label
  */
 protected function getUserList()
 {
     $userService = \tao_models_classes_UserService::singleton();
     $users = array();
     foreach ($userService->getAllUsers() as $user) {
         $users[$user->getUri()] = _dh($user->getLabel());
     }
     return $users;
 }
 /**
  * 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;
 }
 /**
  * initialize the services
  */
 public function __construct()
 {
     parent::__construct();
     $this->userService = \tao_models_classes_UserService::singleton();
 }
Exemple #30
0
 /**
  * create an execution environnement only for the authentication
  * @return array the executionEnvironment
  */
 public static function createAuthEnvironment()
 {
     $context = Context::getInstance();
     $session = PHPSession::singleton();
     if (strtolower($context->getActionName()) == 'createauthenvironment') {
         throw new Exception('Action denied, only servers side call are allowed');
     }
     if (!$session->hasAttribute('processUri')) {
         throw new Exception('Envirnoment can be create only in a workflow context');
     }
     $processExecution = new core_kernel_classes_Resource(tao_helpers_Uri::decode($session->getAttribute('processUri')));
     $userService = tao_models_classes_UserService::singleton();
     $user = $userService->getCurrentUser();
     if (is_null($user)) {
         throw new Exception('No user is logged in');
     }
     $sessionKey = self::ENV_VAR_NAME . '_' . tao_helpers_Uri::encode($user->getUri());
     if ($session->hasAttribute($sessionKey)) {
         $executionEnvironment = $session->getAttribute($sessionKey);
         if (isset($executionEnvironment['token']) && $executionEnvironment[CLASS_PROCESS_EXECUTIONS]['uri'] == $processExecution->getUri()) {
             return $executionEnvironment;
         }
     }
     $executionEnvironment = array('token' => self::createToken(), CLASS_PROCESS_EXECUTIONS => array('uri' => $processExecution->getUri(), RDFS_LABEL => $processExecution->getLabel()), TAO_SUBJECT_CLASS => array('uri' => $user->getUri(), RDFS_LABEL => $user->getLabel(), PROPERTY_USER_LOGIN => (string) $user->getOnePropertyValue(new core_kernel_classes_Property(PROPERTY_USER_LOGIN)), PROPERTY_USER_FIRSTNAME => (string) $user->getOnePropertyValue(new core_kernel_classes_Property(PROPERTY_USER_FIRSTNAME)), PROPERTY_USER_LASTNAME => (string) $user->getOnePropertyValue(new core_kernel_classes_Property(PROPERTY_USER_LASTNAME))));
     $session->setAttribute($sessionKey, $executionEnvironment);
     return $executionEnvironment;
 }