2012-10-19 181 views
0

我试图用弹簧安全2.0.3LDAP身份验证春季安全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

我应该在哪里提及域名?

回答

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”不是。 “基本”属性也看起来不正确。它通常应该是一棵树,根(dc=mycompany,dc=com在最后)。所以它应该可能是ou=mygroup,ou=mycountry,dc=mycompany,dc=com

最后,你不应该使用2.0.3版本。它有已知的安全漏洞。始终及时了解您正在使用的补丁和新版本库 - number 6 in the OWASP "top ten"。如果遇到已修复的错误,检查最新版本也是有意义的。