Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6e6ac9e

Browse files
committed
feature #25092 [Security] #25091 add target user to SwitchUserListener (jwmickey)
This PR was squashed before being merged into the 4.1-dev branch (closes #25092). Discussion ---------- [Security] #25091 add target user to SwitchUserListener | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #25091 | License | MIT | Doc PR | This patch provides the target user to the SwitchUserListener's accessDecisionManager->decide() call as the $object parameter to give any registered voters extra information. Commits ------- 5cb6f2a [Security] #25091 add target user to SwitchUserListener
2 parents 49f8b73 + 5cb6f2a commit 6e6ac9e

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

src/Symfony/Component/Security/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ CHANGELOG
1919
* removed HTTP digest authentication
2020
* removed `GuardAuthenticatorInterface` in favor of `AuthenticatorInterface`
2121
* removed `AbstractGuardAuthenticator::supports()`
22+
* added target user to `SwitchUserListener`
2223

2324
3.4.0
2425
-----

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,9 @@ private function attemptSwitchUser(Request $request, $username)
126126
throw new \LogicException(sprintf('You are already switched to "%s" user.', $token->getUsername()));
127127
}
128128

129-
if (false === $this->accessDecisionManager->decide($token, array($this->role))) {
129+
$user = $this->provider->loadUserByUsername($username);
130+
131+
if (false === $this->accessDecisionManager->decide($token, array($this->role), $user)) {
130132
$exception = new AccessDeniedException();
131133
$exception->setAttributes($this->role);
132134

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

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

143144
$roles = $user->getRoles();

src/Symfony/Component/Security/Http/Tests/Firewall/SwitchUserListenerTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ public function testSwitchUser()
182182
$this->request->query->set('_switch_user', 'kuba');
183183

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

188188
$this->userProvider->expects($this->once())
@@ -212,7 +212,7 @@ public function testSwitchUserKeepsOtherQueryStringParameters()
212212
));
213213

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

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

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

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

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

282282
$this->userProvider->expects($this->once())

0 commit comments

Comments
 (0)