Skip to content

Commit fc2710a

Browse files
committed
Fix deprecation warning for the UsernamePasswordToken constructor
1 parent 29b8dcb commit fc2710a

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

Security/LoginManager.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\Component\HttpFoundation\Response;
1717
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
1818
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
19+
use Symfony\Component\Security\Core\Authorization\Voter\CacheableVoterInterface;
1920
use Symfony\Component\Security\Core\User\UserCheckerInterface;
2021
use Symfony\Component\Security\Http\RememberMe\RememberMeHandlerInterface;
2122
use Symfony\Component\Security\Http\RememberMe\RememberMeServicesInterface;
@@ -102,6 +103,11 @@ final public function logInUser($firewallName, UserInterface $user, Response $re
102103
*/
103104
protected function createToken($firewall, UserInterface $user)
104105
{
105-
return new UsernamePasswordToken($user, null, $firewall, $user->getRoles());
106+
// Bc layer for Symfony <5.4
107+
if (!interface_exists(CacheableVoterInterface::class)) {
108+
return new UsernamePasswordToken($user, null, $firewall, $user->getRoles());
109+
}
110+
111+
return new UsernamePasswordToken($user, $firewall, $user->getRoles());
106112
}
107113
}

0 commit comments

Comments
 (0)