‪TYPO3CMS  11.5
BackendUserSessionRepository.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
24 
29 {
31 
32  public function ‪__construct()
33  {
34  $this->sessionBackend = GeneralUtility::makeInstance(SessionManager::class)->getSessionBackend('BE');
35  }
36 
42  public function ‪findAllActive(): array
43  {
44  $allSessions = $this->sessionBackend->getAll();
45 
46  // Map array to correct keys
47  $allSessions = array_map(
48  static function ($session) {
49  return [
50  'id' => $session['ses_id'], // this is the hashed sessionId
51  'ip' => $session['ses_iplock'],
52  'timestamp' => $session['ses_tstamp'],
53  'ses_userid' => $session['ses_userid'],
54  ];
55  },
56  $allSessions
57  );
58 
59  // Sort by timestamp
60  usort($allSessions, static function ($session1, $session2) {
61  return $session1['timestamp'] <=> $session2['timestamp'];
62  });
63 
64  return $allSessions;
65  }
66 
73  public function ‪findByBackendUser(‪BackendUser $backendUser)
74  {
75  $allActive = $this->‪findAllActive();
76 
77  return array_filter(
78  $allActive,
79  static function ($session) use ($backendUser) {
80  return (int)$session['ses_userid'] === $backendUser->‪getUid();
81  }
82  );
83  }
84 
86  {
87  $currentSessionId = $userObject->‪getSession()->‪getIdentifier();
88  if ($this->sessionBackend instanceof ‪HashableSessionBackendInterface) {
89  $currentSessionId = $this->sessionBackend->hash($currentSessionId);
90  }
91  return $currentSessionId;
92  }
93 
94  public function ‪terminateSessionByIdentifier(string $sessionIdentifier): bool
95  {
96  return $this->sessionBackend->remove($sessionIdentifier);
97  }
98 }
‪TYPO3\CMS\Core\Authentication\AbstractUserAuthentication\getSession
‪UserSession getSession()
Definition: AbstractUserAuthentication.php:1322
‪TYPO3\CMS\Extbase\DomainObject\AbstractDomainObject\getUid
‪int null getUid()
Definition: AbstractDomainObject.php:67
‪TYPO3\CMS\Core\Session\UserSession\getIdentifier
‪string getIdentifier()
Definition: UserSession.php:63
‪TYPO3\CMS\Core\Session\SessionManager
Definition: SessionManager.php:39
‪TYPO3\CMS\Core\Session\Backend\HashableSessionBackendInterface
Definition: HashableSessionBackendInterface.php:21
‪TYPO3\CMS\Beuser\Domain\Repository\BackendUserSessionRepository\findAllActive
‪array findAllActive()
Definition: BackendUserSessionRepository.php:42
‪TYPO3\CMS\Beuser\Domain\Repository\BackendUserSessionRepository
Definition: BackendUserSessionRepository.php:29
‪TYPO3\CMS\Beuser\Domain\Repository
Definition: BackendUserGroupRepository.php:16
‪TYPO3\CMS\Core\Session\Backend\SessionBackendInterface
Definition: SessionBackendInterface.php:28
‪TYPO3\CMS\Beuser\Domain\Repository\BackendUserSessionRepository\terminateSessionByIdentifier
‪terminateSessionByIdentifier(string $sessionIdentifier)
Definition: BackendUserSessionRepository.php:94
‪TYPO3\CMS\Beuser\Domain\Repository\BackendUserSessionRepository\__construct
‪__construct()
Definition: BackendUserSessionRepository.php:32
‪TYPO3\CMS\Beuser\Domain\Model\BackendUser
Definition: BackendUser.php:30
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\Beuser\Domain\Repository\BackendUserSessionRepository\findByBackendUser
‪array findByBackendUser(BackendUser $backendUser)
Definition: BackendUserSessionRepository.php:73
‪TYPO3\CMS\Beuser\Domain\Repository\BackendUserSessionRepository\$sessionBackend
‪SessionBackendInterface $sessionBackend
Definition: BackendUserSessionRepository.php:30
‪TYPO3\CMS\Core\Authentication\AbstractUserAuthentication
Definition: AbstractUserAuthentication.php:56
‪TYPO3\CMS\Beuser\Domain\Repository\BackendUserSessionRepository\getPersistedSessionIdentifier
‪getPersistedSessionIdentifier(AbstractUserAuthentication $userObject)
Definition: BackendUserSessionRepository.php:85