Skip to content

Commit 3fce9f6

Browse files
derhansenbmack
authored andcommitted
[TASK] Provide public method to create anonymous user session
With #100307 new PSR-14 events have been introduced to allow implementation of custom logic for classes extending `\TYPO3\CMS\Core\Authentication\AbstractUserAuthentication`. The PSR-14 event `BeforeUserLogoutEvent` allows to control, if the logout process should be handled by `AbstractUserAuthentication`. If an extension author decides to implement a custom logout process by using the PSR-14 event `AfterUserLoggedOutEvent`, it is currently not possible to use a public API method to create an anonymous user session. Instead, extension authors can use the internal method `initializeUserSessionManager` to. In order to provide a public API method to create an anonymous user session, this change adds the method `createAnonymousSession` to `AbstractUserAuthentication`. The method is now additionally used internally in the class to create an anonymous user session where required. Resolves: #106052 Releases: main, 13.4 Signed-off-by: Torben Hansen <derhansen@gmail.com> Change-Id: I7957d177d98c49ff10bb896e9c85466dcc8c0710 Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/87979 Tested-by: Benni Mack <benni@typo3.org> Tested-by: core-ci <typo3@b13.com> Tested-by: Garvin Hicking <gh@faktor-e.de> Reviewed-by: Benni Mack <benni@typo3.org> Reviewed-by: Garvin Hicking <gh@faktor-e.de> Tested-by: Christian Kuhn <lolli@schwarzbu.ch> Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
1 parent 3f987b0 commit 3fce9f6

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

typo3/sysext/core/Classes/Authentication/AbstractUserAuthentication.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,19 @@ public function __construct()
240240
public function initializeUserSessionManager(?UserSessionManager $userSessionManager = null): void
241241
{
242242
$this->userSessionManager = $userSessionManager ?? UserSessionManager::create($this->loginType);
243-
$this->userSession = $this->userSessionManager->createAnonymousSession();
243+
$this->createAnonymousSession();
244+
}
245+
246+
/**
247+
* Creates an anonymous user session.
248+
* This method should be avoided, as it is only a workaround due to the ugly setup of this class
249+
* and the authentication / logout behavior.
250+
*/
251+
public function createAnonymousSession(): void
252+
{
253+
if (!empty($this->userSessionManager)) {
254+
$this->userSession = $this->userSessionManager->createAnonymousSession();
255+
}
244256
}
245257

246258
/**
@@ -800,7 +812,7 @@ protected function fetchValidUserFromSessionOrDestroySession(bool $skipSessionUp
800812
// Delete any user set...
801813
$this->logoff();
802814
$userRecord = false;
803-
$this->userSession = $this->userSessionManager->createAnonymousSession();
815+
$this->createAnonymousSession();
804816
}
805817
}
806818
return is_array($userRecord) ? $userRecord : null;
@@ -848,7 +860,7 @@ protected function performLogoff()
848860
if ($this->userSession) {
849861
$this->userSessionManager->removeSession($this->userSession);
850862
}
851-
$this->userSession = $this->userSessionManager->createAnonymousSession();
863+
$this->createAnonymousSession();
852864
$this->user = null;
853865
if ($this->isCookieSet()) {
854866
$this->removeCookie();

0 commit comments

Comments
 (0)