48 lines
1.3 KiB
PHP
48 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Security;
|
|
|
|
use App\Entity\User;
|
|
use Symfony\Component\HttpFoundation\RequestStack;
|
|
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
|
|
use Symfony\Component\Security\Core\User\UserInterface;
|
|
use Symfony\Component\Security\Core\User\UserProviderInterface;
|
|
|
|
class SQLLoginUserProvider implements UserProviderInterface
|
|
{
|
|
protected RequestStack $requestStack;
|
|
|
|
public function __construct(RequestStack $requestStack)
|
|
{
|
|
$this->requestStack = $requestStack;
|
|
}
|
|
|
|
public function loadUserByIdentifier(string $identifier, ?User $user): ?UserInterface
|
|
{
|
|
if ($user->getUserIdentifier() === $identifier) {
|
|
return $user;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
public function loadUserByUsername(string $username): ?UserInterface
|
|
{
|
|
return $this->loadUserByIdentifier($username, null);
|
|
}
|
|
|
|
public function refreshUser(UserInterface $user)
|
|
{
|
|
if (!$user instanceof User) {
|
|
throw new UnsupportedUserException(sprintf('Invalid user class "%s".', get_class($user)));
|
|
}
|
|
|
|
return $this->loadUserByIdentifier($user->getUserIdentifier(), $user);
|
|
}
|
|
|
|
public function supportsClass(string $class)
|
|
{
|
|
return User::class === $class || is_subclass_of($class, User::class);
|
|
}
|
|
}
|