JsonLoginLdapFactory.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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\ChildDefinition;
  13. use Symfony\Component\DependencyInjection\ContainerBuilder;
  14. use Symfony\Component\DependencyInjection\Reference;
  15. use Symfony\Component\Security\Core\Exception\LogicException;
  16. /**
  17. * JsonLoginLdapFactory creates services for json login ldap authentication.
  18. *
  19. * @internal
  20. */
  21. class JsonLoginLdapFactory extends JsonLoginFactory
  22. {
  23. use LdapFactoryTrait;
  24. public function getKey()
  25. {
  26. return 'json-login-ldap';
  27. }
  28. protected function createAuthProvider(ContainerBuilder $container, string $id, array $config, string $userProviderId)
  29. {
  30. $provider = 'security.authentication.provider.ldap_bind.'.$id;
  31. $definition = $container
  32. ->setDefinition($provider, new ChildDefinition('security.authentication.provider.ldap_bind'))
  33. ->replaceArgument(0, new Reference($userProviderId))
  34. ->replaceArgument(1, new Reference('security.user_checker.'.$id))
  35. ->replaceArgument(2, $id)
  36. ->replaceArgument(3, new Reference($config['service']))
  37. ->replaceArgument(4, $config['dn_string'])
  38. ->replaceArgument(6, $config['search_dn'])
  39. ->replaceArgument(7, $config['search_password'])
  40. ;
  41. if (!empty($config['query_string'])) {
  42. if ('' === $config['search_dn'] || '' === $config['search_password']) {
  43. throw new LogicException('Using the "query_string" config without using a "search_dn" and a "search_password" is not supported.');
  44. }
  45. $definition->addMethodCall('setQueryString', [$config['query_string']]);
  46. }
  47. return $provider;
  48. }
  49. public function addConfiguration(NodeDefinition $node)
  50. {
  51. parent::addConfiguration($node);
  52. $node
  53. ->children()
  54. ->scalarNode('service')->defaultValue('ldap')->end()
  55. ->scalarNode('dn_string')->defaultValue('{username}')->end()
  56. ->scalarNode('query_string')->end()
  57. ->scalarNode('search_dn')->defaultValue('')->end()
  58. ->scalarNode('search_password')->defaultValue('')->end()
  59. ->end()
  60. ;
  61. }
  62. }