So, I dug up something else and found out that the class Listenerfor my custom authentication provider was not spelled correctly. It was written in such a way that a new one was created at each page load Token.
As a result, two things had to be done.
The first was a change in the authentication listener, similar to those contained in the Symfony Firewall Listeners , the general structure of which is shown below.
if (null !== $token = $this->securityContext->getToken()) {
if ($token instanceof UsernamePasswordToken && $token->isAuthenticated() &&
$token->getUsername() === $username) {
return;
}
}
, . , , , .
-, , . , - . , , SwitchUserRole, . , if .
foreach ($token->getRoles() as $role) {
if ($role instanceof SwitchUserRole) {
$token = $role->getSource();
break;
}
}
, , , , , , , .