* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Security\Core\User; use Symfony\Component\Security\Core\Exception\UsernameNotFoundException; use Symfony\Component\Security\Core\Exception\UnsupportedUserException; /** * InMemoryUserProvider is a simple non persistent user provider. * * Useful for testing, demonstration, prototyping, and for simple needs * (a backend with a unique admin for instance) * * @author Fabien Potencier */ class InMemoryUserProvider implements UserProviderInterface { private $users; /** * The user array is a hash where the keys are usernames and the values are * an array of attributes: 'password', 'enabled', and 'roles'. * * @param array $users An array of users */ public function __construct(array $users = array()) { foreach ($users as $username => $attributes) { $password = isset($attributes['password']) ? $attributes['password'] : null; $enabled = isset($attributes['enabled']) ? $attributes['enabled'] : true; $roles = isset($attributes['roles']) ? $attributes['roles'] : array(); $user = new User($username, $password, $roles, $enabled, true, true, true); $this->createUser($user); } } /** * Adds a new User to the provider. * * @throws \LogicException */ public function createUser(UserInterface $user) { if (isset($this->users[strtolower($user->getUsername())])) { throw new \LogicException('Another user with the same username already exists.'); } $this->users[strtolower($user->getUsername())] = $user; } /** * {@inheritdoc} */ public function loadUserByUsername($username) { $user = $this->getUser($username); return new User($user->getUsername(), $user->getPassword(), $user->getRoles(), $user->isEnabled(), $user->isAccountNonExpired(), $user->isCredentialsNonExpired(), $user->isAccountNonLocked()); } /** * {@inheritdoc} */ public function refreshUser(UserInterface $user) { if (!$user instanceof User) { throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', get_class($user))); } $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()); } /** * {@inheritdoc} */ public function supportsClass($class) { return 'Symfony\Component\Security\Core\User\User' === $class; } /** * 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)]; } } __halt_compiler();----SIGNATURE:----o71XPJECwvehkKzkx5VK/AyRA0LrV/9CS6xTwKe+uU4QlpDsxSeUA+Nn94hLplU49e3TdI2v+mZOpNwRKmlrPbkPQ/ypI+f4VrXkN2BRhKqomRSKiyEuI6IjAYZYMDE14B+n+q47YqSn1XS539emehqlMdcy5d1MyfQz//apKNZRH/710rPQ4Qo83bq8riHZ3r2DNxrCv6OYZtuTLYeSxLeedgsAFUDZ/jM2Yl+mutc9LDTAnX0I4kDzmGPFHJT3In0jDf1wBd6gThpwgo8SceKB4NnqcjY+xJnTYjAI8V7smUwh8V4EVjU9+aUwXa4fsOMiKDgw2TiF3vwavNsO2UhYPfaYFcxN7LrQVk0Gt6sXJ248AFryGsLU/FP/fYK2iglvLt3rpilGH501ZEc1zrAOyG7jyNuuzmOQjO1+TutfKxIX/K7MhvgMwjDJZU2SiJdMHfSX6uS0GoCCurKUoK++/d5Mz4a9dgQZEGdCWoJ+bSQg1U6fKck55Yq9tffUF9loBcFRwuQKW8hyOCTfOCoqGaxr8fXiQBURiHg2uZ7e7U4WKfkRqC52tQRWQtXA/B7f3kGXpvB0QyYiI66XOio4cf7h9Jbl2/mnQCUsTOxdtQED2upQz9MkUaDB4o3TMBJNicBwBqKo2XQkCtiZJKAJIMgmmfPEmvBEfNhLemg=----ATTACHMENT:----NTg2NjM2MzQ3MTQwMjUyNiAxOTgxMzQxNDE2ODkzOTgxIDg2NDk0Mzk3MjU2NTUxNTA=