DirectoryTree / LdapRecord

A fully-featured LDAP framework.
https://ldaprecord.com
MIT License
512 stars 44 forks source link

User::findBy() doesn't work, but $connection->query()->findByOrFail() does #729

Closed gabrielhmsantos closed 3 months ago

gabrielhmsantos commented 3 months ago

Environment:

LDAP Server Type: ActiveDirectory PHP Version: 8.2.4 LDAPS: true

Describe the bug:

I'm having a problem when trying to use the search for ActiveDirectory with User::findBy(), laravel returns me:

ldap_search(): Search: Can't contact LDAP server

But if I use $connection->query()->findByOrFail() it normally searches for information from AD users.

What I can say about my environment is that it is an EntraID replication environment, does this affect how LdapRecord handles information?

If it's something related to the model, how can I "remap" the model to ActiveDirectory?

stevebauman commented 3 months ago

Hi @gabrielhmsantos,

Have you added the same connection instance into the Container?

https://ldaprecord.com/docs/core/v3/connections#container

use LdapRecord\Container;
use LdapRecord\Connection;

$connection = new Connection([
    // ...
]);

$connection->connect();

Container::addConnection($connection);

Also, are you using the Laravel integration, or just the core LdapRecord framework?

gabrielhmsantos commented 3 months ago

Thank you very much, as I am developing an application that fetches connection data from the DB, it does not use the .env which is clean (the Ldap variables), and that is why I was not connecting to the Default Container.

To resolve this, I created a /default endpoint that defines the Container according to the AD aliases

stevebauman commented 3 months ago

Great, glad you're up and running @gabrielhmsantos! Happy to help 👍