/** * Singleton implementation * @return PHPSession */ public static function singleton() { if (is_null(self::$instance)) { self::$instance = new self(); } return self::$instance; }
/** * Save a context in the current activity execution */ public function save() { $session = PHPSession::singleton(); if (!$session->hasAttribute('activityExecutionUri')) { throw new common_exception_Error('missing activityExecutionUri in Session during RecoveryContext::retrieve()'); } if (!$this->hasRequestParameter('context')) { throw new common_exception_MissingParameter('context'); } $saved = false; $activityExecutionUri = $session->getAttribute('activityExecutionUri'); if (!empty($activityExecutionUri)) { $activityExecution = new core_kernel_classes_Resource($activityExecutionUri); $recoveryService = wfEngine_models_classes_RecoveryService::singleton(); $context = $this->getRequestParameter('context'); if (is_array($context)) { if (count($context) > 0) { $saved = $recoveryService->saveContext($activityExecution, $context); } } else { if (is_null($context) || $context == 'null') { //if the data sent are null [set context to null], we remove it $saved = $recoveryService->removeContext($activityExecution); } } } echo json_encode(array('saved' => $saved)); }
/** * Starts a new session and stores it in the session if stateful * * @param common_session_Session $session * @return boolean */ public static function startSession(common_session_Session $session) { self::$session = $session; // do not start session in cli mode (testcase script) if (PHP_SAPI != 'cli') { if ($session instanceof common_session_StatefulSession) { // start session if not yet started if (session_id() === '') { session_name(GENERIS_SESSION_NAME); session_start(); } else { // prevent session fixation. session_regenerate_id(); } PHPSession::singleton()->setAttribute(self::PHPSESSION_SESSION_KEY, $session); } } return true; }
/** * * @author Lionel Lecaque, lionel@taotesting.com * */ public function testSpawnResultDelivery() { //init the resultserver $this->service->initResultServer('http://www.tao.lu/Ontologies/TAOResultServer.rdf#void'); //no result id given will take run the spawnResult of storage interface $this->service->spawnResult('testcase_deliveryexecId'); $resultServer_deliveryResultIdentifier = \PHPSession::singleton()->getAttribute("resultServer_deliveryResultIdentifier"); $resultServer_deliveryExecutionIdentifier = \PHPSession::singleton()->getAttribute("resultServer_deliveryExecutionIdentifier"); $this->assertNull($resultServer_deliveryResultIdentifier); $this->assertEquals('testcase_deliveryexecId', $resultServer_deliveryExecutionIdentifier); //provide both identifier $this->service->spawnResult('testcase_deliveryexecId', 'testcase_deliveryresultId'); $resultServer_deliveryResultIdentifier = \PHPSession::singleton()->getAttribute("resultServer_deliveryResultIdentifier"); $resultServer_deliveryExecutionIdentifier = \PHPSession::singleton()->getAttribute("resultServer_deliveryExecutionIdentifier"); $this->assertEquals('testcase_deliveryresultId', $resultServer_deliveryResultIdentifier); $this->assertEquals('testcase_deliveryexecId', $resultServer_deliveryExecutionIdentifier); //provide no results identifier but will retrieve previous call $this->service->spawnResult('testcase_deliveryexecId'); $resultServer_deliveryResultIdentifier = \PHPSession::singleton()->getAttribute("resultServer_deliveryResultIdentifier"); $resultServer_deliveryExecutionIdentifier = \PHPSession::singleton()->getAttribute("resultServer_deliveryExecutionIdentifier"); $this->assertEquals('testcase_deliveryresultId', $resultServer_deliveryResultIdentifier); $this->assertEquals('testcase_deliveryexecId', $resultServer_deliveryExecutionIdentifier); }
/** * * @param type $test an identifier for the test uri rpeferred * @param taoResultServer_models_classes_Variable $testVariable * @param type $callIdTest a call test reference (distinguish test being embdded twice) * @return type */ public function storeTestVariable($test, taoResultServer_models_classes_Variable $testVariable, $callIdTest) { $resultServer = $this->restoreResultServer(); $resultServer->getStorageInterface()->storeTestVariable(PHPSession::singleton()->getAttribute("resultServer_deliveryResultIdentifier"), $test, $testVariable, $callIdTest); return PHPSession::singleton()->getAttribute("resultServer_deliveryResultIdentifier"); }
/** * Create or retrieve the current activity execution of a process execution * a given activity definition and a user * * @access public * @author Somsack Sipasseuth, <*****@*****.**> * @param Resource processExecution * @param Resource activityExecution * @param Resource user * @param boolean bypassACL * @return core_kernel_classes_Resource */ public function initCurrentActivityExecution(core_kernel_classes_Resource $processExecution, core_kernel_classes_Resource $activityExecution, core_kernel_classes_Resource $user, $bypassACL = false) { $returnValue = null; if (!is_null($processExecution) && !is_null($activityExecution) && !is_null($user)) { $assignedUser = $this->activityExecutionService->getActivityExecutionUser($activityExecution); if (!is_null($assignedUser) && $assignedUser->getUri() == $user->getUri()) { $this->activityExecutionService->setStatus($activityExecution, 'resumed'); $returnValue = $activityExecution; } else { if ($bypassACL || $this->activityExecutionService->checkAcl($activityExecution, $user, $processExecution)) { //force assignation to the user: if ($this->activityExecutionService->setActivityExecutionUser($activityExecution, $user, true)) { $this->activityExecutionService->setStatus($activityExecution, 'started'); $returnValue = $activityExecution; } } } //set in the session the current activity uri if (!is_null($returnValue)) { //set time properties: $propStartedTime = new core_kernel_classes_Property(PROPERTY_ACTIVITY_EXECUTION_TIME_STARTED); $propLastTime = new core_kernel_classes_Property(PROPERTY_ACTIVITY_EXECUTION_TIME_LASTACCESS); if (is_null($activityExecution->getOnePropertyValue($propStartedTime))) { $activityExecution->setPropertyValue($propStartedTime, time()); } $activityExecution->editPropertyValues($propLastTime, time()); $session = PHPSession::singleton(); $session->setAttribute("activityExecutionUri", $returnValue->getUri()); //for variable service only? } } return $returnValue; }
/** * * @example http://tao-dev/taoResultServer/ResultServerStateFull/spawnResult * @return type */ public function spawnResult($deliveryExecutionIdentifier, $deliveryResultIdentifier = null) { if ($deliveryResultIdentifier == null) { $resultServer = $this->restoreResultServer(); if ($this->getValue("resultServer_deliveryExecutionIdentifier") !== null and $this->getValue("resultServer_deliveryExecutionIdentifier") == $deliveryExecutionIdentifier) { $resultServer_deliveryResultIdentifier = $this->getValue("resultServer_deliveryResultIdentifier"); } else { $resultServer_deliveryResultIdentifier = $resultServer->getStorageInterface()->spawnResult(); } } else { $resultServer_deliveryResultIdentifier = $deliveryResultIdentifier; } PHPSession::singleton()->setAttribute("resultServer_deliveryResultIdentifier", $resultServer_deliveryResultIdentifier); PHPSession::singleton()->setAttribute("resultServer_deliveryExecutionIdentifier", $deliveryExecutionIdentifier); return $resultServer_deliveryResultIdentifier; }
/** * 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; }
public function getSession() { return PHPSession::singleton(); }
/** * Short description of method _set * * @access private * @author Somsack Sipasseuth, <*****@*****.**> * @param string key * @param string value * @param Resource activityExecution * @param boolean edit * @return boolean */ private function _set($key, $value, core_kernel_classes_Resource $activityExecution = null, $edit = false) { $returnValue = (bool) false; $session = PHPSession::singleton(); if (is_null($activityExecution) && $session->hasAttribute("activityExecutionUri")) { $activityExecution = new core_kernel_classes_Resource($session->getAttribute("activityExecutionUri")); } if (!is_null($activityExecution)) { $allVars = unserialize($activityExecution->getOnePropertyValue($this->variablesProperty)); $processVariable = $this->getProcessVariable($key); if (!is_null($processVariable)) { $property = new core_kernel_classes_Property($processVariable->getUri()); if ($edit) { $returnValue &= $activityExecution->editPropertyValues($property, $value); } else { $returnValue &= $activityExecution->setPropertyValue($property, $value); } if (is_array($allVars)) { if (!array_search($key, $allVars)) { $allVars[] = $key; } } else { $allVars = array($key); } } $returnValue = $activityExecution->editPropertyValues($this->variablesProperty, serialize($allVars)); } return (bool) $returnValue; }
public function clearSession($global = true) { PHPSession::singleton()->clear($global); }
/** * Revokes the current CSRF token * @return void */ public function revokeCsrfToken() { $sessionId = $this->getSessionId(); $service = self::getExtendedStateService(); $service->resetSecurity($sessionId); \PHPSession::singleton()->setAttribute(self::TOKEN_KEY . $sessionId, $service->getSessionToken($sessionId)); }
/** * Revokes the current CSRF token * @return void */ public function revokeCsrfToken() { $session = \PHPSession::singleton(); $session->removeAttribute(self::TOKEN_KEY . $this->name); $session->removeAttribute(self::TIMESTAMP_KEY . $this->name); }