【问题标题】:Spring security ldap baseDNSpring 安全 ldap baseDN
【发布时间】:2016-01-06 16:54:48
【问题描述】:

我正在尝试在我的 Spring ldap 上下文源上配置 baseDN,但它不断抛出异常:

配置如下:

<beans:bean id="contextSource" class="org.springframework.security.ldap.DefaultSpringSecurityContextSource">
        <beans:constructor-arg index="0" value="${ldap_server}"/>
        <beans:constructor-arg index="1" value="${ldap_searchbase}"/>
    </beans:bean>

我的 ldap_searchbase 中有一个空格,我查看了 Spring 代码:导致问题:

public DefaultSpringSecurityContextSource(String providerUrl) {
        Assert.hasLength(providerUrl, "An LDAP connection URL must be supplied.");

        StringTokenizer st = new StringTokenizer(providerUrl);

        ArrayList<String> urls = new ArrayList<String>();

        // Work out rootDn from the first URL and check that the other URLs (if any) match
        while (st.hasMoreTokens()) {
            String url = st.nextToken();
            String urlRootDn = LdapUtils.parseRootDnFromUrl(url);

            urls.add(url.substring(0, url.lastIndexOf(urlRootDn)));

            logger.info(" URL '" + url + "', root DN is '" + urlRootDn + "'");

            if (rootDn == null) {
                rootDn = urlRootDn;
            } else if (!rootDn.equals(urlRootDn)) {
                throw new IllegalArgumentException("Root DNs must be the same when using multiple URLs");
            }
        }

我收到“使用多个 URL 时根 DN 必须相同”错误,并且我注意到字符串标记器由空格标记,因此它正在压缩我的 baseDN 并使其成为单独的 LDAP 服务器 URL。是什么赋予了?我在这里做错了什么?

如果我这样配置,我会遇到同样的问题(显然):

<beans:bean id="contextSource" class="org.springframework.security.ldap.DefaultSpringSecurityContextSource">
        <beans:constructor-arg index="0" value="${ldap_server}/${ldap_searchbase}"/>
    </beans:bean>

【问题讨论】:

    标签: spring-security spring-security-ldap


    【解决方案1】:

    DefaultSpringSecurityContextSource 的编写方式不能像它自己一样处理空格。

    这最初是作为 ISSUE-2264 中的错误报告的。 但根据错误的 cmets,这似乎是一个已知问题,解决方案建议使用转义字符(即%20) 更多 LDAP URL 示例见:Section-3

    因此,当您定义 LDAP DN 时,请执行以下操作:

    真实网址:

    ldap://ldap.itd.umich.edu/o=University of Michigan,c=US
    

    用于 DefaultSpringSecurityContextSource 参数的更正 URL:

    ldap://ldap.itd.umich.edu/o=University%20of%20Michigan,c=US
    

    【讨论】:

    • 是空间。是否有可能对University\ of\ Michigan等角色进行转义??
    【解决方案2】:

    好的 - 所以我还没有弄清楚如何为安全上下文源提供搜索库,但是通过这样做:

    <beans:bean id="contextSource" class="org.springframework.security.ldap.DefaultSpringSecurityContextSource">
            <beans:constructor-arg index="0" value="${ldap_server}"/>
        </beans:bean>
    

    和:

    <beans:bean id="ldapUserSearch" class="org.springframework.security.ldap.search.FilterBasedLdapUserSearch">
            <beans:constructor-arg index="0" value="${ldap_searchbase}"/>
            <beans:constructor-arg index="1" value="${ldap_auth_search_filter}"/>
            <beans:constructor-arg index="2" ref="contextSource" />
        </beans:bean>
    

    它有效。

    【讨论】:

      猜你喜欢
      • 2014-02-15
      • 2011-09-22
      • 2017-07-02
      • 2020-04-14
      • 2011-03-30
      • 2019-04-03
      • 2015-01-17
      • 2017-11-10
      • 2011-05-04
      相关资源
      最近更新 更多