‪TYPO3CMS  10.4
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 
30 {
36  public function ‪findAllActive()
37  {
38  $sessionBackend = $this->‪getSessionBackend();
39  $allSessions = $sessionBackend->getAll();
40 
41  // Map array to correct keys
42  $allSessions = array_map(
43  function ($session) {
44  return [
45  'id' => $session['ses_id'], // this is the hashed sessionId
46  'ip' => $session['ses_iplock'],
47  'timestamp' => $session['ses_tstamp'],
48  'ses_userid' => $session['ses_userid']
49  ];
50  },
51  $allSessions
52  );
53 
54  // Sort by timestamp
55  usort($allSessions, function ($session1, $session2) {
56  return $session1['timestamp'] <=> $session2['timestamp'];
57  });
58 
59  return $allSessions;
60  }
61 
68  public function ‪findByBackendUser(‪BackendUser $backendUser)
69  {
70  $allActive = $this->‪findAllActive();
71 
72  return array_filter(
73  $allActive,
74  function ($session) use ($backendUser) {
75  return (int)$session['ses_userid'] === $backendUser->‪getUid();
76  }
77  );
78  }
79 
86  {
87  $sessionBackend = $this->‪getSessionBackend();
88  $sessionId = $this->‪getBackendSessionId();
89  $sessionBackend->update(
90  $sessionId,
91  [
92  'ses_userid' => $authentication->user['ses_backuserid'],
93  'ses_backuserid' => 0
94  ]
95  );
96  }
97 
101  protected function ‪getBackendSessionId(): string
102  {
103  return ‪$GLOBALS['BE_USER']->id;
104  }
105 
110  {
111  return GeneralUtility::makeInstance(SessionManager::class)->getSessionBackend('BE');
112  }
113 }
‪TYPO3\CMS\Extbase\DomainObject\AbstractDomainObject\getUid
‪int null getUid()
Definition: AbstractDomainObject.php:67
‪TYPO3\CMS\Beuser\Domain\Repository\BackendUserSessionRepository\getSessionBackend
‪SessionBackendInterface getSessionBackend()
Definition: BackendUserSessionRepository.php:109
‪TYPO3\CMS\Core\Session\SessionManager
Definition: SessionManager.php:39
‪TYPO3\CMS\Beuser\Domain\Repository\BackendUserSessionRepository\findAllActive
‪array findAllActive()
Definition: BackendUserSessionRepository.php:36
‪TYPO3\CMS\Beuser\Domain\Repository\BackendUserSessionRepository
Definition: BackendUserSessionRepository.php:30
‪TYPO3\CMS\Beuser\Domain\Repository
Definition: BackendUserGroupRepository.php:16
‪TYPO3\CMS\Core\Session\Backend\SessionBackendInterface
Definition: SessionBackendInterface.php:28
‪TYPO3\CMS\Extbase\Persistence\Repository
Definition: Repository.php:29
‪TYPO3\CMS\Beuser\Domain\Repository\BackendUserSessionRepository\switchBackToOriginalUser
‪switchBackToOriginalUser(AbstractUserAuthentication $authentication)
Definition: BackendUserSessionRepository.php:85
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Beuser\Domain\Model\BackendUser
Definition: BackendUser.php:26
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Beuser\Domain\Repository\BackendUserSessionRepository\findByBackendUser
‪array findByBackendUser(BackendUser $backendUser)
Definition: BackendUserSessionRepository.php:68
‪TYPO3\CMS\Beuser\Domain\Repository\BackendUserSessionRepository\getBackendSessionId
‪string getBackendSessionId()
Definition: BackendUserSessionRepository.php:101
‪TYPO3\CMS\Core\Authentication\AbstractUserAuthentication
Definition: AbstractUserAuthentication.php:51