1: <?php
2:
3: namespace Mapbender\CoreBundle\Security;
4:
5: use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
6: use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
7: use Symfony\Component\Security\Core\User\UserProviderInterface;
8: use Symfony\Component\Security\Core\User\UserInterface;
9: use PDO;
10:
11: 12: 13: 14: 15:
16: class Mapbender2UserProvider implements UserProviderInterface {
17: private $connection;
18:
19: public function __construct($connection) {
20: $this->connection = $connection;
21: }
22:
23: public function loadUserByUsername($username) {
24: $sql = "SELECT * FROM mb_user WHERE mb_user_name = :name";
25: $statement = $this->connection->prepare($sql);
26: $statement->bindValue('name', $username);
27: $statement->execute();
28: $user_data = $statement->fetch(PDO::FETCH_ASSOC);
29: if($user_data === False) {
30: throw new UsernameNotFoundException(sprintf('User %s can not be found.', $username));
31: return;
32: }
33:
34: $user = new User($username,
35: $user_data['mb_user_password'],
36: $user_data['mb_user_email'],
37: $user_data['mb_user_realname']);
38: $user->setExtraData($user_data);
39: return $user;
40: }
41:
42: public function refreshUser(UserInterface $user) {
43: if(!$user instanceof User) {
44: throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', get_class($user)));
45: }
46: return $this->loadUserByUsername($user->getUsername());
47: }
48:
49: public function supportsClass($class) {
50: return true;
51: }
52: }
53:
54: