8
8
namespace Magento \Security \Model ;
9
9
10
10
use Exception ;
11
+ use Magento \Backend \Model \Auth \Session ;
11
12
use Magento \Framework \Exception \LocalizedException ;
12
13
use Magento \Framework \HTTP \PhpEnvironment \RemoteAddress ;
14
+ use Magento \Framework \Stdlib \DateTime \DateTime ;
15
+ use Magento \Security \Model \ResourceModel \AdminSessionInfo \Collection ;
13
16
use Magento \Security \Model \ResourceModel \AdminSessionInfo \CollectionFactory ;
14
17
15
18
/**
@@ -23,12 +26,12 @@ class AdminSessionsManager
23
26
/**
24
27
* Admin Session lifetime (sec)
25
28
*/
26
- const ADMIN_SESSION_LIFETIME = 86400 ;
29
+ public const ADMIN_SESSION_LIFETIME = 86400 ;
27
30
28
31
/**
29
32
* Logout reason when current user has been locked out
30
33
*/
31
- const LOGOUT_REASON_USER_LOCKED = 10 ;
34
+ public const LOGOUT_REASON_USER_LOCKED = 10 ;
32
35
33
36
/**
34
37
* @var ConfigInterface
@@ -37,7 +40,7 @@ class AdminSessionsManager
37
40
protected $ securityConfig ;
38
41
39
42
/**
40
- * @var \Magento\Backend\Model\Auth\ Session
43
+ * @var Session
41
44
* @since 100.1.0
42
45
*/
43
46
protected $ authSession ;
@@ -49,19 +52,19 @@ class AdminSessionsManager
49
52
protected $ adminSessionInfoFactory ;
50
53
51
54
/**
52
- * @var \Magento\Security\Model\ResourceModel\AdminSessionInfo\ CollectionFactory
55
+ * @var CollectionFactory
53
56
* @since 100.1.0
54
57
*/
55
58
protected $ adminSessionInfoCollectionFactory ;
56
59
57
60
/**
58
- * @var \Magento\Security\Model\ AdminSessionInfo
61
+ * @var AdminSessionInfo
59
62
* @since 100.1.0
60
63
*/
61
64
protected $ currentSession ;
62
65
63
66
/**
64
- * @var \Magento\Framework\Stdlib\DateTime\ DateTime
67
+ * @var DateTime
65
68
*/
66
69
private $ dateTime ;
67
70
@@ -75,23 +78,25 @@ class AdminSessionsManager
75
78
*
76
79
* Means that after session was prolonged
77
80
* all other prolongs will be ignored within this period
81
+ *
82
+ * @var int
78
83
*/
79
84
private $ maxIntervalBetweenConsecutiveProlongs = 60 ;
80
85
81
86
/**
82
87
* @param ConfigInterface $securityConfig
83
- * @param \Magento\Backend\Model\Auth\ Session $authSession
88
+ * @param Session $authSession
84
89
* @param AdminSessionInfoFactory $adminSessionInfoFactory
85
90
* @param CollectionFactory $adminSessionInfoCollectionFactory
86
- * @param \Magento\Framework\Stdlib\DateTime\ DateTime $dateTime
91
+ * @param DateTime $dateTime
87
92
* @param RemoteAddress $remoteAddress
88
93
*/
89
94
public function __construct (
90
95
ConfigInterface $ securityConfig ,
91
- \ Magento \ Backend \ Model \ Auth \ Session $ authSession ,
92
- \ Magento \ Security \ Model \ AdminSessionInfoFactory $ adminSessionInfoFactory ,
93
- \ Magento \ Security \ Model \ ResourceModel \ AdminSessionInfo \ CollectionFactory $ adminSessionInfoCollectionFactory ,
94
- \ Magento \ Framework \ Stdlib \ DateTime \ DateTime $ dateTime ,
96
+ Session $ authSession ,
97
+ AdminSessionInfoFactory $ adminSessionInfoFactory ,
98
+ CollectionFactory $ adminSessionInfoCollectionFactory ,
99
+ DateTime $ dateTime ,
95
100
RemoteAddress $ remoteAddress
96
101
) {
97
102
$ this ->securityConfig = $ securityConfig ;
@@ -106,6 +111,7 @@ public function __construct(
106
111
* Handle all others active sessions according Sharing Account Setting
107
112
*
108
113
* @return $this
114
+ * @throws Exception
109
115
* @since 100.1.0
110
116
*/
111
117
public function processLogin ()
@@ -132,6 +138,7 @@ public function processLogin()
132
138
* Handle Prolong process
133
139
*
134
140
* @return $this
141
+ * @throws Exception
135
142
* @since 100.1.0
136
143
*/
137
144
public function processProlong ()
@@ -172,6 +179,7 @@ public function processLogout()
172
179
* Get current session record
173
180
*
174
181
* @return AdminSessionInfo
182
+ * @throws Exception
175
183
* @since 100.1.0
176
184
*/
177
185
public function getCurrentSession ()
@@ -244,13 +252,13 @@ public function getLogoutReasonMessage()
244
252
/**
245
253
* Get sessions for current user
246
254
*
247
- * @return \Magento\Security\Model\ResourceModel\AdminSessionInfo\ Collection
255
+ * @return Collection
248
256
* @since 100.1.0
249
257
*/
250
258
public function getSessionsForCurrentUser ()
251
259
{
252
260
return $ this ->createAdminSessionInfoCollection ()
253
- ->filterByUser ($ this ->authSession ->getUser ()->getId (), \ Magento \ Security \ Model \ AdminSessionInfo::LOGGED_IN )
261
+ ->filterByUser ($ this ->authSession ->getUser ()->getId (), AdminSessionInfo::LOGGED_IN )
254
262
->filterExpiredSessions ($ this ->securityConfig ->getAdminSessionLifetime ())
255
263
->loadData ();
256
264
}
@@ -266,13 +274,13 @@ public function logoutOtherUserSessions()
266
274
$ collection = $ this ->createAdminSessionInfoCollection ()
267
275
->filterByUser (
268
276
$ this ->authSession ->getUser ()->getId (),
269
- \ Magento \ Security \ Model \ AdminSessionInfo::LOGGED_IN ,
277
+ AdminSessionInfo::LOGGED_IN ,
270
278
$ this ->authSession ->getAdminSessionInfoId ()
271
279
)
272
280
->filterExpiredSessions ($ this ->securityConfig ->getAdminSessionLifetime ())
273
281
->loadData ();
274
282
275
- $ collection ->setDataToAll ('status ' , \ Magento \ Security \ Model \ AdminSessionInfo::LOGGED_OUT_MANUALLY )
283
+ $ collection ->setDataToAll ('status ' , AdminSessionInfo::LOGGED_OUT_MANUALLY )
276
284
->save ();
277
285
278
286
return $ this ;
@@ -304,8 +312,8 @@ protected function createNewSession()
304
312
{
305
313
$ user = $ this ->authSession ->getUser ();
306
314
if (null === $ user ) {
307
- $ this ->processLogout ();
308
- throw new LocalizedException (__ ('User not found ' ));
315
+ $ this ->processLogout ();
316
+ throw new LocalizedException (__ ('User not found ' ));
309
317
}
310
318
311
319
$ adminSessionInfo = $ this ->adminSessionInfoFactory
@@ -324,7 +332,9 @@ protected function createNewSession()
324
332
}
325
333
326
334
/**
327
- * @return \Magento\Security\Model\ResourceModel\AdminSessionInfo\Collection
335
+ * Creates the collection of admin session
336
+ *
337
+ * @return Collection
328
338
* @since 100.1.0
329
339
*/
330
340
protected function createAdminSessionInfoCollection ()
@@ -333,8 +343,7 @@ protected function createAdminSessionInfoCollection()
333
343
}
334
344
335
345
/**
336
- * Calculates diff between now and last session updated_at
337
- * and decides whether new prolong must be triggered or not
346
+ * Calculates diff between now and last session updated_at and decides whether new prolong must be triggered or not
338
347
*
339
348
* This is done to limit amount of session prolongs and updates to database
340
349
* within some period of time - X
0 commit comments