|
23 | 23 | use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
|
24 | 24 | use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
|
25 | 25 | use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
|
| 26 | +use Symfony\Component\Security\Core\Role\SwitchUserRole; |
26 | 27 | use Symfony\Component\Security\Core\User\UserInterface;
|
27 | 28 | use Symfony\Component\Security\Core\User\UserProviderInterface;
|
28 | 29 | use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
@@ -91,7 +92,10 @@ public function handle(GetResponseEvent $event)
|
91 | 92 | $token = unserialize($token);
|
92 | 93 |
|
93 | 94 | if (null !== $this->logger) {
|
94 |
| - $this->logger->debug('Read existing security token from the session.', array('key' => $this->sessionKey)); |
| 95 | + $this->logger->debug('Read existing security token from the session.', array( |
| 96 | + 'key' => $this->sessionKey, |
| 97 | + 'token_class' => is_object($token) ? get_class($token) : null, |
| 98 | + )); |
95 | 99 | }
|
96 | 100 |
|
97 | 101 | if ($token instanceof TokenInterface) {
|
@@ -169,7 +173,16 @@ protected function refreshUser(TokenInterface $token)
|
169 | 173 | $token->setUser($refreshedUser);
|
170 | 174 |
|
171 | 175 | if (null !== $this->logger) {
|
172 |
| - $this->logger->debug('User was reloaded from a user provider.', array('username' => $refreshedUser->getUsername(), 'provider' => get_class($provider))); |
| 176 | + $context = array('provider' => get_class($provider), 'username' => $refreshedUser->getUsername()); |
| 177 | + |
| 178 | + foreach ($token->getRoles() as $role) { |
| 179 | + if ($role instanceof SwitchUserRole) { |
| 180 | + $context['impersonator_username'] = $role->getSource()->getUsername(); |
| 181 | + break; |
| 182 | + } |
| 183 | + } |
| 184 | + |
| 185 | + $this->logger->debug('User was reloaded from a user provider.', $context); |
173 | 186 | }
|
174 | 187 |
|
175 | 188 | return $token;
|
|
0 commit comments