Question

How to terminate other administrator session in back-end

Was it helpful?

Solution

Simple we can get $sessionInfo \Magento\Security\Model\AdminSessionInfo */ and set status 0 for which $sessionId we want to terminate

public function destroySession($sessionId)
{
    /** @var  $sessionInfo \Magento\Security\Model\AdminSessionInfo */
    $sessionInfo = $this->adminSessionInfoFactory->create()->load($sessionId, 'session_id');

    try{

        $sessionInfo->getResource()->updateStatusByUserId(
            \Magento\Security\Model\AdminSessionInfo::LOGGED_OUT,
            $sessionInfo->getUserId(),
            [1],
            [],
            null
        );

    } catch (\Exception $e) {

    }

    return $this;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top