Overview

Namespaces

  • Mapbender
    • Component
      • HTTP
    • CoreBundle
      • Command
      • Component
        • Exception
      • Controller
      • DataFixtures
        • ORM
      • DependencyInjection
      • Element
        • Type
      • Entity
      • EventListener
      • Extension
      • Form
        • DataTransformer
        • EventListener
        • Type
      • Security
      • Template
    • KmlBundle
      • Element
    • ManagerBundle
      • Controller
      • Form
        • DataTransformer
        • Type
    • MonitoringBundle
      • Command
      • Component
      • Controller
      • DependencyInjection
      • Entity
      • EventListener
      • Form
    • PrintBundle
      • Component
      • Controller
    • WmcBundle
      • Component
        • Exception
      • Element
        • Type
      • Entity
      • Form
        • Type
    • WmsBundle
      • Component
        • Exception
      • Controller
      • DependencyInjection
      • Element
        • Type
      • Entity
      • Event
      • Form
        • EventListener
        • Type
    • WmtsBundle
      • Component
        • Exception
      • Controller
      • Entity
      • Form
        • Type
  • None
  • PHP

Classes

  • Mapbender2UserProvider
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Todo
  • Download
 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:  * User provider for Mapbender2 databases
13:  *
14:  * @author Christian Wygoda <christian.wygoda@wheregroup.com>
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: 
Mapbender3 API documenation API documentation generated by ApiGen 2.8.0