在我的节点应用程序中,我有一个用例,我只需要对属于特定组的LDAP用户进行身份验证。如果用户不属于上述组,则身份验证应失败。
我正在使用库ldapauth-fork进行LDAP身份验证。
我为过滤器尝试了各种方法,但它们都没有按预期工作。以下是我尝试过的尝试:
let ldapConnector = new LdapAuth (
{
url : config.ldap.url,
bindDN : config.ldap.bindDN,
adminPassword : config.ldap.adminPassword,
searchBase : config.ldap.searchBase,
searchFilter : "(&(sAMAccountName=testUser)(memberOf=testGroup))",
cache : true,
includeRaw : true,
log : logger
}
);
对于此配置,即使用户是no such user: "testuser"
组的成员,我也总是获得testGroup
。
let ldapConnector = new LdapAuth (
{
url : config.ldap.url,
bindDN : config.ldap.bindDN,
adminPassword : config.ldap.adminPassword,
searchBase : config.ldap.searchBase,
searchFilter : "(sAMAccountName=testuser)",
groupSearchFilter : "(member=testGroup)"`
cache : true,
includeRaw : true,
log : logger
}
);
对于此配置,即使组名是随机字符串,身份验证也始终成功。
那么,什么应该是正确的过滤器字符串,以使身份验证工作?
答案 0 :(得分:2)
我发现你想要在“username = x和group = y”上匹配LDAP搜索过滤器。为此,您需要为memberOf属性的值提供完全可分辨的名称。
这应该有效:
(&(sAMAccountName=testuser)(memberOf=cn=testGroup,cn=Users,DC=yourdomain,DC=yourdomainsuffix))
上面的示例假设testGroup位于Active Directory域中CN = Users的默认位置。如果它位于其他位置,请根据需要修改LDAP路径。例如,这适用于我的隔离测试域,因为我没有将GroupA组移出Users容器:
(&(sAMAccountName=Todd)(memberOf=cn=GroupA,cn=Users,DC=dev,DC=local))
EDIT(4/20/2018):在第二种情况下,根据mvreijn的评论,groupSearchFilter仅用于请求有效用户所属的组列表。它在身份验证期间不起作用。