查询 LDAP

Querying an LDAP(查询 LDAP)
本文介绍了查询 LDAP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以前没有使用过 LDAP,所以我有点迷茫.我需要连接到 LDAP 源找到特定属性并更改它.该程序的输入是一个包含用户列表的 CSV 文件.该程序应该从CSV文件中读取UID,找到LDAP中的记录并替换某个属性.我不知道如何做到这一点.谁能指出我正确的方向吗?

I haven't worked with an LDAP before so I am a bit lost. I need to connect to an LDAP source find a specific attribute and change it. The input for the program is a CSV file with a list of users. The program is supposed to read the UID from the CSV file find the record in the LDAP and replace a certain attribute. I haven't a clue how to do this. Could any one point me in the right direction please?

推荐答案

@KenL 差点把我搞定.我还必须将 DirectoryEntry 的 AuthenticationType 设置为让它工作.另外,请注意您如何使用通配符(Kleene Stars).

@KenL Almost got me there. I also had to set the AuthenticationType of the DirectoryEntry to get it to work. Also, pay attention to how you are using wildcards (Kleene Stars).

DirectoryEntry rootEntry = new DirectoryEntry("LDAP://some.ldap.server.com");
rootEntry.AuthenticationType = AuthenticationTypes.None; //Or whatever it need be
DirectorySearcher searcher = new DirectorySearcher(rootEntry);
var queryFormat = "(&(objectClass=user)(objectCategory=person)(|(SAMAccountName=*{0}*)(cn=*{0}*)(gn=*{0}*)(sn=*{0}*)(email=*{0}*)))";
searcher.Filter = string.Format(queryFormat, searchString);
foreach(SearchResult result in searcher.FindAll()) 
{
    Console.WriteLine("account name: {0}", result.Properties["samaccountname"].Count > 0 ? result.Properties["samaccountname"][0] : string.Empty);
    Console.WriteLine("common name: {0}", result.Properties["cn"].Count > 0 ? result.Properties["cn"][0] : string.Empty);
}

这篇关于查询 LDAP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)