【问题标题】:Authenticate LDAP user if he's a part of a specific group如果 LDAP 用户属于特定组,则对他进行身份验证
【发布时间】:2018-04-18 16:11:38
【问题描述】:

在我的节点应用程序中,我有一个用例,我只需要对属于特定组的 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
    }
);

对于这种配置,认证总是成功的,即使组名是一个随机字符串。

那么,使身份验证工作的正确过滤字符串应该是什么?

【问题讨论】:

  • 您使用的是 Microsoft Active Directory、OpenLDAP 还是其他?
  • @T-Heron 我正在使用 Microsoft Active Directory。

标签: javascript node.js ldap ldap-query ldapauth


【解决方案1】:

我看到您希望对“用户名 = x 和组 = y”进行 LDAP 搜索过滤器匹配。为此,您需要为 memberOf 属性的值提供一个完全可分辨的名称。

这应该可行:

(&(sAMAccountName=testuser)(memberOf=cn=testGroup,cn=Users,DC=yourdomain,DC=yourdomainsuffix))

以上示例假定 testGroup 位于 Active Directory 域中 CN=Users 的默认位置。如果它位于其他位置,请根据需要修改 LDAP 路径。例如,这适用于我的隔离测试域,因为我没有将 GroupA 组移出用户容器:

(&(sAMAccountName=Todd)(memberOf=cn=GroupA,cn=Users,DC=dev,DC=local))

编辑(2018 年 4 月 20 日):在第二种情况下,根据 mvreijn 的评论,groupSearchFilter 仅用于请求有效用户所属的组列表。它在身份验证期间不起作用。

【讨论】:

  • groupSearchFilter 仅用于请求有效用户所属的组列表。它在身份验证期间不起作用。
  • @mvreijn - +1 给你!不错。
  • 我错过了我小组的完整路径。谢谢@T-Heron :)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-07-13
  • 2012-07-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-08-23
  • 2021-09-02
相关资源
最近更新 更多