Skip to content

Commit 523fceb

Browse files
authored
Merge pull request #440 from magento-performance/cabpi-386-expired-session
CABPI-386: Add null check for user in AdminSessionsManager
2 parents 57a850d + 89f9d69 commit 523fceb

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

app/code/Magento/Security/Model/AdminSessionsManager.php

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -266,17 +266,20 @@ public function getSessionsForCurrentUser()
266266
*/
267267
public function logoutOtherUserSessions()
268268
{
269-
$collection = $this->createAdminSessionInfoCollection()
270-
->filterByUser(
271-
$this->authSession->getUser()->getId(),
272-
\Magento\Security\Model\AdminSessionInfo::LOGGED_IN,
273-
$this->authSession->getAdminSessionInfoId()
274-
)
275-
->filterExpiredSessions($this->securityConfig->getAdminSessionLifetime())
276-
->loadData();
269+
$user = $this->authSession->getUser();
270+
if ($user) {
271+
$collection = $this->createAdminSessionInfoCollection()
272+
->filterByUser(
273+
$user->getId(),
274+
\Magento\Security\Model\AdminSessionInfo::LOGGED_IN,
275+
$this->authSession->getAdminSessionInfoId()
276+
)
277+
->filterExpiredSessions($this->securityConfig->getAdminSessionLifetime())
278+
->loadData();
277279

278-
$collection->setDataToAll('status', \Magento\Security\Model\AdminSessionInfo::LOGGED_OUT_MANUALLY)
279-
->save();
280+
$collection->setDataToAll('status', \Magento\Security\Model\AdminSessionInfo::LOGGED_OUT_MANUALLY)
281+
->save();
282+
}
280283

281284
return $this;
282285
}
@@ -304,11 +307,12 @@ public function cleanExpiredSessions()
304307
*/
305308
protected function createNewSession()
306309
{
310+
$user = $this->authSession->getUser();
307311
$adminSessionInfo = $this->adminSessionInfoFactory
308312
->create()
309313
->setData(
310314
[
311-
'user_id' => $this->authSession->getUser()->getId(),
315+
'user_id' => $user ? $user->getId() : null,
312316
'ip' => $this->remoteAddress->getRemoteAddress(),
313317
'status' => AdminSessionInfo::LOGGED_IN
314318
]

0 commit comments

Comments
 (0)