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