isAHandledBackendSession($authentication)) { $objectManager = GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\ObjectManager::class); $backendUserSessionRepository = $objectManager->get(\TYPO3\CMS\Beuser\Domain\Repository\BackendUserSessionRepository::class); $backendUserSessionRepository->switchBackToOriginalUser($authentication); /** @var \TYPO3\CMS\Backend\Routing\UriBuilder $uriBuilder */ $uriBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Routing\UriBuilder::class); HttpUtility::redirect((string)$uriBuilder->buildUriFromRoute('main')); } } /** * Check if the given authentication object is a backend session and * contains all necessary information to allow switching. * * @param AbstractUserAuthentication $authentication * @return bool */ protected function isAHandledBackendSession(AbstractUserAuthentication $authentication) { return ($authentication instanceof BackendUserAuthentication) && is_array($authentication->user) && (int)$authentication->user['uid'] > 0 && (int)$authentication->user['ses_backuserid'] > 0; } }