Description
Description
When using the Ldap component of Symfony 3.1, binding an LdapClient results in an UndefinedOptionsException.
You can easily reproduce this bug by doing this
$client = new \Symfony\Component\Ldap\LdapClient('your-ldap-host');
$client->bind(); // Throws UndefinedOptionsException
What is happening
When creating an instance of LdapClient, a configuration is created using the arguments of the constructor
// Symfony/Component/Ldap/LdapClient.php
// __constructor($host = null, $port = 389, $version = 3, $useSsl = false, $useStartTls = false, $optReferrals = false, LdapInterface $ldap = null)
$config = array(
'host' => $host,
'port' => $port,
'version' => $version,
'useSsl' => (bool) $useSsl,
'useStartTls' => (bool) $useStartTls,
'optReferrals' => (bool) $optReferrals,
);
and an instance of Ldap is automatically created
// Symfony/Component/Ldap/LdapClient.php
// __constructor($host = null, $port = 389, $version = 3, $useSsl = false, $useStartTls = false, $optReferrals = false, LdapInterface $ldap = null)
$this->ldap = null !== $ldap ? $ldap : Ldap::create('ext_ldap', $config);
Which results in instanciating a new Symfony\Component\Ldap\Adapter\ExtLdap\Adapter using the configuration defined above
// Symfony/Component/Ldap/Ldap.php
private static $adapterMap = array(
'ext_ldap' => 'Symfony\Component\Ldap\Adapter\ExtLdap\Adapter',
);
// Symfony/Component/Ldap/Ldap.php
// create($adapter, array $config = array()) method
$class = self::$adapterMap[$adapter];
return new self(new $class($config));
Then when calling the bind() method of the LdapClient, which call the bind() method of the Ldap, which call the getConnection() method of the Adapter, it results in instanciating a new Symfony\Component\Ldap\Adapter\ExtLdap\Connection using the configuration defined above
But this Connection defines its own configuration format
// Symfony/Component/Ldap/Adapter/AbstractConnection.php
// configureOptions(OptionsResolver $resolver) method
$resolver->setAllowedTypes('host', 'string');
$resolver->setAllowedTypes('port', 'numeric');
$resolver->setAllowedTypes('connection_string', 'string');
$resolver->setAllowedTypes('version', 'numeric');
$resolver->setAllowedValues('encryption', array('none', 'ssl', 'tls'));
$resolver->setAllowedTypes('options', 'array');
Which does not match the original configuration defined in the LdapClient, resulting in a UndefinedOptionsException when the OptionResolver tries to resolve the given configuration.