88namespace Magento \Security \Model ;
99
1010use Exception ;
11+ use Magento \Backend \Model \Auth \Session ;
1112use Magento \Framework \Exception \LocalizedException ;
1213use Magento \Framework \HTTP \PhpEnvironment \RemoteAddress ;
14+ use Magento \Framework \Stdlib \DateTime \DateTime ;
15+ use Magento \Security \Model \ResourceModel \AdminSessionInfo \Collection ;
1316use Magento \Security \Model \ResourceModel \AdminSessionInfo \CollectionFactory ;
1417
1518/**
@@ -23,12 +26,12 @@ class AdminSessionsManager
2326 /**
2427 * Admin Session lifetime (sec)
2528 */
26- const ADMIN_SESSION_LIFETIME = 86400 ;
29+ public const ADMIN_SESSION_LIFETIME = 86400 ;
2730
2831 /**
2932 * Logout reason when current user has been locked out
3033 */
31- const LOGOUT_REASON_USER_LOCKED = 10 ;
34+ public const LOGOUT_REASON_USER_LOCKED = 10 ;
3235
3336 /**
3437 * @var ConfigInterface
@@ -37,7 +40,7 @@ class AdminSessionsManager
3740 protected $ securityConfig ;
3841
3942 /**
40- * @var \Magento\Backend\Model\Auth\ Session
43+ * @var Session
4144 * @since 100.1.0
4245 */
4346 protected $ authSession ;
@@ -49,19 +52,19 @@ class AdminSessionsManager
4952 protected $ adminSessionInfoFactory ;
5053
5154 /**
52- * @var \Magento\Security\Model\ResourceModel\AdminSessionInfo\ CollectionFactory
55+ * @var CollectionFactory
5356 * @since 100.1.0
5457 */
5558 protected $ adminSessionInfoCollectionFactory ;
5659
5760 /**
58- * @var \Magento\Security\Model\ AdminSessionInfo
61+ * @var AdminSessionInfo
5962 * @since 100.1.0
6063 */
6164 protected $ currentSession ;
6265
6366 /**
64- * @var \Magento\Framework\Stdlib\DateTime\ DateTime
67+ * @var DateTime
6568 */
6669 private $ dateTime ;
6770
@@ -75,23 +78,25 @@ class AdminSessionsManager
7578 *
7679 * Means that after session was prolonged
7780 * all other prolongs will be ignored within this period
81+ *
82+ * @var int
7883 */
7984 private $ maxIntervalBetweenConsecutiveProlongs = 60 ;
8085
8186 /**
8287 * @param ConfigInterface $securityConfig
83- * @param \Magento\Backend\Model\Auth\ Session $authSession
88+ * @param Session $authSession
8489 * @param AdminSessionInfoFactory $adminSessionInfoFactory
8590 * @param CollectionFactory $adminSessionInfoCollectionFactory
86- * @param \Magento\Framework\Stdlib\DateTime\ DateTime $dateTime
91+ * @param DateTime $dateTime
8792 * @param RemoteAddress $remoteAddress
8893 */
8994 public function __construct (
9095 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 ,
95100 RemoteAddress $ remoteAddress
96101 ) {
97102 $ this ->securityConfig = $ securityConfig ;
@@ -106,6 +111,7 @@ public function __construct(
106111 * Handle all others active sessions according Sharing Account Setting
107112 *
108113 * @return $this
114+ * @throws Exception
109115 * @since 100.1.0
110116 */
111117 public function processLogin ()
@@ -132,6 +138,7 @@ public function processLogin()
132138 * Handle Prolong process
133139 *
134140 * @return $this
141+ * @throws Exception
135142 * @since 100.1.0
136143 */
137144 public function processProlong ()
@@ -172,6 +179,7 @@ public function processLogout()
172179 * Get current session record
173180 *
174181 * @return AdminSessionInfo
182+ * @throws Exception
175183 * @since 100.1.0
176184 */
177185 public function getCurrentSession ()
@@ -244,13 +252,13 @@ public function getLogoutReasonMessage()
244252 /**
245253 * Get sessions for current user
246254 *
247- * @return \Magento\Security\Model\ResourceModel\AdminSessionInfo\ Collection
255+ * @return Collection
248256 * @since 100.1.0
249257 */
250258 public function getSessionsForCurrentUser ()
251259 {
252260 return $ this ->createAdminSessionInfoCollection ()
253- ->filterByUser ($ this ->authSession ->getUser ()->getId (), \ Magento \ Security \ Model \ AdminSessionInfo::LOGGED_IN )
261+ ->filterByUser ($ this ->authSession ->getUser ()->getId (), AdminSessionInfo::LOGGED_IN )
254262 ->filterExpiredSessions ($ this ->securityConfig ->getAdminSessionLifetime ())
255263 ->loadData ();
256264 }
@@ -266,13 +274,13 @@ public function logoutOtherUserSessions()
266274 $ collection = $ this ->createAdminSessionInfoCollection ()
267275 ->filterByUser (
268276 $ this ->authSession ->getUser ()->getId (),
269- \ Magento \ Security \ Model \ AdminSessionInfo::LOGGED_IN ,
277+ AdminSessionInfo::LOGGED_IN ,
270278 $ this ->authSession ->getAdminSessionInfoId ()
271279 )
272280 ->filterExpiredSessions ($ this ->securityConfig ->getAdminSessionLifetime ())
273281 ->loadData ();
274282
275- $ collection ->setDataToAll ('status ' , \ Magento \ Security \ Model \ AdminSessionInfo::LOGGED_OUT_MANUALLY )
283+ $ collection ->setDataToAll ('status ' , AdminSessionInfo::LOGGED_OUT_MANUALLY )
276284 ->save ();
277285
278286 return $ this ;
@@ -304,8 +312,8 @@ protected function createNewSession()
304312 {
305313 $ user = $ this ->authSession ->getUser ();
306314 if (null === $ user ) {
307- $ this ->processLogout ();
308- throw new LocalizedException (__ ('User not found ' ));
315+ $ this ->processLogout ();
316+ throw new LocalizedException (__ ('User not found ' ));
309317 }
310318
311319 $ adminSessionInfo = $ this ->adminSessionInfoFactory
@@ -324,7 +332,9 @@ protected function createNewSession()
324332 }
325333
326334 /**
327- * @return \Magento\Security\Model\ResourceModel\AdminSessionInfo\Collection
335+ * Creates the collection of admin session
336+ *
337+ * @return Collection
328338 * @since 100.1.0
329339 */
330340 protected function createAdminSessionInfoCollection ()
@@ -333,8 +343,7 @@ protected function createAdminSessionInfoCollection()
333343 }
334344
335345 /**
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
338347 *
339348 * This is done to limit amount of session prolongs and updates to database
340349 * within some period of time - X
0 commit comments