summaryrefslogtreecommitdiffstats
path: root/Core/User
diff options
context:
space:
mode:
Diffstat (limited to 'Core/User')
-rw-r--r--Core/User/ChainUserProvider.php12
-rw-r--r--Core/User/InMemoryUserProvider.php37
-rw-r--r--Core/User/User.php2
3 files changed, 33 insertions, 18 deletions
diff --git a/Core/User/ChainUserProvider.php b/Core/User/ChainUserProvider.php
index 6e14a4f..8604ddc 100644
--- a/Core/User/ChainUserProvider.php
+++ b/Core/User/ChainUserProvider.php
@@ -47,7 +47,7 @@ class ChainUserProvider implements UserProviderInterface
foreach ($this->providers as $provider) {
try {
return $provider->loadUserByUsername($username);
- } catch (UsernameNotFoundException $notFound) {
+ } catch (UsernameNotFoundException $e) {
// try next one
}
}
@@ -67,18 +67,18 @@ class ChainUserProvider implements UserProviderInterface
foreach ($this->providers as $provider) {
try {
return $provider->refreshUser($user);
- } catch (UnsupportedUserException $unsupported) {
+ } catch (UnsupportedUserException $e) {
// try next one
- } catch (UsernameNotFoundException $notFound) {
+ } catch (UsernameNotFoundException $e) {
$supportedUserFound = true;
// try next one
}
}
if ($supportedUserFound) {
- $ex = new UsernameNotFoundException(sprintf('There is no user with name "%s".', $user->getUsername()));
- $ex->setUsername($user->getUsername());
- throw $ex;
+ $e = new UsernameNotFoundException(sprintf('There is no user with name "%s".', $user->getUsername()));
+ $e->setUsername($user->getUsername());
+ throw $e;
} else {
throw new UnsupportedUserException(sprintf('The account "%s" is not supported.', get_class($user)));
}
diff --git a/Core/User/InMemoryUserProvider.php b/Core/User/InMemoryUserProvider.php
index 624eb3d..9aa39ca 100644
--- a/Core/User/InMemoryUserProvider.php
+++ b/Core/User/InMemoryUserProvider.php
@@ -67,17 +67,9 @@ class InMemoryUserProvider implements UserProviderInterface
*/
public function loadUserByUsername($username)
{
- if (!isset($this->users[strtolower($username)])) {
- $ex = new UsernameNotFoundException(sprintf('Username "%s" does not exist.', $username));
- $ex->setUsername($username);
-
- throw $ex;
- }
+ $user = $this->getUser($username);
- $user = $this->users[strtolower($username)];
-
- return new User($user->getUsername(), $user->getPassword(), $user->getRoles(), $user->isEnabled(), $user->isAccountNonExpired(),
- $user->isCredentialsNonExpired(), $user->isAccountNonLocked());
+ return new User($user->getUsername(), $user->getPassword(), $user->getRoles(), $user->isEnabled(), $user->isAccountNonExpired(), $user->isCredentialsNonExpired(), $user->isAccountNonLocked());
}
/**
@@ -89,7 +81,9 @@ class InMemoryUserProvider implements UserProviderInterface
throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', get_class($user)));
}
- return $this->loadUserByUsername($user->getUsername());
+ $storedUser = $this->getUser($user->getUsername());
+
+ return new User($storedUser->getUsername(), $storedUser->getPassword(), $storedUser->getRoles(), $storedUser->isEnabled(), $storedUser->isAccountNonExpired(), $storedUser->isCredentialsNonExpired() && $storedUser->getPassword() === $user->getPassword(), $storedUser->isAccountNonLocked());
}
/**
@@ -99,4 +93,25 @@ class InMemoryUserProvider implements UserProviderInterface
{
return $class === 'Symfony\Component\Security\Core\User\User';
}
+
+ /**
+ * Returns the user by given username.
+ *
+ * @param string $username The username.
+ *
+ * @return User
+ *
+ * @throws UsernameNotFoundException If user whose given username does not exist.
+ */
+ private function getUser($username)
+ {
+ if (!isset($this->users[strtolower($username)])) {
+ $ex = new UsernameNotFoundException(sprintf('Username "%s" does not exist.', $username));
+ $ex->setUsername($username);
+
+ throw $ex;
+ }
+
+ return $this->users[strtolower($username)];
+ }
}
diff --git a/Core/User/User.php b/Core/User/User.php
index ea2c6a4..86f1acd 100644
--- a/Core/User/User.php
+++ b/Core/User/User.php
@@ -30,7 +30,7 @@ final class User implements AdvancedUserInterface
public function __construct($username, $password, array $roles = array(), $enabled = true, $userNonExpired = true, $credentialsNonExpired = true, $userNonLocked = true)
{
- if (empty($username)) {
+ if ('' === $username || null === $username) {
throw new \InvalidArgumentException('The username cannot be empty.');
}