【问题标题】:LDAP authentication using Spring security 2.0.3使用 Spring security 2.0.3 的 LDAP 身份验证
【发布时间】:2012-10-10 03:24:18
【问题描述】:

我正在尝试使用 spring security 2.0.3 进行 LDAP 身份验证

这是我的配置

<bean id="contextSource" class="org.springframework.security.ldap.DefaultSpringSecurityContextSource">
        <constructor-arg value="ldap://IP:3268"/>
        <property name="base" value="dc=alliance",dc=com,OU=Users,OU=India"/>
        <property name="userDn" value="sAMAccountName=username" />
        <property name="password" value="password" />
    </bean>



    <bean id="ldapProvider" class="org.springframework.security.providers.ldap.LdapAuthenticationProvider">
        <sec:custom-authentication-provider/>
        <constructor-arg>
            <bean class="org.springframework.security.providers.ldap.authenticator.BindAuthenticator">
                <constructor-arg ref="contextSource"/>
                <!--<property name="userSearch" ref="ldapSearchBean"/>-->
                <property name="userDnPatterns">
                   <list><value>sAMAccountName={0}</value></list>
                 </property>
            </bean>
        </constructor-arg>
        <constructor-arg>
            <bean class="org.springframework.security.ldap.populator.DefaultLdapAuthoritiesPopulator">
                <constructor-arg ref="contextSource"/>
                <constructor-arg value="ou=groups"/>
                <property name="groupSearchFilter" value="member={0}"/>
                <property name="groupRoleAttribute" value="ou"/>
                <property name="rolePrefix" value="ROLE_"/>
                <property name="searchSubtree" value="true"/>
                <property name="convertToUpperCase" value="true"/>
            </bean>
        </constructor-arg>
    </bean>

Maven入口集如下

<dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-core</artifactId>
            <version>2.0.3</version>
            <exclusions>
                <exclusion>
                    <groupId>commons-logging</groupId>
                    <artifactId>commons-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
<dependency>
            <groupId>org.springframework.ldap</groupId>
            <artifactId>spring-ldap</artifactId>
            <version>1.2.1</version>
        </dependency>

我得到的例外是

[BindAuthenticator,2329165@qtp-24103634-0] - 无法绑定为 sAMAccountName=csepena:org.springframework.ldap.AuthenticationException:[LDAP:错误代码 49 - 80090308:LdapErr:DSID-0C090334,注释:AcceptSecurityContext 错误, 数据 525, vece

我应该在哪里提到域名?

【问题讨论】:

    标签: active-directory spring-security ldap spring-ldap


    【解决方案1】:

    如果您在网上搜索错误消息,您会发现类似this page of Active Directory errors 的内容,它在顶部列出了您的错误:

    Common Active Directory LDAP bind errors:
    
    80090308: LdapErr: DSID-0C09030B, comment: AcceptSecurityContext error, data 525, v893
    HEX: 0×525 – user not found
    DEC: 1317 – ERROR_NO_SUCH_USER (The specified account does not exist.)
    NOTE: Returns when username is invalid.
    

    所以根据 AD,用户不存在。您已尝试将 sAMAccountName 属性用作 DN 模式的一部分,但由于它是 LDAP 属性,因此无法正常工作。您需要使用搜索首先通过此属性的值定位用户。本网站和网络上的其他地方有关于如何做到这一点的示例。看起来您已经尝试过了,因为您注释掉了一个搜索 bean。如果这不起作用,您应该解释您的问题出了什么问题。

    事实上,它似乎很可能失败,因为您的上下文源有一些问题。 userDn property 的值是错误的。它必须是目录中的有效专有名称,“sAMAccountName=username”不是。 “base”属性看起来也不正确。它通常应该是根(dc=mycompany,dc=com 位于末尾)的树。所以应该是ou=mygroup,ou=mycountry,dc=mycompany,dc=com

    最后,您不应该使用 2.0.3 版。它有已知的安全漏洞。始终与您正在使用的库的补丁和新版本保持同步 - number 6 in the OWASP "top ten"。检查最新版本也很有意义,以防遇到已修复的错误。

    【讨论】:

      猜你喜欢
      • 2016-09-09
      • 2012-02-18
      • 2016-09-01
      • 2018-08-09
      • 2013-05-08
      • 2015-10-20
      • 2012-11-18
      • 2013-01-11
      • 2016-08-05
      相关资源
      最近更新 更多