簡體   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