Skip to content

Commit a6b7f4f

Browse files
committed
AC-2653: Fix an admin custom URL functionality
1 parent 6e7f8f6 commit a6b7f4f

File tree

1 file changed

+20
-39
lines changed

1 file changed

+20
-39
lines changed

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

Lines changed: 20 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,7 @@
77

88
namespace Magento\Security\Model;
99

10-
use Exception;
11-
use Magento\Backend\Model\Auth\Session;
12-
use Magento\Framework\Exception\LocalizedException;
1310
use Magento\Framework\HTTP\PhpEnvironment\RemoteAddress;
14-
use Magento\Framework\Stdlib\DateTime\DateTime;
15-
use Magento\Security\Model\ResourceModel\AdminSessionInfo\Collection;
1611
use Magento\Security\Model\ResourceModel\AdminSessionInfo\CollectionFactory;
1712

1813
/**
@@ -26,12 +21,12 @@ class AdminSessionsManager
2621
/**
2722
* Admin Session lifetime (sec)
2823
*/
29-
public const ADMIN_SESSION_LIFETIME = 86400;
24+
const ADMIN_SESSION_LIFETIME = 86400;
3025

3126
/**
3227
* Logout reason when current user has been locked out
3328
*/
34-
public const LOGOUT_REASON_USER_LOCKED = 10;
29+
const LOGOUT_REASON_USER_LOCKED = 10;
3530

3631
/**
3732
* @var ConfigInterface
@@ -40,7 +35,7 @@ class AdminSessionsManager
4035
protected $securityConfig;
4136

4237
/**
43-
* @var Session
38+
* @var \Magento\Backend\Model\Auth\Session
4439
* @since 100.1.0
4540
*/
4641
protected $authSession;
@@ -52,19 +47,19 @@ class AdminSessionsManager
5247
protected $adminSessionInfoFactory;
5348

5449
/**
55-
* @var CollectionFactory
50+
* @var \Magento\Security\Model\ResourceModel\AdminSessionInfo\CollectionFactory
5651
* @since 100.1.0
5752
*/
5853
protected $adminSessionInfoCollectionFactory;
5954

6055
/**
61-
* @var AdminSessionInfo
56+
* @var \Magento\Security\Model\AdminSessionInfo
6257
* @since 100.1.0
6358
*/
6459
protected $currentSession;
6560

6661
/**
67-
* @var DateTime
62+
* @var \Magento\Framework\Stdlib\DateTime\DateTime
6863
*/
6964
private $dateTime;
7065

@@ -78,25 +73,23 @@ class AdminSessionsManager
7873
*
7974
* Means that after session was prolonged
8075
* all other prolongs will be ignored within this period
81-
*
82-
* @var int
8376
*/
8477
private $maxIntervalBetweenConsecutiveProlongs = 60;
8578

