Touch a session to refresh the last active timestamp

POST /sso/session/xyz-123/touch

@param string $sessionId The session id
974988
public function touchAction($sessionId) {
		if ($this->request->getHttpRequest()->getMethod() !== 'POST') {
			$this->response->setStatus(405);
			$this->response->setHeader('Allow', 'POST');
			return;
		}

		$session = $this->sessionManager->getSession($sessionId);
		if ($session !== NULL) {
			$session->touch();

			if ($this->ssoLogger !== NULL) {
				$this->ssoLogger->log('Touched session "' . $sessionId . '"' , LOG_DEBUG);
			}

			$this->view->assign('value', array('success' => TRUE));
		} else {
			$this->response->setStatus(404);

			$this->view->assign('value', array('error' => 'SessionNotFound'));
		}
	}
968347
public function refreshSessionAction($sessionId, Request $request)
    {
        $session = $request->getSession();

        if ($session === null || !$session->isStarted() || $session->getId() != $sessionId || !$this->hasStoredCsrfToken()) {
            $response = $this->authenticator->logout($request);
            $response->setStatusCode(404);

            return $response;
        }

        $this->checkCsrfToken($request);

        return new Values\UserSession(
            $this->repository->getCurrentUser(),
            $session->getName(),
            $session->getId(),
            $request->headers->get('X-CSRF-Token'),
            false
        );
    }
21243
public function read($sessionId)
    {
        $sql = "SELECT {$this->options['data_col']} 
 FROM {$this->options['table']} 
 WHERE {$this->options['id_col']} = :id";

        try {
            $stmt = $this->db->prepare($sql);

            $stmt->bindParam(':id', $sessionId, \PDO::PARAM_STR);

            $stmt->execute();

            // We use fetchAll instead of fetchColumn to make sure the DB cursor gets closed
            $sessionRows = $stmt->fetchAll(\PDO::FETCH_NUM);

            if ($sessionRows) {
                return base64_decode($sessionRows[0][0]);
            }

            return '';
        } catch (\PDOException $e) {
            throw new \RuntimeException(
                sprintf(
                    'PDOException was thrown when trying to read the session data: %s',
                    $e->getMessage()
                ),
                0,
                $e
            );
        }
    }
583684
public function start(string $sessionID = null)
    {
        if($this->isStart)
        {
            throw new \RuntimeException('Session can not repeated start');
        }
        $this->handler = RequestContext::getServerBean($this->handlerClass);
        $this->isNewSession = null === $sessionID;
        if($this->isNewSession)
        {
            $this->id = $this->handler->createSessionID();
        }
        else
        {
            $this->id = $sessionID;
            $this->data = $this->handler->decode($this->handler->read($this->id));
        }
        $this->isStart = true;
    }
655890
public function session_write($sessionId, $sessionData)
    {
        $sessionData       = (!$sessionData || !is_array($sessionData)) ? [] : $sessionData;
        $this->sessionData = (!$this->sessionData) ? [] : $this->sessionData;

        $this->sessionData = array_merge($sessionData, $this->sessionData);
        $this->engine->set($this->sessionKey . $sessionId, $this->sessionData, $this->sessionLifeTime);

        return true;
    }
1285306
public function session_read($sessionId)
    {
        // assign the current session id
        $this->sessionId   = (string)$sessionId;
        $this->sessionData = $this->engine->get($this->sessionKey . $sessionId);
        // if the sessionData is "false" set it to be an array (casting would create an array with a false entry)
        if (!$this->sessionData) {
            $this->sessionData = [];
        }

        // session data is set uncompressed
        return $this->sessionData;
    }
637698
protected function doWrite($sessionId, $data): bool
    {
        $this->sessionDataProvider->setData($data);
        $this->getFacade()->setEx($this->prefix . $sessionId, $this->sessionDataProvider, 'ex', $this->ttl);

        return true;
    }
168553
public function read($sessionId)
    {
        $sessionId = $this->keyPrefix . $sessionId;
        $sessionData = $this->redis->get($sessionId);

        $this->redis->expire($sessionId, $this->maxLifetime);

        return $sessionData;
    }
544422
function touch()
    {
        if ($this->ID) {
            $this->db->query(
                "UPDATE ".$this->db->table_name('users', true).
                " SET `last_login` = ".$this->db->now().
                " WHERE `user_id` = ?",
                $this->ID);
        }
    }
