diff options
author | Fabien Potencier <fabien.potencier@gmail.com> | 2013-12-29 21:34:05 +0100 |
---|---|---|
committer | Fabien Potencier <fabien.potencier@gmail.com> | 2013-12-29 21:34:05 +0100 |
commit | 83e46fee1d960010bd09a9dbd82249a15e1602f4 (patch) | |
tree | 3c2300828baee3394410d55ee0d0a02f56e45243 /Core/Authentication/Provider | |
parent | fa9c90990e10a322a55caa8bb1ece92bb0a07ca3 (diff) | |
parent | 763b54967bf8bd0798bab530df38ec6b695d2d49 (diff) | |
download | symfony-security-83e46fee1d960010bd09a9dbd82249a15e1602f4.zip symfony-security-83e46fee1d960010bd09a9dbd82249a15e1602f4.tar.gz symfony-security-83e46fee1d960010bd09a9dbd82249a15e1602f4.tar.bz2 |
Merge branch '2.4'
* 2.4:
fix some cs
use restore_error_handler instead of set_error_handler($previous)
fix #9321 Crawler::addHtmlContent add gbk encoding support
[Console] fixed column width when using the Table helper with some decoration in cells
[Security] Fixed problem with losing ROLE_PREVIOUS_ADMIN role.
Fix for cache-key conflict when having a \Traversable as choices
[Security] removed obsolete comment
Diffstat (limited to 'Core/Authentication/Provider')
-rw-r--r-- | Core/Authentication/Provider/UserAuthenticationProvider.php | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/Core/Authentication/Provider/UserAuthenticationProvider.php b/Core/Authentication/Provider/UserAuthenticationProvider.php index 626f50b..18c3e70 100644 --- a/Core/Authentication/Provider/UserAuthenticationProvider.php +++ b/Core/Authentication/Provider/UserAuthenticationProvider.php @@ -19,6 +19,7 @@ use Symfony\Component\Security\Core\Exception\BadCredentialsException; use Symfony\Component\Security\Core\Exception\AuthenticationServiceException; use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken; use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; +use Symfony\Component\Security\Core\Role\SwitchUserRole; /** * UserProviderInterface retrieves users for UsernamePasswordToken tokens. @@ -92,7 +93,7 @@ abstract class UserAuthenticationProvider implements AuthenticationProviderInter throw $e; } - $authenticatedToken = new UsernamePasswordToken($user, $token->getCredentials(), $this->providerKey, $user->getRoles()); + $authenticatedToken = new UsernamePasswordToken($user, $token->getCredentials(), $this->providerKey, $this->getRoles($user, $token)); $authenticatedToken->setAttributes($token->getAttributes()); return $authenticatedToken; @@ -107,6 +108,29 @@ abstract class UserAuthenticationProvider implements AuthenticationProviderInter } /** + * Retrieves roles from user and appends SwitchUserRole if original token contained one. + * + * @param UserInterface $user The user + * @param TokenInterface $token The token + * + * @return Role[] The user roles + */ + private function getRoles(UserInterface $user, TokenInterface $token) + { + $roles = $user->getRoles(); + + foreach ($token->getRoles() as $role) { + if ($role instanceof SwitchUserRole) { + $roles[] = $role; + + break; + } + } + + return $roles; + } + + /** * Retrieves the user from an implementation-specific location. * * @param string $username The username to retrieve |