LdapRecord: Initial connection failover to subsequent hosts

Environment (please complete the following information):

  • LDAP Server Type: ActiveDirectory
  • PHP: v7.4.12
  • Laravel: v6
  • directorytree/ldaprecord v2.0.3
  • directorytree/ldaprecord-laravel v2.0.1

I have multiple ldap hosts servers. The hosts IP address is passed as an Array. If the first connection fails, I would like you to start the second validation.

However, it does not work as expected. Even if hosts is passed as an Array, an error will be returned if the first validation fails.

i tried it.

  • .env
LDAP_HOST=0.0.0.1,0.0.0.2
  • config/ldap.php
'connections' => [
        'default' => [
            'hosts' => array_map('trim', explode(',', env('LDAP_HOST', '127.0.0.1'))), // I modified it here

However, in reality, the first array is used for processing. So I edited \directorytree\ldaprecord\src\Connection.php

public function __construct($config = [], Ldap $ldap = null)
    {
        $this->configuration = new DomainConfiguration($config);

        $this->hosts = $this->configuration->get('hosts');

        //$this->host = reset($this->hosts); 
        $this->host = $this->hosts; // I modified it here

        $this->setLdapConnection($ldap ?? new Ldap());
    }

Please let me know if there is another good way. Thanks.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 2
  • Comments: 31 (15 by maintainers)

Commits related to this issue

Most upvoted comments

LdapRecord-Laravel v2.1.0 has just been released with all these fixes 🎉

Thanks for your help debugging this @LunaTakaishi! ❤️

Hi @LunaTakaishi,

A new release has just been pushed (v2.1.0).

However, while this has resolved the issue in the LdapRecord core repository, I have to make a small update to the LdapRecord-Laravel repo as well so it utilizes the fallback properly.

I’ll have this new version of LdapRecord-Laravel out tomorrow and I’ll post back here once done. 🎉

Hi @LunaTakaishi,

Thanks for posting all of that detail – I’m now able to reproduce this using LdapRecord-Laravel and attempting to log users in.

This is due to the LdapUserAuthenticator calling the auth()->attempt() method explicitly, which isn’t set up to failover to another host… I’ll have to see if there’s an implementation I can use to resolve this. 👍

That’s bizarre… Can you post how you’re utilizing LdapRecord in your application? Or does this occur when you’re trying to authenticate users?