login consent app sql
This commit is contained in:
332
vendor/symfony/security-core/Authentication/Token/AbstractToken.php
vendored
Normal file
332
vendor/symfony/security-core/Authentication/Token/AbstractToken.php
vendored
Normal file
@ -0,0 +1,332 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Security\Core\Authentication\Token;
|
||||
|
||||
use Symfony\Component\Security\Core\User\EquatableInterface;
|
||||
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
|
||||
use Symfony\Component\Security\Core\User\UserInterface;
|
||||
|
||||
/**
|
||||
* Base class for Token instances.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
|
||||
*/
|
||||
abstract class AbstractToken implements TokenInterface
|
||||
{
|
||||
private $user;
|
||||
private $roleNames = [];
|
||||
private $authenticated = false;
|
||||
private $attributes = [];
|
||||
|
||||
/**
|
||||
* @param string[] $roles An array of roles
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function __construct(array $roles = [])
|
||||
{
|
||||
foreach ($roles as $role) {
|
||||
$this->roleNames[] = $role;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getRoleNames(): array
|
||||
{
|
||||
return $this->roleNames;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getUsername(/* $legacy = true */)
|
||||
{
|
||||
if (1 === \func_num_args() && false === func_get_arg(0)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
trigger_deprecation('symfony/security-core', '5.3', 'Method "%s()" is deprecated, use getUserIdentifier() instead.', __METHOD__);
|
||||
|
||||
if ($this->user instanceof UserInterface) {
|
||||
return method_exists($this->user, 'getUserIdentifier') ? $this->user->getUserIdentifier() : $this->user->getUsername();
|
||||
}
|
||||
|
||||
return (string) $this->user;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getUserIdentifier(): string
|
||||
{
|
||||
// method returns "null" in non-legacy mode if not overridden
|
||||
$username = $this->getUsername(false);
|
||||
if (null !== $username) {
|
||||
trigger_deprecation('symfony/security-core', '5.3', 'Method "%s::getUsername()" is deprecated, override "getUserIdentifier()" instead.', get_debug_type($this));
|
||||
}
|
||||
|
||||
if ($this->user instanceof UserInterface) {
|
||||
// @deprecated since Symfony 5.3, change to $user->getUserIdentifier() in 6.0
|
||||
return method_exists($this->user, 'getUserIdentifier') ? $this->user->getUserIdentifier() : $this->user->getUsername();
|
||||
}
|
||||
|
||||
return (string) $this->user;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getUser()
|
||||
{
|
||||
return $this->user;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setUser($user)
|
||||
{
|
||||
if (!($user instanceof UserInterface || (\is_object($user) && method_exists($user, '__toString')) || \is_string($user))) {
|
||||
throw new \InvalidArgumentException('$user must be an instanceof UserInterface, an object implementing a __toString method, or a primitive string.');
|
||||
}
|
||||
|
||||
if (!$user instanceof UserInterface) {
|
||||
trigger_deprecation('symfony/security-core', '5.4', 'Using an object that is not an instance of "%s" as $user in "%s" is deprecated.', UserInterface::class, static::class);
|
||||
}
|
||||
|
||||
// @deprecated since Symfony 5.4, remove the whole block if/elseif/else block in 6.0
|
||||
if (1 < \func_num_args() && !func_get_arg(1)) {
|
||||
// ContextListener checks if the user has changed on its own and calls `setAuthenticated()` subsequently,
|
||||
// avoid doing the same checks twice
|
||||
$changed = false;
|
||||
} elseif (null === $this->user) {
|
||||
$changed = false;
|
||||
} elseif ($this->user instanceof UserInterface) {
|
||||
if (!$user instanceof UserInterface) {
|
||||
$changed = true;
|
||||
} else {
|
||||
$changed = $this->hasUserChanged($user);
|
||||
}
|
||||
} elseif ($user instanceof UserInterface) {
|
||||
$changed = true;
|
||||
} else {
|
||||
$changed = (string) $this->user !== (string) $user;
|
||||
}
|
||||
|
||||
// @deprecated since Symfony 5.4
|
||||
if ($changed) {
|
||||
$this->setAuthenticated(false, false);
|
||||
}
|
||||
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @deprecated since Symfony 5.4
|
||||
*/
|
||||
public function isAuthenticated()
|
||||
{
|
||||
if (1 > \func_num_args() || func_get_arg(0)) {
|
||||
trigger_deprecation('symfony/security-core', '5.4', 'Method "%s()" is deprecated, return null from "getUser()" instead when a token is not authenticated.', __METHOD__);
|
||||
}
|
||||
|
||||
return $this->authenticated;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setAuthenticated(bool $authenticated)
|
||||
{
|
||||
if (2 > \func_num_args() || func_get_arg(1)) {
|
||||
trigger_deprecation('symfony/security-core', '5.4', 'Method "%s()" is deprecated', __METHOD__);
|
||||
}
|
||||
|
||||
$this->authenticated = $authenticated;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function eraseCredentials()
|
||||
{
|
||||
if ($this->getUser() instanceof UserInterface) {
|
||||
$this->getUser()->eraseCredentials();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all the necessary state of the object for serialization purposes.
|
||||
*
|
||||
* There is no need to serialize any entry, they should be returned as-is.
|
||||
* If you extend this method, keep in mind you MUST guarantee parent data is present in the state.
|
||||
* Here is an example of how to extend this method:
|
||||
* <code>
|
||||
* public function __serialize(): array
|
||||
* {
|
||||
* return [$this->childAttribute, parent::__serialize()];
|
||||
* }
|
||||
* </code>
|
||||
*
|
||||
* @see __unserialize()
|
||||
*/
|
||||
public function __serialize(): array
|
||||
{
|
||||
return [$this->user, $this->authenticated, null, $this->attributes, $this->roleNames];
|
||||
}
|
||||
|
||||
/**
|
||||
* Restores the object state from an array given by __serialize().
|
||||
*
|
||||
* There is no need to unserialize any entry in $data, they are already ready-to-use.
|
||||
* If you extend this method, keep in mind you MUST pass the parent data to its respective class.
|
||||
* Here is an example of how to extend this method:
|
||||
* <code>
|
||||
* public function __unserialize(array $data): void
|
||||
* {
|
||||
* [$this->childAttribute, $parentData] = $data;
|
||||
* parent::__unserialize($parentData);
|
||||
* }
|
||||
* </code>
|
||||
*
|
||||
* @see __serialize()
|
||||
*/
|
||||
public function __unserialize(array $data): void
|
||||
{
|
||||
[$this->user, $this->authenticated, , $this->attributes, $this->roleNames] = $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getAttributes()
|
||||
{
|
||||
return $this->attributes;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setAttributes(array $attributes)
|
||||
{
|
||||
$this->attributes = $attributes;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function hasAttribute(string $name)
|
||||
{
|
||||
return \array_key_exists($name, $this->attributes);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getAttribute(string $name)
|
||||
{
|
||||
if (!\array_key_exists($name, $this->attributes)) {
|
||||
throw new \InvalidArgumentException(sprintf('This token has no "%s" attribute.', $name));
|
||||
}
|
||||
|
||||
return $this->attributes[$name];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setAttribute(string $name, $value)
|
||||
{
|
||||
$this->attributes[$name] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
$class = static::class;
|
||||
$class = substr($class, strrpos($class, '\\') + 1);
|
||||
|
||||
$roles = [];
|
||||
foreach ($this->roleNames as $role) {
|
||||
$roles[] = $role;
|
||||
}
|
||||
|
||||
return sprintf('%s(user="%s", authenticated=%s, roles="%s")', $class, $this->getUserIdentifier(), json_encode($this->authenticated), implode(', ', $roles));
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final public function serialize(): string
|
||||
{
|
||||
return serialize($this->__serialize());
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final public function unserialize($serialized)
|
||||
{
|
||||
$this->__unserialize(\is_array($serialized) ? $serialized : unserialize($serialized));
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated since Symfony 5.4
|
||||
*/
|
||||
private function hasUserChanged(UserInterface $user): bool
|
||||
{
|
||||
if (!($this->user instanceof UserInterface)) {
|
||||
throw new \BadMethodCallException('Method "hasUserChanged" should be called when current user class is instance of "UserInterface".');
|
||||
}
|
||||
|
||||
if ($this->user instanceof EquatableInterface) {
|
||||
return !(bool) $this->user->isEqualTo($user);
|
||||
}
|
||||
|
||||
// @deprecated since Symfony 5.3, check for PasswordAuthenticatedUserInterface on both user objects before comparing passwords
|
||||
if ($this->user->getPassword() !== $user->getPassword()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// @deprecated since Symfony 5.3, check for LegacyPasswordAuthenticatedUserInterface on both user objects before comparing salts
|
||||
if ($this->user->getSalt() !== $user->getSalt()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$userRoles = array_map('strval', (array) $user->getRoles());
|
||||
|
||||
if ($this instanceof SwitchUserToken) {
|
||||
$userRoles[] = 'ROLE_PREVIOUS_ADMIN';
|
||||
}
|
||||
|
||||
if (\count($userRoles) !== \count($this->getRoleNames()) || \count($userRoles) !== \count(array_intersect($userRoles, $this->getRoleNames()))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// @deprecated since Symfony 5.3, drop getUsername() in 6.0
|
||||
$userIdentifier = function ($user) {
|
||||
return method_exists($user, 'getUserIdentifier') ? $user->getUserIdentifier() : $user->getUsername();
|
||||
};
|
||||
if ($userIdentifier($this->user) !== $userIdentifier($user)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
79
vendor/symfony/security-core/Authentication/Token/AnonymousToken.php
vendored
Normal file
79
vendor/symfony/security-core/Authentication/Token/AnonymousToken.php
vendored
Normal file
@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Security\Core\Authentication\Token;
|
||||
|
||||
use Symfony\Component\Security\Core\User\UserInterface;
|
||||
|
||||
/**
|
||||
* AnonymousToken represents an anonymous token.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* @deprecated since 5.4, anonymous is now represented by the absence of a token
|
||||
*/
|
||||
class AnonymousToken extends AbstractToken
|
||||
{
|
||||
private $secret;
|
||||
|
||||
/**
|
||||
* @param string $secret A secret used to make sure the token is created by the app and not by a malicious client
|
||||
* @param string|\Stringable|UserInterface $user
|
||||
* @param string[] $roles
|
||||
*/
|
||||
public function __construct(string $secret, $user, array $roles = [])
|
||||
{
|
||||
trigger_deprecation('symfony/security-core', '5.4', 'The "%s" class is deprecated.', __CLASS__);
|
||||
|
||||
parent::__construct($roles);
|
||||
|
||||
$this->secret = $secret;
|
||||
$this->setUser($user);
|
||||
// @deprecated since Symfony 5.4
|
||||
$this->setAuthenticated(true, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getCredentials()
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the secret.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getSecret()
|
||||
{
|
||||
return $this->secret;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __serialize(): array
|
||||
{
|
||||
return [$this->secret, parent::__serialize()];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __unserialize(array $data): void
|
||||
{
|
||||
[$this->secret, $parentData] = $data;
|
||||
$parentData = \is_array($parentData) ? $parentData : unserialize($parentData);
|
||||
parent::__unserialize($parentData);
|
||||
}
|
||||
}
|
134
vendor/symfony/security-core/Authentication/Token/NullToken.php
vendored
Normal file
134
vendor/symfony/security-core/Authentication/Token/NullToken.php
vendored
Normal file
@ -0,0 +1,134 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Security\Core\Authentication\Token;
|
||||
|
||||
/**
|
||||
* @author Wouter de Jong <wouter@wouterj.nl>
|
||||
*/
|
||||
class NullToken implements TokenInterface
|
||||
{
|
||||
public function __toString(): string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
public function getRoleNames(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getCredentials()
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
public function getUser()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public function setUser($user)
|
||||
{
|
||||
throw new \BadMethodCallException('Cannot set user on a NullToken.');
|
||||
}
|
||||
|
||||
public function getUsername()
|
||||
{
|
||||
trigger_deprecation('symfony/security-core', '5.3', 'Method "%s()" is deprecated, use getUserIdentifier() instead.', __METHOD__);
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
public function getUserIdentifier(): string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated since Symfony 5.4
|
||||
*/
|
||||
public function isAuthenticated()
|
||||
{
|
||||
if (0 === \func_num_args() || func_get_arg(0)) {
|
||||
trigger_deprecation('symfony/security-core', '5.4', 'Method "%s()" is deprecated, return null from "getUser()" instead when a token is not authenticated.', __METHOD__);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated since Symfony 5.4
|
||||
*/
|
||||
public function setAuthenticated(bool $isAuthenticated)
|
||||
{
|
||||
throw new \BadMethodCallException('Cannot change authentication state of NullToken.');
|
||||
}
|
||||
|
||||
public function eraseCredentials()
|
||||
{
|
||||
}
|
||||
|
||||
public function getAttributes()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function setAttributes(array $attributes)
|
||||
{
|
||||
throw new \BadMethodCallException('Cannot set attributes of NullToken.');
|
||||
}
|
||||
|
||||
public function hasAttribute(string $name)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getAttribute(string $name)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public function setAttribute(string $name, $value)
|
||||
{
|
||||
throw new \BadMethodCallException('Cannot add attribute to NullToken.');
|
||||
}
|
||||
|
||||
public function __serialize(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function __unserialize(array $data): void
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*
|
||||
* @internal in 5.3
|
||||
* @final in 5.3
|
||||
*/
|
||||
public function serialize()
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*
|
||||
* @internal in 5.3
|
||||
* @final in 5.3
|
||||
*/
|
||||
public function unserialize($serialized)
|
||||
{
|
||||
}
|
||||
}
|
114
vendor/symfony/security-core/Authentication/Token/PreAuthenticatedToken.php
vendored
Normal file
114
vendor/symfony/security-core/Authentication/Token/PreAuthenticatedToken.php
vendored
Normal file
@ -0,0 +1,114 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Security\Core\Authentication\Token;
|
||||
|
||||
use Symfony\Component\Security\Core\User\UserInterface;
|
||||
|
||||
/**
|
||||
* PreAuthenticatedToken implements a pre-authenticated token.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
class PreAuthenticatedToken extends AbstractToken
|
||||
{
|
||||
private $credentials;
|
||||
private $firewallName;
|
||||
|
||||
/**
|
||||
* @param UserInterface $user
|
||||
* @param string $firewallName
|
||||
* @param string[] $roles
|
||||
*/
|
||||
public function __construct($user, /*string*/ $firewallName, /*array*/ $roles = [])
|
||||
{
|
||||
if (\is_string($roles)) {
|
||||
trigger_deprecation('symfony/security-core', '5.4', 'Argument $credentials of "%s()" is deprecated.', __METHOD__);
|
||||
|
||||
$credentials = $firewallName;
|
||||
$firewallName = $roles;
|
||||
$roles = \func_num_args() > 3 ? func_get_arg(3) : [];
|
||||
}
|
||||
|
||||
parent::__construct($roles);
|
||||
|
||||
if ('' === $firewallName) {
|
||||
throw new \InvalidArgumentException('$firewallName must not be empty.');
|
||||
}
|
||||
|
||||
$this->setUser($user);
|
||||
$this->credentials = $credentials ?? null;
|
||||
$this->firewallName = $firewallName;
|
||||
|
||||
if ($roles) {
|
||||
$this->setAuthenticated(true, false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the provider key.
|
||||
*
|
||||
* @return string The provider key
|
||||
*
|
||||
* @deprecated since Symfony 5.2, use getFirewallName() instead
|
||||
*/
|
||||
public function getProviderKey()
|
||||
{
|
||||
if (1 !== \func_num_args() || true !== func_get_arg(0)) {
|
||||
trigger_deprecation('symfony/security-core', '5.2', 'Method "%s()" is deprecated, use "getFirewallName()" instead.', __METHOD__);
|
||||
}
|
||||
|
||||
return $this->firewallName;
|
||||
}
|
||||
|
||||
public function getFirewallName(): string
|
||||
{
|
||||
return $this->getProviderKey(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getCredentials()
|
||||
{
|
||||
trigger_deprecation('symfony/security-core', '5.4', 'Method "%s()" is deprecated.', __METHOD__);
|
||||
|
||||
return $this->credentials;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function eraseCredentials()
|
||||
{
|
||||
parent::eraseCredentials();
|
||||
|
||||
$this->credentials = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __serialize(): array
|
||||
{
|
||||
return [$this->credentials, $this->firewallName, parent::__serialize()];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __unserialize(array $data): void
|
||||
{
|
||||
[$this->credentials, $this->firewallName, $parentData] = $data;
|
||||
$parentData = \is_array($parentData) ? $parentData : unserialize($parentData);
|
||||
parent::__unserialize($parentData);
|
||||
}
|
||||
}
|
118
vendor/symfony/security-core/Authentication/Token/RememberMeToken.php
vendored
Normal file
118
vendor/symfony/security-core/Authentication/Token/RememberMeToken.php
vendored
Normal file
@ -0,0 +1,118 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Security\Core\Authentication\Token;
|
||||
|
||||
use Symfony\Component\Security\Core\User\UserInterface;
|
||||
|
||||
/**
|
||||
* Authentication Token for "Remember-Me".
|
||||
*
|
||||
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
|
||||
*/
|
||||
class RememberMeToken extends AbstractToken
|
||||
{
|
||||
private $secret;
|
||||
private $firewallName;
|
||||
|
||||
/**
|
||||
* @param string $secret A secret used to make sure the token is created by the app and not by a malicious client
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function __construct(UserInterface $user, string $firewallName, string $secret)
|
||||
{
|
||||
parent::__construct($user->getRoles());
|
||||
|
||||
if (empty($secret)) {
|
||||
throw new \InvalidArgumentException('$secret must not be empty.');
|
||||
}
|
||||
|
||||
if ('' === $firewallName) {
|
||||
throw new \InvalidArgumentException('$firewallName must not be empty.');
|
||||
}
|
||||
|
||||
$this->firewallName = $firewallName;
|
||||
$this->secret = $secret;
|
||||
|
||||
$this->setUser($user);
|
||||
parent::setAuthenticated(true, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setAuthenticated(bool $authenticated)
|
||||
{
|
||||
if ($authenticated) {
|
||||
throw new \LogicException('You cannot set this token to authenticated after creation.');
|
||||
}
|
||||
|
||||
parent::setAuthenticated(false, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the provider secret.
|
||||
*
|
||||
* @return string The provider secret
|
||||
*
|
||||
* @deprecated since Symfony 5.2, use getFirewallName() instead
|
||||
*/
|
||||
public function getProviderKey()
|
||||
{
|
||||
if (1 !== \func_num_args() || true !== func_get_arg(0)) {
|
||||
trigger_deprecation('symfony/security-core', '5.2', 'Method "%s()" is deprecated, use "getFirewallName()" instead.', __METHOD__);
|
||||
}
|
||||
|
||||
return $this->firewallName;
|
||||
}
|
||||
|
||||
public function getFirewallName(): string
|
||||
{
|
||||
return $this->getProviderKey(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getSecret()
|
||||
{
|
||||
return $this->secret;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getCredentials()
|
||||
{
|
||||
trigger_deprecation('symfony/security-core', '5.4', 'Method "%s()" is deprecated.', __METHOD__);
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __serialize(): array
|
||||
{
|
||||
return [$this->secret, $this->firewallName, parent::__serialize()];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __unserialize(array $data): void
|
||||
{
|
||||
[$this->secret, $this->firewallName, $parentData] = $data;
|
||||
$parentData = \is_array($parentData) ? $parentData : unserialize($parentData);
|
||||
parent::__unserialize($parentData);
|
||||
}
|
||||
}
|
71
vendor/symfony/security-core/Authentication/Token/Storage/TokenStorage.php
vendored
Normal file
71
vendor/symfony/security-core/Authentication/Token/Storage/TokenStorage.php
vendored
Normal file
@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Security\Core\Authentication\Token\Storage;
|
||||
|
||||
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
|
||||
use Symfony\Contracts\Service\ResetInterface;
|
||||
|
||||
/**
|
||||
* TokenStorage contains a TokenInterface.
|
||||
*
|
||||
* It gives access to the token representing the current user authentication.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
|
||||
*/
|
||||
class TokenStorage implements TokenStorageInterface, ResetInterface
|
||||
{
|
||||
private $token;
|
||||
private $initializer;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getToken()
|
||||
{
|
||||
if ($initializer = $this->initializer) {
|
||||
$this->initializer = null;
|
||||
$initializer();
|
||||
}
|
||||
|
||||
return $this->token;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setToken(TokenInterface $token = null)
|
||||
{
|
||||
if ($token) {
|
||||
// ensure any initializer is called
|
||||
$this->getToken();
|
||||
|
||||
// @deprecated since Symfony 5.3
|
||||
if (!method_exists($token, 'getUserIdentifier')) {
|
||||
trigger_deprecation('symfony/security-core', '5.3', 'Not implementing method "getUserIdentifier(): string" in token class "%s" is deprecated. This method will replace "getUsername()" in Symfony 6.0.', get_debug_type($token));
|
||||
}
|
||||
}
|
||||
|
||||
$this->initializer = null;
|
||||
$this->token = $token;
|
||||
}
|
||||
|
||||
public function setInitializer(?callable $initializer): void
|
||||
{
|
||||
$this->initializer = $initializer;
|
||||
}
|
||||
|
||||
public function reset()
|
||||
{
|
||||
$this->setToken(null);
|
||||
}
|
||||
}
|
36
vendor/symfony/security-core/Authentication/Token/Storage/TokenStorageInterface.php
vendored
Normal file
36
vendor/symfony/security-core/Authentication/Token/Storage/TokenStorageInterface.php
vendored
Normal file
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Security\Core\Authentication\Token\Storage;
|
||||
|
||||
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
|
||||
|
||||
/**
|
||||
* The TokenStorageInterface.
|
||||
*
|
||||
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
|
||||
*/
|
||||
interface TokenStorageInterface
|
||||
{
|
||||
/**
|
||||
* Returns the current security token.
|
||||
*
|
||||
* @return TokenInterface|null
|
||||
*/
|
||||
public function getToken();
|
||||
|
||||
/**
|
||||
* Sets the authentication token.
|
||||
*
|
||||
* @param TokenInterface|null $token A TokenInterface token, or null if no further authentication information should be stored
|
||||
*/
|
||||
public function setToken(TokenInterface $token = null);
|
||||
}
|
109
vendor/symfony/security-core/Authentication/Token/Storage/UsageTrackingTokenStorage.php
vendored
Normal file
109
vendor/symfony/security-core/Authentication/Token/Storage/UsageTrackingTokenStorage.php
vendored
Normal file
@ -0,0 +1,109 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Security\Core\Authentication\Token\Storage;
|
||||
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
use Symfony\Component\HttpFoundation\Session\SessionInterface;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
|
||||
use Symfony\Contracts\Service\ServiceSubscriberInterface;
|
||||
|
||||
/**
|
||||
* A token storage that increments the session usage index when the token is accessed.
|
||||
*
|
||||
* @author Nicolas Grekas <p@tchwork.com>
|
||||
*/
|
||||
final class UsageTrackingTokenStorage implements TokenStorageInterface, ServiceSubscriberInterface
|
||||
{
|
||||
private $storage;
|
||||
private $container;
|
||||
private $enableUsageTracking = false;
|
||||
|
||||
public function __construct(TokenStorageInterface $storage, ContainerInterface $container)
|
||||
{
|
||||
$this->storage = $storage;
|
||||
$this->container = $container;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getToken(): ?TokenInterface
|
||||
{
|
||||
if ($this->shouldTrackUsage()) {
|
||||
// increments the internal session usage index
|
||||
$this->getSession()->getMetadataBag();
|
||||
}
|
||||
|
||||
return $this->storage->getToken();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setToken(TokenInterface $token = null): void
|
||||
{
|
||||
$this->storage->setToken($token);
|
||||
|
||||
if ($token && $this->shouldTrackUsage()) {
|
||||
// increments the internal session usage index
|
||||
$this->getSession()->getMetadataBag();
|
||||
}
|
||||
}
|
||||
|
||||
public function enableUsageTracking(): void
|
||||
{
|
||||
$this->enableUsageTracking = true;
|
||||
}
|
||||
|
||||
public function disableUsageTracking(): void
|
||||
{
|
||||
$this->enableUsageTracking = false;
|
||||
}
|
||||
|
||||
public static function getSubscribedServices(): array
|
||||
{
|
||||
return [
|
||||
'request_stack' => RequestStack::class,
|
||||
];
|
||||
}
|
||||
|
||||
private function getSession(): SessionInterface
|
||||
{
|
||||
// BC for symfony/security-bundle < 5.3
|
||||
if ($this->container->has('session')) {
|
||||
trigger_deprecation('symfony/security-core', '5.3', 'Injecting the "session" in "%s" is deprecated, inject the "request_stack" instead.', __CLASS__);
|
||||
|
||||
return $this->container->get('session');
|
||||
}
|
||||
|
||||
return $this->container->get('request_stack')->getSession();
|
||||
}
|
||||
|
||||
private function shouldTrackUsage(): bool
|
||||
{
|
||||
if (!$this->enableUsageTracking) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// BC for symfony/security-bundle < 5.3
|
||||
if ($this->container->has('session')) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!$this->container->get('request_stack')->getMainRequest()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
87
vendor/symfony/security-core/Authentication/Token/SwitchUserToken.php
vendored
Normal file
87
vendor/symfony/security-core/Authentication/Token/SwitchUserToken.php
vendored
Normal file
@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Security\Core\Authentication\Token;
|
||||
|
||||
use Symfony\Component\Security\Core\User\UserInterface;
|
||||
|
||||
/**
|
||||
* Token representing a user who temporarily impersonates another one.
|
||||
*
|
||||
* @author Christian Flothmann <christian.flothmann@sensiolabs.de>
|
||||
*/
|
||||
class SwitchUserToken extends UsernamePasswordToken
|
||||
{
|
||||
private $originalToken;
|
||||
private $originatedFromUri;
|
||||
|
||||
/**
|
||||
* @param UserInterface $user
|
||||
* @param string|null $originatedFromUri The URI where was the user at the switch
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function __construct($user, /*string*/ $firewallName, /*array*/ $roles, /*TokenInterface*/ $originalToken, /*string*/ $originatedFromUri = null)
|
||||
{
|
||||
if (\is_string($roles)) {
|
||||
// @deprecated since 5.4, deprecation is triggered by UsernamePasswordToken::__construct()
|
||||
$credentials = $firewallName;
|
||||
$firewallName = $roles;
|
||||
$roles = $originalToken;
|
||||
$originalToken = $originatedFromUri;
|
||||
$originatedFromUri = \func_num_args() > 5 ? func_get_arg(5) : null;
|
||||
|
||||
parent::__construct($user, $credentials, $firewallName, $roles);
|
||||
} else {
|
||||
parent::__construct($user, $firewallName, $roles);
|
||||
}
|
||||
|
||||
if (!$originalToken instanceof TokenInterface) {
|
||||
throw new \TypeError(sprintf('Argument $originalToken of "%s" must be an instance of "%s", "%s" given.', __METHOD__, TokenInterface::class, get_debug_type($originalToken)));
|
||||
}
|
||||
|
||||
$this->originalToken = $originalToken;
|
||||
$this->originatedFromUri = $originatedFromUri;
|
||||
}
|
||||
|
||||
public function getOriginalToken(): TokenInterface
|
||||
{
|
||||
return $this->originalToken;
|
||||
}
|
||||
|
||||
public function getOriginatedFromUri(): ?string
|
||||
{
|
||||
return $this->originatedFromUri;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __serialize(): array
|
||||
{
|
||||
return [$this->originalToken, $this->originatedFromUri, parent::__serialize()];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __unserialize(array $data): void
|
||||
{
|
||||
if (3 > \count($data)) {
|
||||
// Support for tokens serialized with version 5.1 or lower of symfony/security-core.
|
||||
[$this->originalToken, $parentData] = $data;
|
||||
} else {
|
||||
[$this->originalToken, $this->originatedFromUri, $parentData] = $data;
|
||||
}
|
||||
$parentData = \is_array($parentData) ? $parentData : unserialize($parentData);
|
||||
parent::__unserialize($parentData);
|
||||
}
|
||||
}
|
133
vendor/symfony/security-core/Authentication/Token/TokenInterface.php
vendored
Normal file
133
vendor/symfony/security-core/Authentication/Token/TokenInterface.php
vendored
Normal file
@ -0,0 +1,133 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Security\Core\Authentication\Token;
|
||||
|
||||
use Symfony\Component\Security\Core\User\UserInterface;
|
||||
|
||||
/**
|
||||
* TokenInterface is the interface for the user authentication information.
|
||||
*
|
||||
* @method string getUserIdentifier() returns the user identifier used during authentication (e.g. a user's email address or username)
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
|
||||
*/
|
||||
interface TokenInterface extends \Serializable
|
||||
{
|
||||
/**
|
||||
* Returns a string representation of the Token.
|
||||
*
|
||||
* This is only to be used for debugging purposes.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString();
|
||||
|
||||
/**
|
||||
* Returns the user roles.
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public function getRoleNames(): array;
|
||||
|
||||
/**
|
||||
* Returns the user credentials.
|
||||
*
|
||||
* @return mixed
|
||||
*
|
||||
* @deprecated since Symfony 5.4
|
||||
*/
|
||||
public function getCredentials();
|
||||
|
||||
/**
|
||||
* Returns a user representation.
|
||||
*
|
||||
* @return UserInterface|null
|
||||
*
|
||||
* @see AbstractToken::setUser()
|
||||
*/
|
||||
public function getUser();
|
||||
|
||||
/**
|
||||
* Sets the authenticated user in the token.
|
||||
*
|
||||
* @param UserInterface $user
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function setUser($user);
|
||||
|
||||
/**
|
||||
* Returns whether the user is authenticated or not.
|
||||
*
|
||||
* @return bool true if the token has been authenticated, false otherwise
|
||||
*
|
||||
* @deprecated since Symfony 5.4, return null from "getUser()" instead when a token is not authenticated
|
||||
*/
|
||||
public function isAuthenticated();
|
||||
|
||||
/**
|
||||
* Sets the authenticated flag.
|
||||
*
|
||||
* @deprecated since Symfony 5.4
|
||||
*/
|
||||
public function setAuthenticated(bool $isAuthenticated);
|
||||
|
||||
/**
|
||||
* Removes sensitive information from the token.
|
||||
*/
|
||||
public function eraseCredentials();
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getAttributes();
|
||||
|
||||
/**
|
||||
* @param array $attributes The token attributes
|
||||
*/
|
||||
public function setAttributes(array $attributes);
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function hasAttribute(string $name);
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*
|
||||
* @throws \InvalidArgumentException When attribute doesn't exist for this token
|
||||
*/
|
||||
public function getAttribute(string $name);
|
||||
|
||||
/**
|
||||
* @param mixed $value The attribute value
|
||||
*/
|
||||
public function setAttribute(string $name, $value);
|
||||
|
||||
/**
|
||||
* Returns all the necessary state of the object for serialization purposes.
|
||||
*/
|
||||
public function __serialize(): array;
|
||||
|
||||
/**
|
||||
* Restores the object state from an array given by __serialize().
|
||||
*/
|
||||
public function __unserialize(array $data): void;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*
|
||||
* @deprecated since Symfony 5.3, use getUserIdentifier() instead
|
||||
*/
|
||||
public function getUsername();
|
||||
}
|
125
vendor/symfony/security-core/Authentication/Token/UsernamePasswordToken.php
vendored
Normal file
125
vendor/symfony/security-core/Authentication/Token/UsernamePasswordToken.php
vendored
Normal file
@ -0,0 +1,125 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Security\Core\Authentication\Token;
|
||||
|
||||
use Symfony\Component\Security\Core\User\UserInterface;
|
||||
|
||||
/**
|
||||
* UsernamePasswordToken implements a username and password token.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*/
|
||||
class UsernamePasswordToken extends AbstractToken
|
||||
{
|
||||
private $credentials;
|
||||
private $firewallName;
|
||||
|
||||
/**
|
||||
* @param UserInterface $user
|
||||
* @param string[] $roles
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function __construct($user, /*string*/ $firewallName, /*array*/ $roles = [])
|
||||
{
|
||||
if (\is_string($roles)) {
|
||||
trigger_deprecation('symfony/security-core', '5.4', 'The $credentials argument of "%s" is deprecated.', static::class.'::__construct');
|
||||
|
||||
$credentials = $firewallName;
|
||||
$firewallName = $roles;
|
||||
$roles = \func_num_args() > 3 ? func_get_arg(3) : [];
|
||||
}
|
||||
|
||||
parent::__construct($roles);
|
||||
|
||||
if ('' === $firewallName) {
|
||||
throw new \InvalidArgumentException('$firewallName must not be empty.');
|
||||
}
|
||||
|
||||
$this->setUser($user);
|
||||
$this->credentials = $credentials ?? null;
|
||||
$this->firewallName = $firewallName;
|
||||
|
||||
parent::setAuthenticated(\count($roles) > 0, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setAuthenticated(bool $isAuthenticated)
|
||||
{
|
||||
if ($isAuthenticated) {
|
||||
throw new \LogicException('Cannot set this token to trusted after instantiation.');
|
||||
}
|
||||
|
||||
parent::setAuthenticated(false, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getCredentials()
|
||||
{
|
||||
trigger_deprecation('symfony/security-core', '5.4', 'Method "%s" is deprecated.', __METHOD__);
|
||||
|
||||
return $this->credentials;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the provider key.
|
||||
*
|
||||
* @return string The provider key
|
||||
*
|
||||
* @deprecated since Symfony 5.2, use getFirewallName() instead
|
||||
*/
|
||||
public function getProviderKey()
|
||||
{
|
||||
if (1 !== \func_num_args() || true !== func_get_arg(0)) {
|
||||
trigger_deprecation('symfony/security-core', '5.2', 'Method "%s" is deprecated, use "getFirewallName()" instead.', __METHOD__);
|
||||
}
|
||||
|
||||
return $this->firewallName;
|
||||
}
|
||||
|
||||
public function getFirewallName(): string
|
||||
{
|
||||
return $this->getProviderKey(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function eraseCredentials()
|
||||
{
|
||||
parent::eraseCredentials();
|
||||
|
||||
$this->credentials = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __serialize(): array
|
||||
{
|
||||
return [$this->credentials, $this->firewallName, parent::__serialize()];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __unserialize(array $data): void
|
||||
{
|
||||
[$this->credentials, $this->firewallName, $parentData] = $data;
|
||||
$parentData = \is_array($parentData) ? $parentData : unserialize($parentData);
|
||||
parent::__unserialize($parentData);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user