【发布时间】:2017-11-06 14:14:03
【问题描述】:
我想知道如何获取 AD 组的成员列表。
检查用户输入的密码是否正确可以正常工作。为此,我使用的是 Novell 的 Ldap.NetStandard:
private bool IsUserValid(string userName,string userPassword)
{
try{
using (var connection = new LdapConnection { SecureSocketLayer = false })
{
connection.Connect("test.local", LdapConnection.DEFAULT_PORT);
connection.Bind(userDn, userPassword);
if (connection.Bound)
{
return true;
}
}
}
catch (LdapException ex)
{
Console.WriteLine(ex.Massage);
}
return false;
}
我现在想要的是这样的:
bool isUserInGroup("testUser","testGroup");
问题是我的方法无法正常工作:
public bool IsUserMemberOfGroup(string userName,string groupName)
{
var ldapConn = GetConnection();
var searchBase = "";
var filter = $"(&(objectClass=group)(cn={groupName}))";
var search = ldapConn.Search(searchBase, LdapConnection.SCOPE_BASE, filter, null, false);
while (search.hasMore())
{
var nextEntry = search.next();
if (nextEntry.DN == userName)
return true;
}
return false;
}
无论我在做什么,我都没有从我的Ldap.Search() 那里获得任何价值...
【问题讨论】:
-
不要在开始搜索前先指定搜索库?即
var searchBase = "DC=test,DC=local"; -
@DavidLiang 也尝试过。结果还是一样……
-
aww 要知道发生了什么并不容易,因为我不能过多询问您的 AD 设置。我可以告诉你我的设置是什么。请看我的回答here。
-
@DavidLiang 非常感谢,我会看看!
标签: asp.net asp.net-mvc asp.net-core active-directory ldap