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

[Security] #25091 add target user to SwitchUserListener #25092

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions 1 src/Symfony/Component/Security/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ CHANGELOG
* removed HTTP digest authentication
* removed `GuardAuthenticatorInterface` in favor of `AuthenticatorInterface`
* removed `AbstractGuardAuthenticator::supports()`
* added target user to `SwitchUserListener`

3.4.0
-----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@ private function attemptSwitchUser(Request $request, $username)
throw new \LogicException(sprintf('You are already switched to "%s" user.', $token->getUsername()));
}

if (false === $this->accessDecisionManager->decide($token, array($this->role))) {
$user = $this->provider->loadUserByUsername($username);

if (false === $this->accessDecisionManager->decide($token, array($this->role), $user)) {
$exception = new AccessDeniedException();
$exception->setAttributes($this->role);

Expand All @@ -137,7 +139,6 @@ private function attemptSwitchUser(Request $request, $username)
$this->logger->info('Attempting to switch to user.', array('username' => $username));
}

$user = $this->provider->loadUserByUsername($username);
$this->userChecker->checkPostAuth($user);

$roles = $user->getRoles();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public function testSwitchUser()
$this->request->query->set('_switch_user', 'kuba');

$this->accessDecisionManager->expects($this->once())
->method('decide')->with($token, array('ROLE_ALLOWED_TO_SWITCH'))
->method('decide')->with($token, array('ROLE_ALLOWED_TO_SWITCH'), $user)
->will($this->returnValue(true));

$this->userProvider->expects($this->once())
Expand Down Expand Up @@ -212,7 +212,7 @@ public function testSwitchUserKeepsOtherQueryStringParameters()
));

$this->accessDecisionManager->expects($this->once())
->method('decide')->with($token, array('ROLE_ALLOWED_TO_SWITCH'))
->method('decide')->with($token, array('ROLE_ALLOWED_TO_SWITCH'), $user)
->will($this->returnValue(true));

$this->userProvider->expects($this->once())
Expand Down Expand Up @@ -240,7 +240,7 @@ public function testSwitchUserWithReplacedToken()
$this->request->query->set('_switch_user', 'kuba');

$this->accessDecisionManager->expects($this->any())
->method('decide')->with($token, array('ROLE_ALLOWED_TO_SWITCH'))
->method('decide')->with($token, array('ROLE_ALLOWED_TO_SWITCH'), $user)
->will($this->returnValue(true));

$this->userProvider->expects($this->any())
Expand Down Expand Up @@ -276,7 +276,7 @@ public function testSwitchUserStateless()
$this->request->query->set('_switch_user', 'kuba');

$this->accessDecisionManager->expects($this->once())
->method('decide')->with($token, array('ROLE_ALLOWED_TO_SWITCH'))
->method('decide')->with($token, array('ROLE_ALLOWED_TO_SWITCH'), $user)
->will($this->returnValue(true));

$this->userProvider->expects($this->once())
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.