繁体   English   中英

如何使用 System.DirectoryServices 在 Apache Directory Studio 上搜索 LDAP 用户数据?

[英]How to do a search of LDAP user data on Apache Directory Studio with System.DirectoryServices?

我连接到 Apache Directory Studio 的 LDAP 服务器上,并使用他的凭据绑定用户,但现在我想获取他自己的数据,如邮件、电话号码等。如何在 System.DirectoryServices 中做到这一点? 这是我到目前为止所做的事情?

LdapDirectoryIdentifier id= new LdapDirectoryIdentifier("localhost", 10389);
                LdapConnection conn=
                    new LdapConnection(id);
                var username= text_field_for_username.Text;
                var pass= text_field_for_pass.Text;
                conn.AuthType = AuthType.Basic;
                conn.SessionOptions.ProtocolVersion = 3;
                NetworkCredential param= new NetworkCredential("uid="+username+",ou=employees,dc=company,dc=com",pass);
conn.Bind(param);

它奏效了。 现在,如何使用 System.DirectoryServices 获取经过身份验证的用户的数据? 顺便说一句,我知道不存在用户的可能性,我将为此添加 try 和 catch 块。

基本上,您可以使用 DirectoryServices SearchRequestSearchResponse执行以下操作:

// ...

// Just for convenience 
conn.Credential = new NetworkCredential(userDN, userPass);
conn.Bind();

// The attributes to read, use "*" to request all user attributes.
var attr = new[] { "uid", "displayName", "mail" };

// Set userDN as basedn and search scope to Base to search user's own entry (filter is null)
SearchRequest req = new SearchRequest(userDN, (string) null, SearchScope.Base, attr);
var response = (SearchResponse) conn.SendRequest(req);

var entry = response.Entries[0];
// ... 

请参阅文档: SearchRequestSearchResponse

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM