diff --git a/src/CommonLib/LDAPUtils.cs b/src/CommonLib/LDAPUtils.cs index bb757da8..7804ad4d 100644 --- a/src/CommonLib/LDAPUtils.cs +++ b/src/CommonLib/LDAPUtils.cs @@ -1702,18 +1702,30 @@ private class ResolvedWellKnownPrincipal public string GetConfigurationPath(string domainName = null) { - var rootDse = domainName == null - ? new DirectoryEntry("LDAP://RootDSE") - : new DirectoryEntry($"LDAP://{NormalizeDomainName(domainName)}/RootDSE"); + string path = domainName == null + ? "LDAP://RootDSE" + : $"LDAP://{NormalizeDomainName(domainName)}/RootDSE"; + + DirectoryEntry rootDse; + if (_ldapConfig.Username != null) + rootDse = new DirectoryEntry(path, _ldapConfig.Username, _ldapConfig.Password); + else + rootDse = new DirectoryEntry(path); return $"{rootDse.Properties["configurationNamingContext"]?[0]}"; } public string GetSchemaPath(string domainName) { - var rootDse = domainName == null - ? new DirectoryEntry("LDAP://RootDSE") - : new DirectoryEntry($"LDAP://{NormalizeDomainName(domainName)}/RootDSE"); + string path = domainName == null + ? "LDAP://RootDSE" + : $"LDAP://{NormalizeDomainName(domainName)}/RootDSE"; + + DirectoryEntry rootDse; + if (_ldapConfig.Username != null) + rootDse = new DirectoryEntry(path, _ldapConfig.Username, _ldapConfig.Password); + else + rootDse = new DirectoryEntry(path); return $"{rootDse.Properties["schemaNamingContext"]?[0]}"; }