‪TYPO3CMS  9.5
BackendUserSessionRepository.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
23 
29 {
35  public function ‪findAllActive()
36  {
37  $sessionBackend = $this->‪getSessionBackend();
38  $allSessions = $sessionBackend->getAll();
39 
40  // Map array to correct keys
41  $allSessions = array_map(
42  function ($session) {
43  return [
44  'id' => $session['ses_id'], // this is the hashed sessionId
45  'ip' => $session['ses_iplock'],
46  'timestamp' => $session['ses_tstamp'],
47  'ses_userid' => $session['ses_userid']
48  ];
49  },
50  $allSessions
51  );
52 
53  // Sort by timestamp
54  usort($allSessions, function ($session1, $session2) {
55  return $session1['timestamp'] <=> $session2['timestamp'];
56  });
57 
58  return $allSessions;
59  }
60 
67  public function ‪findByBackendUser(‪BackendUser $backendUser)
68  {
69  $allActive = $this->‪findAllActive();
70 
71  return array_filter(
72  $allActive,
73  function ($session) use ($backendUser) {
74  return (int)$session['ses_userid'] === $backendUser->‪getUid();
75  }
76  );
77  }
78 
85  {
86  $sessionBackend = $this->‪getSessionBackend();
87  $sessionId = $this->‪getBackendSessionId();
88  $sessionBackend->update(
89  $sessionId,
90  [
91  'ses_userid' => $authentication->user['ses_backuserid'],
92  'ses_backuserid' => 0
93  ]
94  );
95  }
96 
100  protected function ‪getBackendSessionId(): string
101  {
102  return ‪$GLOBALS['BE_USER']->id;
103  }
104 
109  {
110  return GeneralUtility::makeInstance(SessionManager::class)->getSessionBackend('BE');
111  }
112 }
‪TYPO3\CMS\Beuser\Domain\Repository\BackendUserSessionRepository\getSessionBackend
‪SessionBackendInterface getSessionBackend()
Definition: BackendUserSessionRepository.php:108
‪TYPO3\CMS\Core\Session\SessionManager
Definition: SessionManager.php:37
‪TYPO3\CMS\Beuser\Domain\Repository\BackendUserSessionRepository\findAllActive
‪array findAllActive()
Definition: BackendUserSessionRepository.php:35
‪TYPO3\CMS\Beuser\Domain\Repository\BackendUserSessionRepository
Definition: BackendUserSessionRepository.php:29
‪TYPO3\CMS\Beuser\Domain\Repository
Definition: BackendUserGroupRepository.php:2
‪TYPO3\CMS\Extbase\DomainObject\AbstractDomainObject\getUid
‪int getUid()
Definition: AbstractDomainObject.php:62
‪TYPO3\CMS\Core\Session\Backend\SessionBackendInterface
Definition: SessionBackendInterface.php:26
‪TYPO3\CMS\Extbase\Persistence\Repository
Definition: Repository.php:23
‪TYPO3\CMS\Beuser\Domain\Repository\BackendUserSessionRepository\switchBackToOriginalUser
‪switchBackToOriginalUser(AbstractUserAuthentication $authentication)
Definition: BackendUserSessionRepository.php:84
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Beuser\Domain\Model\BackendUser
Definition: BackendUser.php:22
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Beuser\Domain\Repository\BackendUserSessionRepository\findByBackendUser
‪array findByBackendUser(BackendUser $backendUser)
Definition: BackendUserSessionRepository.php:67
‪TYPO3\CMS\Beuser\Domain\Repository\BackendUserSessionRepository\getBackendSessionId
‪string getBackendSessionId()
Definition: BackendUserSessionRepository.php:100
‪TYPO3\CMS\Core\Authentication\AbstractUserAuthentication
Definition: AbstractUserAuthentication.php:51