【问题标题】:Multiple CN groups authentication with Active Directory LDAP使用 Active Directory LDAP 进行多个 CN 组身份验证
【发布时间】:2022-01-29 10:57:43
【问题描述】:

将 Active Directory 与 Spring 用于 LDAP,如果我指定搜索的确切目录(基),例如 String base="CN=Administrators" search/authentication 会找到用户,但如果传递给方法 .authenticate(String base="", filter, password),其中基是空字符串,然后找不到它并给出错误

ldapTemplate.authenticate("", MessageFormat.format("(SamAccountName={0})", login), "password")

//error
org.springframework.ldap.PartialResultException: Unprocessed Continuation Reference(s); 
nested exception is javax.naming.PartialResultException: Unprocessed Continuation Reference(s);
remaining name '/'

此外,如果我连接到 OpenLDAP 而不是 Active Directory,它允许我指定一个空字符串 LdapTemplate.authenticate(String base="", filter, password) 并找到用户。据我了解,OpenLDAP 允许搜索所有组,这正是我所需要的。

例如,我有几个 CN 组,如 CN=AdministratorsCN=FreeUsersCN=System 等,里面有很多 CN 用户。 如何在身份验证时允许 Active Directory 搜索所有这些?

【问题讨论】:

    标签: java spring active-directory ldap


    【解决方案1】:

    我通过向 LdapTemplate 添加配置解决了这个问题。现在模板在不指定基数的情况下在 AD 中查找用户。

    曾经

    @Bean
    public LdapTemplate ldapTemplate() {
        LdapTemplate ldapTemplate = new LdapTemplate(contextSource());
        return ldapTemplate;
    }
    

    现在

    @Bean
    public LdapTemplate ldapTemplate() {
        LdapTemplate ldapTemplate = new LdapTemplate(contextSource());
        ldapTemplate.setIgnorePartialResultException(true);
        return ldapTemplate;
    }
    

    【讨论】:

      【解决方案2】:

      Active Directory 不喜欢空字符串,除非搜索范围设置为 base 以发现 RootDSE。不过Active Directory 支持LDAP_SERVER_SEARCH_OPTIONS_OID control,尤其是控制值SERVER_SEARCH_FLAG_PHANTOM_ROO:

      这会启用搜索库,例如空字符串,这将导致服务器搜索它拥有的所有 NC 副本(AD DS DC 上的应用程序 NC 除外)。

      将 Spring 用于 LDAP,您可能必须从 AbstractRequestControlDirContextProcessor.java 继承。 您可以从其他控件中获得灵感 defined 并将此新控件包含在您的搜索中。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2020-07-06
        • 1970-01-01
        • 2012-09-02
        • 2020-02-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多