Skip to content

Commit 9a1dff8

Browse files
committed
simplify login task
1 parent c18859a commit 9a1dff8

File tree

1 file changed

+3
-25
lines changed

1 file changed

+3
-25
lines changed

src/_support/Helper/Browser/PhpBrowser.php

+3-25
Original file line numberDiff line numberDiff line change
@@ -428,8 +428,6 @@ public function amLoggedInAsFrontendUser(UserInterface $user, string $firewallNa
428428
*/
429429
public function amLoggedInAs($username)
430430
{
431-
$firewallName = 'admin';
432-
433431
try {
434432
/** @var PimcoreUser $userModule */
435433
$userModule = $this->getModule('\\' . PimcoreUser::class);
@@ -445,32 +443,12 @@ public function amLoggedInAs($username)
445443
return;
446444
}
447445

448-
/** @var Session $session */
449-
$session = $this->pimcoreCore->getContainer()->get('session');
450-
451-
$user = new \Pimcore\Bundle\AdminBundle\Security\User\User($pimcoreUser);
452-
$token = new UsernamePasswordToken($user, null, $firewallName, $pimcoreUser->getRoles());
453-
$this->pimcoreCore->getContainer()->get('security.token_storage')->setToken($token);
454-
455-
if (VersionHelper::pimcoreVersionIsGreaterOrEqualThan('6.5.0')) {
456-
if ($session->isStarted()) {
457-
$session->save();
458-
}
459-
}
460-
461-
\Pimcore\Tool\Session::useSession(function (AttributeBagInterface $adminSession) use ($pimcoreUser, $session) {
462-
$session->setId(\Pimcore\Tool\Session::getSessionId());
446+
\Pimcore\Tool\Session::invalidate();
447+
\Pimcore\Tool\Session::useSession(function (AttributeBagInterface $adminSession) use ($pimcoreUser) {
463448
$adminSession->set('user', $pimcoreUser);
464-
$adminSession->set('csrfToken', self::PIMCORE_ADMIN_CSRF_TOKEN_NAME);
465449
});
466450

467-
// allow re-usage of session in same cest.
468-
if (!empty($this->sessionSnapShot)) {
469-
$cookie = $this->sessionSnapShot;
470-
} else {
471-
$cookie = new Cookie($session->getName(), $session->getId());
472-
$this->sessionSnapShot = $cookie;
473-
}
451+
$cookie = new Cookie(\Pimcore\Tool\Session::getSessionName(), \Pimcore\Tool\Session::getSessionId());
474452

475453
$this->pimcoreCore->client->getCookieJar()->clear();
476454
$this->pimcoreCore->client->getCookieJar()->set($cookie);

0 commit comments

Comments
 (0)