‪TYPO3CMS  ‪main
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 
40  public function ‪findAllActive(): array
41  {
42  $allSessions = $this->sessionBackend->getAll();
43 
44  // Map array to correct keys
45  $allSessions = array_map(
46  static function (array $session): array {
47  return [
48  'id' => $session['ses_id'], // this is the hashed sessionId
49  'ip' => $session['ses_iplock'],
50  'timestamp' => $session['ses_tstamp'],
51  'ses_userid' => $session['ses_userid'],
52  ];
53  },
54  $allSessions
55  );
56 
57  // Sort by timestamp
58  usort($allSessions, static function ($session1, $session2) {
59  return $session1['timestamp'] <=> $session2['timestamp'];
60  });
61 
62  return $allSessions;
63  }
64 
68  public function ‪findByBackendUser(‪BackendUser $backendUser): array
69  {
70  $allActive = $this->‪findAllActive();
71 
72  return array_filter(
73  $allActive,
74  static function (array $session) use ($backendUser): bool {
75  return (int)$session['ses_userid'] === $backendUser->‪getUid();
76  }
77  );
78  }
79 
81  {
82  $currentSessionId = $userObject->‪getSession()->getIdentifier();
83  if ($this->sessionBackend instanceof ‪HashableSessionBackendInterface) {
84  $currentSessionId = $this->sessionBackend->hash($currentSessionId);
85  }
86  return $currentSessionId;
87  }
88 
89  public function ‪terminateSessionByIdentifier(string $sessionIdentifier): bool
90  {
91  return $this->sessionBackend->remove($sessionIdentifier);
92  }
93 }
‪TYPO3\CMS\Beuser\Domain\Repository\BackendUserSessionRepository\findByBackendUser
‪findByBackendUser(BackendUser $backendUser)
Definition: BackendUserSessionRepository.php:68
‪TYPO3\CMS\Core\Session\SessionManager
Definition: SessionManager.php:41
‪TYPO3\CMS\Core\Session\Backend\HashableSessionBackendInterface
Definition: HashableSessionBackendInterface.php:21
‪TYPO3\CMS\Beuser\Domain\Repository\BackendUserSessionRepository
Definition: BackendUserSessionRepository.php:29
‪TYPO3\CMS\Beuser\Domain\Repository
Definition: BackendUserGroupRepository.php:16
‪TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface\getUid
‪getUid()
‪TYPO3\CMS\Core\Session\Backend\SessionBackendInterface
Definition: SessionBackendInterface.php:28
‪TYPO3\CMS\Core\Authentication\AbstractUserAuthentication\getSession
‪getSession()
Definition: AbstractUserAuthentication.php:1253
‪TYPO3\CMS\Beuser\Domain\Repository\BackendUserSessionRepository\terminateSessionByIdentifier
‪terminateSessionByIdentifier(string $sessionIdentifier)
Definition: BackendUserSessionRepository.php:89
‪TYPO3\CMS\Beuser\Domain\Repository\BackendUserSessionRepository\__construct
‪__construct()
Definition: BackendUserSessionRepository.php:32
‪TYPO3\CMS\Beuser\Domain\Model\BackendUser
Definition: BackendUser.php:32
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Beuser\Domain\Repository\BackendUserSessionRepository\$sessionBackend
‪SessionBackendInterface $sessionBackend
Definition: BackendUserSessionRepository.php:30
‪TYPO3\CMS\Core\Authentication\AbstractUserAuthentication
Definition: AbstractUserAuthentication.php:65
‪TYPO3\CMS\Beuser\Domain\Repository\BackendUserSessionRepository\getPersistedSessionIdentifier
‪getPersistedSessionIdentifier(AbstractUserAuthentication $userObject)
Definition: BackendUserSessionRepository.php:80
‪TYPO3\CMS\Beuser\Domain\Repository\BackendUserSessionRepository\findAllActive
‪findAllActive()
Definition: BackendUserSessionRepository.php:40