DirectoryTree / LdapRecord-Laravel

Multi-domain LDAP Authentication & Management for Laravel.
https://ldaprecord.com/docs/laravel/v3
MIT License
496 stars 52 forks source link

[Bug] Base DN empty #436

Closed TheSoulGamer158 closed 2 years ago

TheSoulGamer158 commented 2 years ago

Environment:

Describe the bug: I can connect to the LDAP Server but can't find any entries. I guess it's because of the empty dn (logs attached from dd(\LDAPRecord\Models\Entry::read()->first());.

^ LdapRecord\Models\Entry {#315 ▼
  +exists: true
  +wasRecentlyCreated: false
  +wasRecentlyRenamed: false
  #dn: ""
  #in: null
  #connection: null
  #guidKey: "objectguid"
  #modifications: []
  #original: array:1 [▶]
  #attributes: array:1 [▼
    "objectclass" => array:2 [▼
      0 => "top"
      1 => "OpenLDAProotDSE"
    ]
  ]
  #dates: []
  #casts: []
  #appends: []
  #dateFormat: null
  #defaultDates: array:2 [▶]
  #hidden: []
  #visible: []
}

My .env looks like this:

LDAP_LOGGING=true
LDAP_CONNECTION=default
LDAP_CONNECTIONS=default

LDAP_DEFAULT_HOSTS=localhost
LDAP_DEFAULT_USERNAME="cn=admin,dc=ahdrive,dc=local"
LDAP_DEFAULT_PASSWORD=adminpassword
LDAP_DEFAULT_PORT=1389
LDAP_BASE_DN="OU=users,DC=ahdrive,DC=local"
LDAP_DEFAULT_TIMEOUT=5
LDAP_DEFAULT_SSL=false
LDAP_DEFAULT_TLS=false

And my ldap.php

 'connections' => [

        'default' => [
            'hosts' => [env('LDAP_HOST', '127.0.0.1')],
            'username' => env('LDAP_USERNAME', 'cn=user,dc=local,dc=com'),
            'password' => env('LDAP_PASSWORD', 'secret'),
            'port' => env('LDAP_PORT', 389),
            'base_dn' => env('LDAP_BASE_DN', 'dc=ahdrive,dc=local'),
            'timeout' => env('LDAP_TIMEOUT', 5),
            'use_ssl' => env('LDAP_SSL', false),
            'use_tls' => env('LDAP_TLS', false),
        ],

    ],
stevebauman commented 2 years ago

Hi @TheSoulGamer158,

It looks like you're configuring your connections in two ways. The published configuration file, and using an .env file, shown here:

Important: It's recommended to only use one approach listed in this guide below. Using both approaches to configure your LDAP connections may lead to unexpected results.

https://ldaprecord.com/docs/laravel/v2/configuration#configuration

Since you've published the configuration file, here is what your .env should look like:

LDAP_LOGGING=true
LDAP_CONNECTION=default

LDAP_HOST=localhost
LDAP_USERNAME="cn=admin,dc=ahdrive,dc=local"
LDAP_PASSWORD=adminpassword
LDAP_PORT=1389
LDAP_BASE_DN="OU=users,DC=ahdrive,DC=local"
LDAP_TIMEOUT=5
LDAP_SSL=false
LDAP_TLS=false

This should resolve your issue.

TheSoulGamer158 commented 2 years ago

OMG I searched so loooong for just a small change... I thank you so much that you answered that fast. Would love to support you when I'm back home :)

stevebauman commented 2 years ago

Happy to help @TheSoulGamer158, thanks for your kind words 😄