LdapFactory.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Bundle\SecurityBundle\DependencyInjection\Security\UserProvider;
  11. use Symfony\Component\Config\Definition\Builder\NodeDefinition;
  12. use Symfony\Component\DependencyInjection\ContainerBuilder;
  13. use Symfony\Component\DependencyInjection\DefinitionDecorator;
  14. use Symfony\Component\DependencyInjection\Reference;
  15. /**
  16. * LdapFactory creates services for Ldap user provider.
  17. *
  18. * @author Grégoire Pineau <lyrixx@lyrixx.info>
  19. * @author Charles Sarrazin <charles@sarraz.in>
  20. */
  21. class LdapFactory implements UserProviderFactoryInterface
  22. {
  23. public function create(ContainerBuilder $container, $id, $config)
  24. {
  25. $container
  26. ->setDefinition($id, new DefinitionDecorator('security.user.provider.ldap'))
  27. ->replaceArgument(0, new Reference($config['service']))
  28. ->replaceArgument(1, $config['base_dn'])
  29. ->replaceArgument(2, $config['search_dn'])
  30. ->replaceArgument(3, $config['search_password'])
  31. ->replaceArgument(4, $config['default_roles'])
  32. ->replaceArgument(5, $config['uid_key'])
  33. ->replaceArgument(6, $config['filter'])
  34. ;
  35. }
  36. public function getKey()
  37. {
  38. return 'ldap';
  39. }
  40. public function addConfiguration(NodeDefinition $node)
  41. {
  42. $node
  43. ->children()
  44. ->scalarNode('service')->isRequired()->cannotBeEmpty()->end()
  45. ->scalarNode('base_dn')->isRequired()->cannotBeEmpty()->end()
  46. ->scalarNode('search_dn')->end()
  47. ->scalarNode('search_password')->end()
  48. ->arrayNode('default_roles')
  49. ->beforeNormalization()->ifString()->then(function ($v) { return preg_split('/\s*,\s*/', $v); })->end()
  50. ->requiresAtLeastOneElement()
  51. ->prototype('scalar')->end()
  52. ->end()
  53. ->scalarNode('uid_key')->defaultValue('sAMAccountName')->end()
  54. ->scalarNode('filter')->defaultValue('({uid_key}={username})')->end()
  55. ->end()
  56. ;
  57. }
  58. }