1: <?php
2:
3: namespace Mapbender\DrupalIntegrationBundle\Security\User;
4:
5: use Symfony\Component\Security\Core\User\UserProviderInterface;
6: use Symfony\Component\Security\Core\User\UserInterface;
7: use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
8: use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
9:
10:
11: class DrupalUserProvider implements UserProviderInterface
12: {
13: public function loadUserByUsername($username)
14: {
15: $drupalUser = user_load_by_name($username);
16: if($drupalUser !== False) {
17: return new DrupalUser($drupalUser);
18: }
19:
20: throw new UsernameNotFoundException(sprintf('Username "%s" does not exist.', $username));
21: }
22:
23: public function refreshUser(UserInterface $user)
24: {
25: if (!$user instanceof DrupalUser) {
26: throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', get_class($user)));
27: }
28:
29: return $this->loadUserByUsername($user->getUsername());
30: }
31:
32: public function supportsClass($class)
33: {
34: return $class === 'Mapbender\DrupalIntegrationBundle\Security\User\DrupalUser';
35: }
36: }
37: