簡體   English   中英

使用 Novell.Directory.Ldap.NETStandard 在 LDAP 中獲取用戶組

[英]Getting user group in LDAP using Novell.Directory.Ldap.NETStandard

我有使用 Novell.Directory.Ldap.NETStandard 和 F# 獲取用戶詳細信息的簡單服務(如果有必要,我可以提供 c# 的成績單,但這部分非常相似),它看起來像這樣:

use connection = new LdapConnection();
connection.Connect(credentials.host, LdapConnection.DefaultPort);
connection.Bind($"{credentials.domain}\{credentials.username}", credentials.password);
match connection.Connected with
| true ->   
    let schema = connection.FetchSchema((connection.GetSchemaDn()));
    let filter = $"(SAMAccountName={credentials.username})"
    let searcher = connection.Search(String.Empty, LdapConnection.ScopeBase, filter, null, false);
    return (searcher |> Some, String.Empty)

| false -> 
    raise (Exception()) 
    return (None, $"Cannot connect to domain {credentials.domain} with user {credentials.username}")

現在我找不到有關該用戶分配給的組的信息,通常當我使用 Directory.Service 時,我只需添加:

directorySearcher.Filter <- sprintf "(SAMAccountName=%s)"credentials.username

對於目錄搜索者,我可以過濾掉這些信息(因為 Directory.Service 是 windows 受限的,我不能在這個項目中使用它),但是我找不到任何關於如何在 Novell.Directory.Ldap 中使用它的信息。

在調用Search()時,您必須提供所需的屬性(即memberOf以讀取用戶組)作為字符串數組而不是null

let attrs = [| "SAMAccountName"; "memberOf"; |];
let searcher = connection.Search(searchbase, scope, filter, attrs, false);

您還可以通過"*"來獲取所有非操作屬性。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM