2020-09-13 13:41:26 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Ldap;
|
|
|
|
|
2020-09-21 12:20:59 +00:00
|
|
|
use Illuminate\Support\Collection;
|
2020-09-13 13:41:26 +00:00
|
|
|
use LdapRecord\Models\Model;
|
2020-09-21 12:20:59 +00:00
|
|
|
use LdapRecord\Models\ModelNotFoundException;
|
|
|
|
use LdapRecord\Query\Model\Builder;
|
2020-09-13 13:41:26 +00:00
|
|
|
|
|
|
|
class Entry extends Model
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* The object classes of the LDAP model.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
public static $objectClasses = [];
|
2020-09-18 14:08:00 +00:00
|
|
|
|
2020-09-21 12:20:59 +00:00
|
|
|
/**
|
|
|
|
* Gets the root DN of the specified LDAPServer, or throws an exception if it
|
|
|
|
* can't find it.
|
|
|
|
*
|
|
|
|
* @param null $connection
|
|
|
|
* @return Collection
|
|
|
|
* @throws ModelNotFoundException
|
|
|
|
* @testedin GetBaseDNTest::testBaseDNExists();
|
|
|
|
*/
|
|
|
|
public function baseDN($connection = NULL): ?Collection
|
|
|
|
{
|
|
|
|
$base = static::on($connection ?? (new static)->getConnectionName())
|
|
|
|
->in(NULL)
|
|
|
|
->read()
|
|
|
|
->select(['namingcontexts'])
|
|
|
|
->whereHas('objectclass')
|
|
|
|
->firstOrFail();
|
|
|
|
|
|
|
|
return $base->namingcontexts ? collect($base->namingcontexts) : NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Obtain the rootDSE for the server, that gives us server information
|
|
|
|
*
|
|
|
|
* @param null $connection
|
|
|
|
* @return Entry|null
|
|
|
|
* @throws ModelNotFoundException
|
|
|
|
* @testedin TranslateOidTest::testRootDSE();
|
|
|
|
*/
|
|
|
|
public function rootDSE($connection = NULL): ?Entry
|
2020-09-18 14:08:00 +00:00
|
|
|
{
|
|
|
|
return static::on($connection ?? (new static)->getConnectionName())
|
2020-09-21 12:20:59 +00:00
|
|
|
->in(NULL)
|
2020-09-18 14:08:00 +00:00
|
|
|
->read()
|
|
|
|
->select(['+'])
|
|
|
|
->whereHas('objectclass')
|
|
|
|
->firstOrFail();
|
|
|
|
}
|
2020-09-13 13:41:26 +00:00
|
|
|
}
|