Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit fc44215

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

File tree

1 file changed

+15
-2
lines changed
Filter options

1 file changed

+15
-2
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Security/Http/Firewall/ContextListener.php
+15-2Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.