Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IBX-5705: Fixed InteractiveLoginToken using PostAuthenticationGuardToken #274

Merged
merged 9 commits into from
Sep 19, 2023
6 changes: 0 additions & 6 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ public function onInteractiveLogin(BaseInteractiveLoginEvent $event)
$providerKey,
$token->getRoleNames()
);
$interactiveToken->setOriginalToken($token);
$interactiveToken->setAttributes($token->getAttributes());
$this->tokenStorage->setToken($interactiveToken);
}
Expand Down
62 changes: 52 additions & 10 deletions src/lib/MVC/Symfony/Security/InteractiveLoginToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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{
* 0: string,
* 1: mixed,
* 2: null|\Symfony\Component\Security\Core\Authentication\Token\TokenInterface
Nattfarinn marked this conversation as resolved.
Show resolved Hide resolved
* } $data
*/
public function __unserialize(array $data): void
{
[$this->originalTokenType, $parentStr] = $serialized;
parent::__unserialize($parentStr);
if (count($data) < 3) {
[$this->originalTokenType, $parentData] = $data;
} else {
[$this->originalTokenType, $parentData, $this->originalToken] = $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 ($this->originalToken instanceof TokenInterface) {
Nattfarinn marked this conversation as resolved.
Show resolved Hide resolved
return $this->originalToken->isAuthenticated();
}

return parent::isAuthenticated();
}
}

Expand Down
Loading