Exemple #1
0
 /**
  * @return void
  */
 public function execute()
 {
     try {
         $this->sessionsManager->logoutOtherUserSessions();
         $this->messageManager->addSuccess(__('All other open sessions for this account were terminated.'));
     } catch (\Magento\Framework\Exception\LocalizedException $e) {
         $this->messageManager->addError($e->getMessage());
     } catch (\Exception $e) {
         $this->messageManager->addException($e, __("We couldn't logout because of an error."));
     }
     $this->_redirect('*/*/activity');
 }
 /**
  * Test if other sessions were logged out if logoutOtherUserSessions() action was performed
  *
  * @magentoAdminConfigFixture admin/security/session_lifetime 100
  * @magentoConfigFixture default_store admin/security/admin_account_sharing 1
  * @magentoDbIsolation enabled
  */
 public function testLogoutOtherUserSessions()
 {
     /** @var \Magento\Security\Model\AdminSessionInfo $session */
     $session = $this->objectManager->create('Magento\\Security\\Model\\AdminSessionInfo');
     $session->setSessionId('669e2e3d752e8')->setUserId(1)->setStatus(1)->setCreatedAt(time() - 50)->setUpdatedAt(time() - 49)->save();
     $this->auth->login(\Magento\TestFramework\Bootstrap::ADMIN_NAME, \Magento\TestFramework\Bootstrap::ADMIN_PASSWORD);
     $collection = $this->getCollectionForLogoutOtherUserSessions($session);
     $this->assertGreaterThanOrEqual(1, $collection->getSize());
     $this->adminSessionsManager->logoutOtherUserSessions();
     $collection = $this->getCollectionForLogoutOtherUserSessions($session);
     $this->assertEquals(0, $collection->getSize());
 }
 /**
  * @return void
  */
 public function testLogoutOtherUserSessions()
 {
     $useId = 1;
     $sessionLifetime = 100;
     $sessionId = 50;
     $this->adminSessionInfoCollectionFactoryMock->expects($this->once())->method('create')->willReturn($this->adminSessionInfoCollectionMock);
     $this->authSessionMock->expects($this->once())->method('getUser')->willReturn($this->userMock);
     $this->authSessionMock->expects($this->once())->method('getSessionId')->willReturn($sessionId);
     $this->userMock->expects($this->once())->method('getId')->willReturn($useId);
     $this->adminSessionInfoCollectionMock->expects($this->once())->method('filterByUser')->with($useId, \Magento\Security\Model\AdminSessionInfo::LOGGED_IN, $sessionId)->willReturnSelf();
     $this->securityConfigMock->expects($this->once())->method('getAdminSessionLifetime')->willReturn($sessionLifetime);
     $this->adminSessionInfoCollectionMock->expects($this->once())->method('filterExpiredSessions')->with($sessionLifetime)->willReturnSelf();
     $this->adminSessionInfoCollectionMock->expects($this->once())->method('loadData')->willReturnSelf();
     $this->adminSessionInfoCollectionMock->expects($this->once())->method('setDataToAll')->with($this->equalTo('status'), \Magento\Security\Model\AdminSessionInfo::LOGGED_OUT_MANUALLY)->willReturnSelf();
     $this->adminSessionInfoCollectionMock->expects($this->once())->method('save');
     $this->model->logoutOtherUserSessions();
 }