Advertisement
Guest User

Untitled

a guest
Mar 15th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.06 KB | None | 0 0
  1. services:
  2. app.ldap:
  3. class: SymfonyComponentLdapLdapClient
  4. arguments: ["ldaps://ldap.uni-rostock.de"]
  5.  
  6. app.db_user_provider:
  7. class: AppBundleSecurityDbUserProvider
  8. arguments: ["@doctrine.orm.entity_manager"]
  9.  
  10. security:
  11. role_hierarchy:
  12. ROLE_ADMIN: ROLE_USER
  13. ROLE_SUPER_ADMIN: [ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]
  14.  
  15. providers:
  16. chain_provider:
  17. chain:
  18. providers: [db_user, app_users]
  19.  
  20. in_memory:
  21. memory:
  22. users:
  23. admin: { password: adminpass, roles: 'ROLE_ADMIN' }
  24.  
  25. app_users:
  26. ldap:
  27. service: app.ldap
  28. base_dn: ou=people,o=uni-rostock,c=de
  29. search_dn: uid=testuser,ou=people,o=uni-rostock,c=de
  30. search_password: testpass
  31. filter: (uid={username})
  32. default_roles: ROLE_USER
  33.  
  34. db_user:
  35. id: app.db_user_provider
  36.  
  37. firewalls:
  38. dev:
  39. pattern: ^/(_(profiler|wdt)|css|images|js)/
  40. security: false
  41.  
  42. admin:
  43. anonymous: true
  44. pattern: ^/
  45. form_login_ldap:
  46. provider: chain_provider
  47. service: app.ldap
  48. dn_string: "uid={username},ou=people,o=uni-rostock,c=de"
  49. check_path: /login_check
  50. login_path: /login
  51. form_login:
  52. provider: in_memory
  53. check_path: /login_check
  54. login_path: /login
  55. logout:
  56. path: /logout
  57. target: /
  58.  
  59. access_control:
  60. - { path: ^/admin, roles: ROLE_USER }
  61.  
  62. encoders:
  63. SymfonyComponentSecurityCoreUserUser: plaintext
  64. AppBundleEntityEmployee: bcrypt
  65.  
  66. namespace AppBundleEntity;
  67.  
  68. use SymfonyComponentSecurityCoreUserUserInterface;
  69. use SymfonyComponentSecurityCoreUserEquatableInterface;
  70. use DoctrineORMMapping as ORM;
  71.  
  72. class Employee implements UserInterface, EquatableInterface
  73. {
  74. // other properties
  75.  
  76. private $username;
  77.  
  78. // getters and setters for the other properties
  79.  
  80. public function getUsername()
  81. {
  82. return $this->username;
  83. }
  84.  
  85. public function getRoles()
  86. {
  87. return array('ROLE_USER');
  88. }
  89.  
  90. public function getPassword()
  91. {
  92. return null;
  93. }
  94.  
  95. public function getSalt()
  96. {
  97. return null;
  98. }
  99.  
  100. public function eraseCredentials()
  101. {
  102. }
  103.  
  104. public function isEqualTo(UserInterface $user)
  105. {
  106. if (!$user instanceof Employee) {
  107. return false;
  108. }
  109.  
  110. if ($this->username !== $user->getUsername()) {
  111. return false;
  112. }
  113.  
  114. return true;
  115. }
  116. }
  117.  
  118. <?php
  119.  
  120. namespace AppBundleSecurity;
  121.  
  122. use SymfonyComponentSecurityCoreUserUserProviderInterface;
  123. use SymfonyComponentSecurityCoreUserUserInterface;
  124. use SymfonyComponentSecurityCoreExceptionUsernameNotFoundException;
  125. use SymfonyComponentSecurityCoreExceptionUnsupportedUserException;
  126. use DoctrineORMEntityManager;
  127. use AppBundleEntityEmployee;
  128.  
  129. class DbUserProvider implements UserProviderInterface
  130. {
  131. private $em;
  132.  
  133. public function __construct(EntityManager $em)
  134. {
  135. $this->em = $em;
  136. }
  137.  
  138. public function loadUserByUsername($username)
  139. {
  140. $repository = $this->em->getRepository('AppBundle:Employee');
  141. $user = $repository->findOneByUsername($username);
  142.  
  143. if ($user) {
  144. return new Employee();
  145. }
  146.  
  147. throw new UsernameNotFoundException(
  148. sprintf('Username "%s" does not exist.', $username)
  149. );
  150. }
  151.  
  152. public function refreshUser(UserInterface $user)
  153. {
  154. if (!$user instanceof Employee) {
  155. throw new UnsupportedUserException(
  156. sprintf('Instances of "%s" are not supported.', get_class($user))
  157. );
  158. }
  159.  
  160. return $this->loadUserByUsername($user->getUsername());
  161. }
  162.  
  163. public function supportsClass($class)
  164. {
  165. return $class === 'AppBundleEntityEmployee';
  166. }
  167. }
  168.  
  169. chain_provider:
  170. chain:
  171. providers: [app_users, db_user]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement