2012-10-19 177 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"。如果遇到已修復的錯誤,檢查最新版本也是有意義的。