HttpBasicLdapFactory.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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\Factory;
  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. * HttpBasicFactory creates services for HTTP basic authentication.
  17. *
  18. * @author Fabien Potencier <fabien@symfony.com>
  19. * @author Grégoire Pineau <lyrixx@lyrixx.info>
  20. * @author Charles Sarrazin <charles@sarraz.in>
  21. */
  22. class HttpBasicLdapFactory extends HttpBasicFactory
  23. {
  24. public function create(ContainerBuilder $container, $id, $config, $userProvider, $defaultEntryPoint)
  25. {
  26. $provider = 'security.authentication.provider.ldap_bind.'.$id;
  27. $container
  28. ->setDefinition($provider, new DefinitionDecorator('security.authentication.provider.ldap_bind'))
  29. ->replaceArgument(0, new Reference($userProvider))
  30. ->replaceArgument(1, new Reference('security.user_checker.'.$id))
  31. ->replaceArgument(2, $id)
  32. ->replaceArgument(3, new Reference($config['service']))
  33. ->replaceArgument(4, $config['dn_string'])
  34. ;
  35. // entry point
  36. $entryPointId = $this->createEntryPoint($container, $id, $config, $defaultEntryPoint);
  37. // listener
  38. $listenerId = 'security.authentication.listener.basic.'.$id;
  39. $listener = $container->setDefinition($listenerId, new DefinitionDecorator('security.authentication.listener.basic'));
  40. $listener->replaceArgument(2, $id);
  41. $listener->replaceArgument(3, new Reference($entryPointId));
  42. return array($provider, $listenerId, $entryPointId);
  43. }
  44. public function addConfiguration(NodeDefinition $node)
  45. {
  46. parent::addConfiguration($node);
  47. $node
  48. ->children()
  49. ->scalarNode('service')->end()
  50. ->scalarNode('dn_string')->defaultValue('{username}')->end()
  51. ->end()
  52. ;
  53. }
  54. public function getKey()
  55. {
  56. return 'http-basic-ldap';
  57. }
  58. }