AuthLDAPURL 中的更多搜索过滤器

use*_*150 5 search filter mod-auth-ldap apache-2.2

在 AuthLDAPURL 中是否可以有多个搜索过滤器?

示例 uid 过滤器:

<Location /test/>
        AuthType Basic
        AuthName "Test"
        AuthBasicProvider ldap
        AuthUserFile /dev/null
        AuthLDAPURL ldap://example.test.com/o=test,c=com?uid
        AuthLDAPBindDN "******"
        AuthLDAPBindPassword ******
        require ldap-group cn=group01,o=test,c=com
</Location>
Run Code Online (Sandbox Code Playgroud)

我们需要搜索uid或mail。喜欢...

AuthLDAPURL ldap://example.test.com/o=test,c=com?uid|mail
Run Code Online (Sandbox Code Playgroud)

解决方案(它对我有用):

使用 Apache 2.4 测试 http://httpd.apache.org/docs/current/mod/mod_authn_core.html

<AuthnProviderAlias ldap ldap-uid>
    AuthLDAPBindDN "******"
    AuthLDAPBindPassword ******
    AuthLDAPURL "ldap://example.test.com/o=test,c=com?uid??(&(isMemberOf=cn=group01,o=test,c=com))"
</AuthnProviderAlias>

<AuthnProviderAlias ldap ldap-mail>
    AuthLDAPBindDN "******"
    AuthLDAPBindPassword ******
    AuthLDAPURL "ldap://example.test.com/o=test,c=com?mail??(&(isMemberOf=cn=group01,o=test,c=com))"
</AuthnProviderAlias>


<Location "/test/">
    Order deny,allow
    Allow from all

    AuthType Basic
    AuthName "Login with mail or uid"
    AuthBasicProvider ldap-uid ldap-mail
    LDAPReferrals Off
    Require valid-user
</Location>
Run Code Online (Sandbox Code Playgroud)

谢谢托宁!

Læt*_*æti 6

我猜你的意思是寻找属性uidmail(不过滤那些)。虽然RFC 2255允许,但不可能立即在 LDAP URL 中使用 2 个不同的属性。

mod_authnz_ldap 单独:不可能

阿帕奇mod_authnz_ldap模块文件规定的URL必须像:ldap://host:port/basedn?attribute?scope?filter

  • 属性:要搜索的属性。尽管RFC 2255允许使用逗号分隔的属性列表,但无论提供多少个属性,都只会使用第一个属性。如果未提供任何属性,则默认使用 uid。最好选择一个在您将使用的子树中的所有条目中唯一的属性。
  • filter:有效的 LDAP 搜索过滤器。如果未提供,则默认为 (objectClass=*),它将搜索树中的所有对象。过滤器限制在大约 8000 个字符(Apache 源代码中 MAX_STRING_LEN 的定义)。这对于任何应用程序来说都应该绰绰有余。

将 2 个提供程序与 mod_authn_alias 一起使用

但是,添加另一个 apache 模块,即mod_authn_alias,您可以使用 2 个不同的 LDAPURL 作为不同的身份验证提供程序。为此,您可以添加一个新文件(将包含在 apache 配置的根目录中),其中包含:

# Different LDAP attributes to be used as login
<AuthnProviderAlias ldap ldap-uid>
    AuthLDAPURL ldap://example.test.com/o=test,c=com?uid
    AuthLDAPBindDN "******"
    AuthLDAPBindPassword ******
</AuthnProviderAlias>
<AuthnProviderAlias ldap ldap-mail>
    AuthLDAPURL ldap://example.test.com/o=test,c=com?mail
    AuthLDAPBindDN "******"
    AuthLDAPBindPassword ******
</AuthnProviderAlias>
Run Code Online (Sandbox Code Playgroud)

然后,在您的<Location>语句中,您使用以下配置:

<Location /test/>
    AuthType Basic
    AuthName "Test"
    AuthBasicProvider ldap-uid ldap-mail
    AuthUserFile /dev/null
    require ldap-group cn=group01,o=test,c=com
</Location>
Run Code Online (Sandbox Code Playgroud)

这将首先尝试使用 进行身份验证uid,如果失败,请尝试使用该mail属性。使用这种类型的配置,您可以根据需要添加任意多个不同的 LDAPURL 提供程序。

但是,您必须注意一件事,LDAP 搜索必须返回单个值,否则您将无法确定将使用多个条目中的哪一个来检查密码。为此,您可以使用范围(one而不是sub)或搜索过滤器来限制返回的条目数。

附加文件必须添加到您的 apache 配置<Location>或任何<VirtualHost>指令之外。它必须包含在 apache 配置的根级别。和authn_alias模块的需求被激活,当然。