diff --git a/src/Symfony/Bridge/Doctrine/Security/User/EntityUserProvider.php b/src/Symfony/Bridge/Doctrine/Security/User/EntityUserProvider.php index 0385a1dd7faed..97664dcde82a4 100644 --- a/src/Symfony/Bridge/Doctrine/Security/User/EntityUserProvider.php +++ b/src/Symfony/Bridge/Doctrine/Security/User/EntityUserProvider.php @@ -54,8 +54,8 @@ public function loadUserByUsername($username) if (null !== $this->property) { $user = $this->repository->findOneBy(array($this->property => $username)); } else { - if (!$this->repository instanceof UserProviderInterface) { - throw new \InvalidArgumentException(sprintf('The Doctrine repository "%s" must implement UserProviderInterface.', get_class($this->repository))); + if (!$this->repository instanceof BaseUserProviderInterface) { + throw new \InvalidArgumentException(sprintf('The Doctrine repository "%s" must implement BaseUserProviderInterface.', get_class($this->repository))); } $user = $this->repository->loadUserByUsername($username); @@ -77,7 +77,7 @@ public function refreshUser(UserInterface $user) throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', get_class($user))); } - if ($this->repository instanceof UserProviderInterface) { + if ($this->repository instanceof BaseUserProviderInterface) { $refreshedUser = $this->repository->refreshUser($user); } else { // The user must be reloaded via the primary key as all other data diff --git a/src/Symfony/Component/Security/Core/User/BaseUserProviderInterface.php b/src/Symfony/Component/Security/Core/User/BaseUserProviderInterface.php new file mode 100644 index 0000000000000..6d9e0c6c28f20 --- /dev/null +++ b/src/Symfony/Component/Security/Core/User/BaseUserProviderInterface.php @@ -0,0 +1,67 @@ + + * + * 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; + +/** + * Represents a class that loads UserInterface objects from some source for the authentication system. + * + * In a typical authentication configuration, a username (i.e. some unique + * user identifier) credential enters the system (via form login, or any + * method). The user provider that is configured with that authentication + * method is asked to load the UserInterface object for the given username + * (via loadUserByUsername) so that the rest of the process can continue. + * + * Internally, a user provider can load users from any source (databases, + * configuration, web service). This is totally independent of how the authentication + * information is submitted or what the UserInterface object looks like. + * + * @see UserInterface + * + * @author Fabien Potencier + */ +interface BaseUserProviderInterface +{ + /** + * Loads the user for the given username. + * + * This method must throw UsernameNotFoundException if the user is not + * found. + * + * @param string $username The username + * + * @return UserInterface + * + * @see UsernameNotFoundException + * + * @throws UsernameNotFoundException if the user is not found + * + */ + public function loadUserByUsername($username); + + /** + * Refreshes the user for the account interface. + * + * It is up to the implementation to decide if the user data should be + * totally reloaded (e.g. from the database), or if the UserInterface + * object can just be merged into some internal array of users / identity + * map. + * @param UserInterface $user + * + * @return UserInterface + * + * @throws UnsupportedUserException if the account is not supported + */ + public function refreshUser(UserInterface $user); +} diff --git a/src/Symfony/Component/Security/Core/User/UserProviderInterface.php b/src/Symfony/Component/Security/Core/User/UserProviderInterface.php index 6b7895cd204e6..86b46627fd35e 100644 --- a/src/Symfony/Component/Security/Core/User/UserProviderInterface.php +++ b/src/Symfony/Component/Security/Core/User/UserProviderInterface.php @@ -11,9 +11,6 @@ namespace Symfony\Component\Security\Core\User; -use Symfony\Component\Security\Core\Exception\UsernameNotFoundException; -use Symfony\Component\Security\Core\Exception\UnsupportedUserException; - /** * Represents a class that loads UserInterface objects from some source for the authentication system. * @@ -31,40 +28,8 @@ * * @author Fabien Potencier */ -interface UserProviderInterface +interface UserProviderInterface extends BaseUserProviderInterface { - /** - * Loads the user for the given username. - * - * This method must throw UsernameNotFoundException if the user is not - * found. - * - * @param string $username The username - * - * @return UserInterface - * - * @see UsernameNotFoundException - * - * @throws UsernameNotFoundException if the user is not found - * - */ - public function loadUserByUsername($username); - - /** - * Refreshes the user for the account interface. - * - * It is up to the implementation to decide if the user data should be - * totally reloaded (e.g. from the database), or if the UserInterface - * object can just be merged into some internal array of users / identity - * map. - * @param UserInterface $user - * - * @return UserInterface - * - * @throws UnsupportedUserException if the account is not supported - */ - public function refreshUser(UserInterface $user); - /** * Whether this provider supports the given user class *