sessionBackend = GeneralUtility::makeInstance(SessionManager::class)->getSessionBackend('BE'); } /** * Find all active sessions for all backend users */ public function findAllActive(): array { $allSessions = $this->sessionBackend->getAll(); // Map array to correct keys $allSessions = array_map( static function (array $session): array { return [ 'id' => $session['ses_id'], // this is the hashed sessionId 'ip' => $session['ses_iplock'], 'timestamp' => $session['ses_tstamp'], 'ses_userid' => $session['ses_userid'], ]; }, $allSessions ); // Sort by timestamp usort($allSessions, static function ($session1, $session2) { return $session1['timestamp'] <=> $session2['timestamp']; }); return $allSessions; } /** * Find Sessions for specific BackendUser */ public function findByBackendUser(BackendUser $backendUser): array { $allActive = $this->findAllActive(); return array_filter( $allActive, static function (array $session) use ($backendUser): bool { return (int)$session['ses_userid'] === $backendUser->getUid(); } ); } public function getPersistedSessionIdentifier(AbstractUserAuthentication $userObject): string { $currentSessionId = $userObject->getSession()->getIdentifier(); if ($this->sessionBackend instanceof HashableSessionBackendInterface) { $currentSessionId = $this->sessionBackend->hash($currentSessionId); } return $currentSessionId; } public function terminateSessionByIdentifier(string $sessionIdentifier): bool { return $this->sessionBackend->remove($sessionIdentifier); } }