Skip to content

Commit fc44215

Browse files
gharlanfabpot
authored andcommitted
[Security] add impersonator_user to "User was reloaded" log message
1 parent d00ac8a commit fc44215

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/Symfony/Component/Security/Http/Firewall/ContextListener.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
2424
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
2525
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
26+
use Symfony\Component\Security\Core\Role\SwitchUserRole;
2627
use Symfony\Component\Security\Core\User\UserInterface;
2728
use Symfony\Component\Security\Core\User\UserProviderInterface;
2829
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
@@ -91,7 +92,10 @@ public function handle(GetResponseEvent $event)
9192
$token = unserialize($token);
9293

9394
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+
));
9599
}
96100

97101
if ($token instanceof TokenInterface) {
@@ -169,7 +173,16 @@ protected function refreshUser(TokenInterface $token)
169173
$token->setUser($refreshedUser);
170174

171175
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);
173186
}
174187

175188
return $token;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy