From 3a64b08bd92fd124e321d5106080341d73e7c406 Mon Sep 17 00:00:00 2001 From: Abhoryo Date: Sun, 14 Aug 2011 00:00:10 +0300 Subject: [PATCH 1/2] Search in others user providers when a user is not found in the first user provider and throws the right exception. --- .../Security/Core/User/ChainUserProvider.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Security/Core/User/ChainUserProvider.php b/src/Symfony/Component/Security/Core/User/ChainUserProvider.php index e6aca3298479..84aa01273c8e 100644 --- a/src/Symfony/Component/Security/Core/User/ChainUserProvider.php +++ b/src/Symfony/Component/Security/Core/User/ChainUserProvider.php @@ -52,15 +52,23 @@ public function loadUserByUsername($username) */ public function refreshUser(UserInterface $user) { + $supportedUserFound = false; + foreach ($this->providers as $provider) { try { return $provider->refreshUser($user); } catch (UnsupportedUserException $unsupported) { // try next one + } catch (UsernameNotFoundException $notFound) { + // try next one + $supportedUserFound = true; } } - - throw new UnsupportedUserException(sprintf('The account "%s" is not supported.', get_class($user))); + + if ($supportedUserFound) + throw new UsernameNotFoundException(sprintf('There is no user with name "%s".', $user->getUsername())); + else + throw new UnsupportedUserException(sprintf('The account "%s" is not supported.', get_class($user))); } /** From e9d2a67c1f4908206f49ddcf97f7af0a32d03592 Mon Sep 17 00:00:00 2001 From: Abhoryo Date: Sun, 14 Aug 2011 01:38:02 +0300 Subject: [PATCH 2/2] CS --- .../Component/Security/Core/User/ChainUserProvider.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/Security/Core/User/ChainUserProvider.php b/src/Symfony/Component/Security/Core/User/ChainUserProvider.php index 84aa01273c8e..b0556f7b0af1 100644 --- a/src/Symfony/Component/Security/Core/User/ChainUserProvider.php +++ b/src/Symfony/Component/Security/Core/User/ChainUserProvider.php @@ -60,15 +60,16 @@ public function refreshUser(UserInterface $user) } catch (UnsupportedUserException $unsupported) { // try next one } catch (UsernameNotFoundException $notFound) { - // try next one $supportedUserFound = true; + // try next one } } - if ($supportedUserFound) + if ($supportedUserFound) { throw new UsernameNotFoundException(sprintf('There is no user with name "%s".', $user->getUsername())); - else + } else { throw new UnsupportedUserException(sprintf('The account "%s" is not supported.', get_class($user))); + } } /**