2017-04-19 71 views
1

您好我正在使用Spring Boot,並試圖從活動目錄中使用spring security進行用戶身份驗證。但我無法登錄用戶到我已經試了好東西,這裏的應用是我試過的代碼:我試圖實現從hereSpring安全無法通過LDAP身份驗證登錄

和錯誤的例子

@Override 
    public void configure(AuthenticationManagerBuilder auth) throws Exception { 
     auth 
      .ldapAuthentication() 
       .userDnPatterns("uid={0},ou=Users") 
       .groupSearchBase("ou=groups") 
       .contextSource(contextSource()) 
       .passwordCompare() 
        .passwordEncoder(new LdapShaPasswordEncoder()) 
        .passwordAttribute("userPassword"); 
    } 

    @Bean 
    public DefaultSpringSecurityContextSource contextSource() { 
     return new DefaultSpringSecurityContextSource(Arrays.asList("ldap://WIN-BSCF2478SL5.Adexample.com"), "CN=Administrator,DC=ADExample,DC=com"); 
    } 

我在嘗試從管理員登錄時得到以下內容:

原因:LDAP處理期間發生未分類異常;嵌套異常是javax.naming.NamingException:[LDAP:錯誤代碼1 - 000004DC:LdapErr:DSID-0C0906E8,註釋:爲了執行此操作,必須在連接上完成成功的綁定,數據0,v1db1]。剩餘名稱爲'uid =管理員,OU =用戶的

我還試圖用的,而不是userDnPatterns userSearchFilter但仍然得到了這裏的例外是代碼

auth.ldapAuthentication().userSearchFilter("uid={0}").contextSource() 
       .url("ldap://WIN-BSCF2478SL5.Adexample.com/DC=ADExample,DC=com").managerDn("Administrator") 
       .managerPassword("Passw0rd"); 

,並從這個代碼例外,我得到的是如下: 例外我得到:原因:[LDAP:錯誤代碼49 - 80090308:LdapErr:DSID-0C0903A9,註釋:AcceptSecurityContext錯誤,數據52e,v1db1];嵌套的異常是javax.naming.AuthenticationException:[LDAP:錯誤代碼49 - 80090308:LdapErr:DSID-0C0903A9,評論:AcceptSecurityContext錯誤,數據52e,v1db1]

並且最後我還嘗試不提供userid及其密碼

auth.ldapAuthentication().userSearchFilter("uid={0}").contextSource() 
      .url("ldap://WIN-BSCF2478SL5.Adexample.com/DC=ADExample,DC=com"); 

,它也沒有爲我工作,並在此我得到的例外是

原因:LDAP處理過程中發生異常未歸類;嵌套異常是javax.naming.NamingException:[LDAP:錯誤代碼1 - 000004DC:LdapErr:DSID-0C0906E8,註釋:爲了執行此操作,必須在連接上完成成功的綁定,數據0,v1db1]。剩餘名稱'/'

回答

0

類似的問題可以發現here

您遇到的錯誤可能是由多種其他原因導致的,因爲我們無法看到您的配置。看起來你無法綁定到LDAP。您的LDAP配置是否正確?你有沒有嘗試配置一個像教程指出的test-server.ldif?

+0

是的,你可能是正確的... ldap配置可能不正確...因爲它是我的本地系統我剛剛安裝了活動目錄並在其中創建了用戶。你可以分享一些教程配置活動目錄? – Jahangeer