1307751
protected function lockSession($sessionId)
    {
        $attempts = (1000000 / $this->spinLockWait) * $this->lockMaxWait;

        $this->token = uniqid();
        $this->lockKey = $this->getRedisKey($sessionId).'.lock';

        $setFunction = function ($redis, $key, $token, $ttl) {
            if ($redis instanceof \Redis) {
                return $redis->set(
                    $key,
                    $token,
                    array('NX', 'PX' => $ttl)
                );
            }

            return $redis->set(
                $key,
                $token,
                'PX',
                $ttl,
                'NX'
            );
        };

        for ($i = 0;$i < $attempts;++$i) {

            // We try to aquire the lock
            $success = $setFunction($this->redis, $this->lockKey, $this->token, $this->lockMaxWait * 1000 + 1);
            if ($success) {
                $this->locked = true;

                return true;
            }

            usleep($this->spinLockWait);
        }

        return false;
    }
894463
public function write($sessionID, $sessionData, $maxLifeTime)
    {
        PoolManager::use($this->poolName, function($resource, \Imi\Redis\RedisHandler $redis) use($sessionID, $sessionData, $maxLifeTime){
            $redis->set($this->getKey($sessionID), $sessionData, $maxLifeTime);
        });
    }
712806
public function session_read($session_id)
    {
        // Set empty result
        $this->session_data = (string)'';

        // Fetch session data from the selected database with the correct
        // timestamp
        $time       = (int)time();
        $session_id = mysql_real_escape_string($session_id);
        $sql        = (string)"SELECT `session_data` FROM `{$this->_db_name}`.`user_session` WHERE `session_id` = '$session_id' AND `expires` > $time";

        $session_res = $this->db->query((string)$sql);
        // if no session data exists return false
        if (empty($session_res)) return false;
        $this->session_data = $this->db->fetch_string($session_res);
        $this->db->free($session_res);

        // session data is set uncompressed
        return $this->session_data;
    }
258233
public function getAttemptsLeftWithSameSession(string $sessionId): int
    {
        $attemptsLeft = ((int) $this->maxAttemptsForSessionId) - $this->enhancedAuthenticationMapper->fetchAttemptsWithSameSession($sessionId, $this->banTimeInSeconds);

        return \max(0, $attemptsLeft);
    }
302994
function delete_session($sessionid) {
        try {
            $param = new \Panopto\SessionManagement\DeleteSessions($this->auth, array($sessionid));
            $this->smclient->DeleteSessions($param);
        } catch (Exception $e) {
            throw new SoapFault('client', $e->getMessage());
        }
        return true;
    }
628617
protected function lock($sessionId)
    {
        if (true === $this->isLocked) {
            return true;
        }

        $attempts = $this->lockMaxWait / $this->spinLockWait;
        $this->lockKey = $this->getSessionLockKey($sessionId);
        for ($i = 0; $i < $attempts; $i++) {
            if ($this->client->set($this->lockKey, 1, array('nx', 'ex' => $this->lockMaxWait / 1000000 + 1))) {
                return $this->isLocked = true;
            }
            usleep($this->spinLockWait);
        }

        if ($this->client->get($this->lockKey) && $this->client->ttl($this->lockKey) === -1) {
            throw new LockException(sprintf("Unable to lock session '%s' (lock ttl not set)", $this->lockKey));
        }

        throw new LockException(sprintf(
            "Unable to lock session '%s' (%d attempts, spinLockWait %d µs, total time %d µs)",
            $this->lockKey, $i, $this->spinLockWait, $i*$this->spinLockWait
        ));
    }
79292
public function destroy( $sessionId )
    {
        ezpEvent::getInstance()->notify( 'session/destroy', array( $sessionId ) );

        $db = eZDB::instance();
        $escKey = $db->escapeString( $sessionId );

        eZSession::triggerCallback( 'destroy_pre', array( $db, $sessionId, $escKey ) );
        $db->query( "DELETE FROM ezsession WHERE session_key='$escKey'" );
        eZSession::triggerCallback( 'destroy_post', array( $db, $sessionId, $escKey ) );

        return true;
    }
438643
public function touch()
    {
        if ($this->started !== true) {
            throw new Exception\SessionNotStartedException('Tried to touch a session, but the session has not been started yet.', 1354284318);
        }

        // Only makes sense for remote sessions because the currently active session
        // will be updated on shutdown anyway:
        if ($this->remote === true) {
            $this->lastActivityTimestamp = $this->now;
            $this->writeSessionMetaDataCacheEntry();
        }
    }