protected function getBaseDn()
{
if (!empty($this->connection->getConfig()->getBaseDn())) {
$baseDn = $this->connection->getConfig()->getBaseDn();
} elseif ($this->connection->getRootDse()->has('defaultNamingContext')) {
$baseDn = $this->connection->getRootDse()->get('defaultNamingContext');
} elseif ($this->connection->getRootDse()->has('namingContexts')) {
$baseDn = $this->connection->getRootDse()->get('namingContexts')[0];
} else {
throw new LdapConnectionException('The base DN is not defined and could not be found in the RootDSE.');
}
return $baseDn;
}