@@ -428,8 +428,6 @@ public function amLoggedInAsFrontendUser(UserInterface $user, string $firewallNa
428
428
*/
429
429
public function amLoggedInAs ($ username )
430
430
{
431
- $ firewallName = 'admin ' ;
432
-
433
431
try {
434
432
/** @var PimcoreUser $userModule */
435
433
$ userModule = $ this ->getModule ('\\' . PimcoreUser::class);
@@ -445,32 +443,12 @@ public function amLoggedInAs($username)
445
443
return ;
446
444
}
447
445
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 ) {
463
448
$ adminSession ->set ('user ' , $ pimcoreUser );
464
- $ adminSession ->set ('csrfToken ' , self ::PIMCORE_ADMIN_CSRF_TOKEN_NAME );
465
449
});
466
450
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 ());
474
452
475
453
$ this ->pimcoreCore ->client ->getCookieJar ()->clear ();
476
454
$ this ->pimcoreCore ->client ->getCookieJar ()->set ($ cookie );
0 commit comments