8679
/**
8780
* @param ConfigInterface $securityConfig
88-
* @param Session $authSession
81+
* @param \Magento\Backend\Model\Auth\Session $authSession
8982
* @param AdminSessionInfoFactory $adminSessionInfoFactory
9083
* @param CollectionFactory $adminSessionInfoCollectionFactory
91-
* @param DateTime $dateTime
84+
* @param \Magento\Framework\Stdlib\DateTime\DateTime $dateTime
9285
* @param RemoteAddress $remoteAddress
9386
*/
9487
public function __construct(
9588
ConfigInterface $securityConfig,
96-
Session $authSession,
97-
AdminSessionInfoFactory $adminSessionInfoFactory,
98-
CollectionFactory $adminSessionInfoCollectionFactory,
99-
DateTime $dateTime,
89+
\Magento\Backend\Model\Auth\Session $authSession,
90+
\Magento\Security\Model\AdminSessionInfoFactory $adminSessionInfoFactory,
91+
\Magento\Security\Model\ResourceModel\AdminSessionInfo\CollectionFactory $adminSessionInfoCollectionFactory,
92+
\Magento\Framework\Stdlib\DateTime\DateTime $dateTime,
10093
RemoteAddress $remoteAddress
10194
) {
10295
$this->securityConfig = $securityConfig;
@@ -111,7 +104,6 @@ public function __construct(
111104
* Handle all others active sessions according Sharing Account Setting
112105
*
113106
* @return $this
114-
* @throws Exception
115107
* @since 100.1.0
116108
*/
117109
public function processLogin()
@@ -138,7 +130,6 @@ public function processLogin()
138130
* Handle Prolong process
139131
*
140132
* @return $this
141-
* @throws Exception
142133
* @since 100.1.0
143134
*/
144135
public function processProlong()
@@ -161,7 +152,6 @@ public function processProlong()
161152
* Handle logout process
162153
*
163154
* @return $this
164-
* @throws Exception
165155
* @since 100.1.0
166156
*/
167157
public function processLogout()
@@ -179,7 +169,6 @@ public function processLogout()
179169
* Get current session record
180170
*
181171
* @return AdminSessionInfo
182-
* @throws Exception
183172
* @since 100.1.0
184173
*/
185174
public function getCurrentSession()
@@ -252,13 +241,13 @@ public function getLogoutReasonMessage()
252241
/**
253242
* Get sessions for current user
254243
*
255-
* @return Collection
244+
* @return \Magento\Security\Model\ResourceModel\AdminSessionInfo\Collection
256245
* @since 100.1.0
257246
*/
258247
public function getSessionsForCurrentUser()
259248
{
260249
return $this->createAdminSessionInfoCollection()
261-
->filterByUser($this->authSession->getUser()->getId(), AdminSessionInfo::LOGGED_IN)
250+
->filterByUser($this->authSession->getUser()->getId(), \Magento\Security\Model\AdminSessionInfo::LOGGED_IN)
262251
->filterExpiredSessions($this->securityConfig->getAdminSessionLifetime())
263252
->loadData();
264253
}
@@ -274,13 +263,13 @@ public function logoutOtherUserSessions()
274263
$collection = $this->createAdminSessionInfoCollection()
275264
->filterByUser(
276265
$this->authSession->getUser()->getId(),
277-
AdminSessionInfo::LOGGED_IN,
266+
\Magento\Security\Model\AdminSessionInfo::LOGGED_IN,
278267
$this->authSession->getAdminSessionInfoId()
279268
)
280269
->filterExpiredSessions($this->securityConfig->getAdminSessionLifetime())
281270
->loadData();
282271

283-
$collection->setDataToAll('status', AdminSessionInfo::LOGGED_OUT_MANUALLY)
272+
$collection->setDataToAll('status', \Magento\Security\Model\AdminSessionInfo::LOGGED_OUT_MANUALLY)
284273
->save();
285274

286275
return $this;
@@ -305,22 +294,15 @@ public function cleanExpiredSessions()
305294
* Create new record
306295
*
307296
* @return $this
308-
* @throws Exception
309297
* @since 100.1.0
310298
*/
311299
protected function createNewSession()
312300
{
313-
$user = $this->authSession->getUser();
314-
if (null === $user) {
315-
$this->processLogout();
316-
throw new LocalizedException(__('User not found'));
317-
}
318-
319301
$adminSessionInfo = $this->adminSessionInfoFactory
320302
->create()
321303
->setData(
322304
[
323-
'user_id' => $user->getId(),
305+
'user_id' => $this->authSession->getUser()->getId(),
324306
'ip' => $this->remoteAddress->getRemoteAddress(),
325307
'status' => AdminSessionInfo::LOGGED_IN
326308
]
@@ -332,9 +314,7 @@ protected function createNewSession()
332314
}
333315

334316
/**
335-
* Creates the collection of admin session
336-
*
337-
* @return Collection
317+
* @return \Magento\Security\Model\ResourceModel\AdminSessionInfo\Collection
338318
* @since 100.1.0
339319
*/
340320
protected function createAdminSessionInfoCollection()
@@ -343,7 +323,8 @@ protected function createAdminSessionInfoCollection()
343323
}
344324

345325
/**
346-
* Calculates diff between now and last session updated_at and decides whether new prolong must be triggered or not
326+
* Calculates diff between now and last session updated_at
327+
* and decides whether new prolong must be triggered or not
347328
*
348329
* This is done to limit amount of session prolongs and updates to database
349330
* within some period of time - X

0 commit comments

Comments
 (0)