LDAP - Force protocol LDAPv3

On Linux, php-ldap seems to rely on a library which still uses deprecated LDAPv2 as default version,
causing authentication issues.

See: https://stackoverflow.com/a/48238224/1484919
This commit is contained in:
ArthurHoaro 2020-06-25 16:18:25 +02:00
parent a69cfe0dd2
commit 8694e8411b

View file

@ -204,12 +204,20 @@ class LoginManager
*/
public function checkCredentialsFromLdap($login, $password, $connect = null, $bind = null)
{
$connect = $connect ?? function($host) { return ldap_connect($host); };
$bind = $bind ?? function($handle, $dn, $password) { return ldap_bind($handle, $dn, $password); };
$connect = $connect ?? function($host) {
$resource = ldap_connect($host);
ldap_set_option($resource, LDAP_OPT_PROTOCOL_VERSION, 3);
return $resource;
};
$bind = $bind ?? function($handle, $dn, $password) {
return ldap_bind($handle, $dn, $password);
};
return $bind(
$connect($this->configManager->get('ldap.host')),
sprintf($this->configManager->get('ldap.dn'), $login),
sprintf($this->configManager->get('ldap.dn'), $login),
$password
);
}