From 4ab1bfccc528dff21777a1588f252ff255997b35 Mon Sep 17 00:00:00 2001 From: Andrew Longosz Date: Wed, 20 Nov 2024 14:21:28 +0100 Subject: [PATCH] [Security] Aligned RestAuthenticator with Symfony 6 --- .../Authenticator/RestAuthenticator.php | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/src/lib/Security/Authenticator/RestAuthenticator.php b/src/lib/Security/Authenticator/RestAuthenticator.php index 9d4c4538..d9285ff4 100644 --- a/src/lib/Security/Authenticator/RestAuthenticator.php +++ b/src/lib/Security/Authenticator/RestAuthenticator.php @@ -45,14 +45,13 @@ public function supports(Request $request): ?bool public function authenticate(Request $request): Passport { $existingUserToken = $this->fetchExistingToken($request); - if ($this->canUserFromSessionBeAuthenticated($existingUserToken)) { + if (null !== $existingUserToken && $this->canUserFromSessionBeAuthenticated($existingUserToken)) { $existingUser = $existingUserToken->getUser(); return $this->createAuthorizationPassport( - /** @phpstan-ignore-next-line */ $existingUser->getUserIdentifier(), - /** @phpstan-ignore-next-line */ - $existingUser->getPassword() + // @todo not sure how to refactor this + '' ); } @@ -112,17 +111,11 @@ private function fetchExistingToken(Request $request): ?TokenInterface } /** - * @phpstan-assert-if-true !null $existingUserToken + * @phpstan-assert-if-true !null $existingUserToken->getUser() */ private function canUserFromSessionBeAuthenticated(?TokenInterface $existingUserToken): bool { - if ($existingUserToken === null) { - return false; - } - - $user = $existingUserToken->getUser(); - - return !($user === null || $user->getPassword() === null); + return $existingUserToken?->getUser() !== null; } private function createAuthorizationPassport(string $login, string $password): Passport