Move getBaseDN to Entry class, some cleanup

This commit is contained in:
Deon George
2020-09-21 22:20:59 +10:00
parent 4ef074fac4
commit 2a099e2dc4
5 changed files with 126 additions and 103 deletions

View File

@@ -2,7 +2,10 @@
namespace App\Ldap;
use Illuminate\Support\Collection;
use LdapRecord\Models\Model;
use LdapRecord\Models\ModelNotFoundException;
use LdapRecord\Query\Model\Builder;
class Entry extends Model
{
@@ -13,10 +16,39 @@ class Entry extends Model
*/
public static $objectClasses = [];
public function rootDSE($connection = null)
/**
* 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
{
return static::on($connection ?? (new static)->getConnectionName())
->in(null)
->in(NULL)
->read()
->select(['+'])
->whereHas('objectclass')