Remove hardcoded use of default LDAP server, added example for opendj

This commit is contained in:
Deon George 2025-01-22 15:27:52 +11:00
parent 16452ebfa9
commit 2f8d120ce8
2 changed files with 21 additions and 5 deletions

View File

@ -59,14 +59,14 @@ final class Server
* Gets the root DN of the specified LDAPServer, or throws an exception if it * Gets the root DN of the specified LDAPServer, or throws an exception if it
* can't find it. * can't find it.
* *
* @param null $connection Return a collection of baseDNs * @param string|null $connection Return a collection of baseDNs
* @param bool $objects Return a collection of Entry Models * @param bool $objects Return a collection of Entry Models
* @return Collection * @return Collection
* @throws ObjectNotFoundException * @throws ObjectNotFoundException
* @testedin GetBaseDNTest::testBaseDNExists(); * @testedin GetBaseDNTest::testBaseDNExists();
* @todo Need to allow for the scenario if the baseDN is not readable by ACLs * @todo Need to allow for the scenario if the baseDN is not readable by ACLs
*/ */
public static function baseDNs(string $connection='default',bool $objects=TRUE): Collection public static function baseDNs(string $connection=NULL,bool $objects=TRUE): Collection
{ {
$cachetime = Carbon::now() $cachetime = Carbon::now()
->addSeconds(Config::get('ldap.cache.time')); ->addSeconds(Config::get('ldap.cache.time'));
@ -360,9 +360,13 @@ final class Server
} }
// Try to get the schema DN from the specified entry. // Try to get the schema DN from the specified entry.
$schema_dn = $this->schemaDN('default'); $schema_dn = $this->schemaDN($this->connection);
$schema = $this->fetch($schema_dn); $schema = $this->fetch($schema_dn);
// If our schema's null, we didnt find it.
if (! $schema)
throw new Exception('Couldnt find schema at:'.$schema_dn);
switch ($item) { switch ($item) {
case 'attributetypes': case 'attributetypes':
Log::debug('Attribute Types'); Log::debug('Attribute Types');

View File

@ -13,7 +13,7 @@ return [
| |
*/ */
'default' => env('LDAP_CONNECTION', 'default'), 'default' => env('LDAP_CONNECTION', 'openldap'),
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
@ -28,7 +28,7 @@ return [
'connections' => [ 'connections' => [
'default' => [ 'openldap' => [
'hosts' => [env('LDAP_HOST', '127.0.0.1')], 'hosts' => [env('LDAP_HOST', '127.0.0.1')],
'username' => env('LDAP_USERNAME', 'cn=user,dc=local,dc=com'), 'username' => env('LDAP_USERNAME', 'cn=user,dc=local,dc=com'),
'password' => env('LDAP_PASSWORD', 'secret'), 'password' => env('LDAP_PASSWORD', 'secret'),
@ -40,6 +40,18 @@ return [
'name' => env('LDAP_NAME','LDAP Server'), 'name' => env('LDAP_NAME','LDAP Server'),
], ],
'opendj' => [
'hosts' => ['opendj'],
'username' => 'cn=Directory Manager',
'password' => 'password',
'port' => 1389,
'base_dn' => 'dc=example,dc=com',
'timeout' => env('LDAP_TIMEOUT', 5),
'use_ssl' => env('LDAP_SSL', false),
'use_tls' => env('LDAP_TLS', false),
'name' => 'OpenDJ Server',
],
], ],
/* /*