diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 09579e6f87..f7d51a19d7 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -12655,11 +12655,6 @@ parameters: count: 1 path: src/lib/MVC/Symfony/Security/InteractiveLoginToken.php - - - message: "#^Method Ibexa\\\\Core\\\\MVC\\\\Symfony\\\\Security\\\\InteractiveLoginToken\\:\\:__unserialize\\(\\) has parameter \\$serialized with no type specified\\.$#" - count: 1 - path: src/lib/MVC/Symfony/Security/InteractiveLoginToken.php - - message: "#^Method Ibexa\\\\Core\\\\MVC\\\\Symfony\\\\Security\\\\User\\:\\:__construct\\(\\) has parameter \\$roles with no value type specified in iterable type array\\.$#" count: 1 @@ -63504,4 +63499,3 @@ parameters: message: "#^Method Ibexa\\\\Tests\\\\Core\\\\Specification\\\\Content\\\\ContentTypeSpecificationTest\\:\\:providerForIsSatisfiedBy\\(\\) return type has no value type specified in iterable type array\\.$#" count: 1 path: tests/lib/Specification/Content/ContentTypeSpecificationTest.php - diff --git a/src/lib/MVC/Symfony/Security/EventListener/SecurityListener.php b/src/lib/MVC/Symfony/Security/EventListener/SecurityListener.php index 8d24f0310c..b836339099 100644 --- a/src/lib/MVC/Symfony/Security/EventListener/SecurityListener.php +++ b/src/lib/MVC/Symfony/Security/EventListener/SecurityListener.php @@ -139,6 +139,7 @@ public function onInteractiveLogin(BaseInteractiveLoginEvent $event) $providerKey, $token->getRoleNames() ); + $interactiveToken->setOriginalToken($token); $interactiveToken->setAttributes($token->getAttributes()); $this->tokenStorage->setToken($interactiveToken); } diff --git a/src/lib/MVC/Symfony/Security/InteractiveLoginToken.php b/src/lib/MVC/Symfony/Security/InteractiveLoginToken.php index 2a5619e183..af7fc23494 100644 --- a/src/lib/MVC/Symfony/Security/InteractiveLoginToken.php +++ b/src/lib/MVC/Symfony/Security/InteractiveLoginToken.php @@ -6,6 +6,7 @@ */ namespace Ibexa\Core\MVC\Symfony\Security; +use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken; /** @@ -14,32 +15,73 @@ */ class InteractiveLoginToken extends UsernamePasswordToken { - /** @var string */ - private $originalTokenType; + private ?TokenInterface $originalToken = null; + + private string $originalTokenType; public function __construct(UserInterface $user, $originalTokenType, $credentials, $providerKey, array $roles = []) { parent::__construct($user, $credentials, $providerKey, $roles); + $this->originalTokenType = $originalTokenType; } - /** - * @return string - */ - public function getOriginalTokenType() + public function getOriginalTokenType(): string { return $this->originalTokenType; } + /** + * @return array{ + * string, + * mixed, + * null|\Symfony\Component\Security\Core\Authentication\Token\TokenInterface + * } $data + */ public function __serialize(): array { - return [$this->originalTokenType, parent::__serialize()]; + return [ + $this->originalTokenType, + parent::__serialize(), + $this->originalToken, + ]; } - public function __unserialize($serialized): void + /** + * @param array{ + * string, + * mixed, + * 2?: \Symfony\Component\Security\Core\Authentication\Token\TokenInterface + * } $data + */ + public function __unserialize(array $data): void { - [$this->originalTokenType, $parentStr] = $serialized; - parent::__unserialize($parentStr); + if (isset($data[2])) { + [$this->originalTokenType, $parentData, $this->originalToken] = $data; + } else { + [$this->originalTokenType, $parentData] = $data; + } + + parent::__unserialize($parentData); + } + + public function setOriginalToken(TokenInterface $token): void + { + $this->originalToken = $token; + } + + public function getOriginalToken(): ?TokenInterface + { + return $this->originalToken; + } + + public function isAuthenticated(): bool + { + if (null !== $this->originalToken) { + return $this->originalToken->isAuthenticated(); + } + + return parent::isAuthenticated(); } }