LDAP错误:用户没有足够的访问权限.:LdapErr:DSID-0C09099D,注释:处理控件时出错



我想使用C#从Active Directory获得增量更改,为此我正在尝试构建一个解决方案,如下面文章中所述(使用DirSync Control(。

https://learn.microsoft.com/en-us/windows/win32/ad/polling-for-changes-using-the-dirsync-control

然而,我面临以下问题:

  1. 当使用以下代码时,我得到了The user has insufficient access rights的异常。该用户是管理员组的一部分

还需要为该帐户授予哪些权限?如何

LdapConnection connection = new LdapConnection("adfs.fed.zzz.com");
connection.SessionOptions.ProtocolVersion = 3;
connection.Credential = new System.Net.NetworkCredential("adfsfed\username", "password");
connection.AuthType = AuthType.Basic;
connection.Bind();
var filter = "(&(objectClass=*))";
var searchRequest = new SearchRequest("", filter, SearchScope.Subtree, properties);
DirSyncRequestControl dirSyncRC = new DirSyncRequestControl(null, DirectorySynchronizationOptions.None);
searchRequest.Controls.Add(dirSyncRC);
var response = connection.SendRequest(searchRequest) as SearchResponse;
  1. 如果我使用以下代码,那么我不会得到任何异常,而是在cookie中得到空结果
String[] properties = { "objectGUID", "sAMAccountName", "displayName", "mail", "member" };
String filter = "(|(objectClass=group)(objectClass=user))";
DirectorySearcher directorySearcher = new DirectorySearcher(myLdapConnection, filter, properties);
var dSynch = new DirectorySynchronization(System.DirectoryServices.DirectorySynchronizationOptions.None); 
directorySearcher.DirectorySynchronization = dSynch;
directorySearcher.SearchScope = System.DirectoryServices.SearchScope.Subtree;
var results = directorySearcher.FindAll();
var cookie = dSynch.GetDirectorySynchronizationCookie();

注意事项:

  1. 我只有一个域控制器
  2. 我是系统管理员。因此,我可以为用户分配适当的权限

请帮忙。

•您的用户ID需要;复制目录更改";权限,并且应该是"域管理员"组的成员才能使用DirSync LDAP控制扩展。但请注意,无论标准权限如何,它几乎可以读取目录分区中的任何内容。尽管他们不能改变任何事情。

但是,您的目录中可能有一些敏感属性。请参阅下面链接中的powershell脚本,并在使用C#授予适当权限后使用用户ID执行该脚本。这是一个dirsync代码,它甚至可以检索诸如'userAccountControl、userparameters、msexchuseraccountcontrol、pwdlastset、unicodePwd(BLANK,因此不返回哈希域密码(、lockouttime、accountexpires、unixuserpassword(返回其哈希(等属性。

http://dloder.blogspot.com/2012/01/powershell-dirsync-sample.html

根据@KartikBhiwapurkar MT给出的响应,我发现了这个错误。

  1. 错误The user has insufficient access rights完全具有误导性(用户已经拥有复制目录更改权限,并且是域管理员组的一员(。System.DirectoryServices.Protocols中发生的错误是我将""作为第一个参数(distinguishedName(传递出去
new SearchRequest("", filter, SearchScope.Subtree, properties);

但它应该作为通过

new SearchRequest("DC=adfs,DC=fed,DC=zzz,DC=com", filter, SearchScope.Subtree, properties);
  1. 由于最新nuget包(6.0.0(中的错误,我在System.DirectoryServices中得到了空cookie。在编写此答案时,该错误仍然打开

对错误的引用

最新更新