Configure Spring security for Ldap connection

风格不统一 提交于 2019-12-01 03:34:48

In AbstractContextSource (parent of LdapContextSource), the Javadoc for the setBase() method says the following: "Set the base suffix from which all operations should origin. If a base suffix is set, you will not have to (and, indeed, must not) specify the full distinguished names in any operations performed.". Since you specify the full DN for the userDN/filter, hence you must not specify the base.

Try setting the userSearchBase either to an empty String (""), or remove the call all togehter.

@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception{
     auth.ldapAuthentication()
         .contextSource()
         .url("ldaps://vldp.floal:636/DC=fg,DC=local")
         .managerDn("CN=A0XXX32,CN=Administration,CN=fdam,DC=fg,DC=local")
         .managerPassword(password)
         .and()         
         .userSearchBase("")     
         .userSearchFilter("CN={0},CN=ProxyUsers,CN=fdam,DC=fg,DC=local")
         .ldapAuthoritiesPopulator(myAuthPopulator);     
}

We have a legacy app that uses Spring Security 3.2.5. We still use XML to config it. Maybe my config could help you to identify whats going on with yours.

What I noticed is that your userSearchBase does not use the complete "FQDN". Try using userSearchBase("CN=ProxyUsers,CN=fdam,DC=fg,DC=local") (despite the log msg "Attempting to bind as cn=F67XX7A,cn=ProxyUsers,cn=fdam,dc=fg,dc=local").

Another hint is to use a LDAP browser tool in order navigate into the ldap server and check to see if the CN, DN and OU are ok.

<ldap-server 
         url="ldap://SERVERNAME.XPTO.BLAH:389" 
         manager-dn="usrLogin" 
         manager-password="usrPwd" />

<authentication-manager>
    <ldap-authentication-provider 
       role-prefix="" 
       user-search base="OU=BR,OU=MYCOMP,DC=XPTO,DC=BLAH"
       user-search-filter="sAMAccountName={0}" 
       group-search-base="OU=Groups,OU=BR,OU=MYCOMP,DC=XPTO,DC=BLAH"
       group-search-filter="member={0}" />
</authentication-manager>

<beans:bean id="ldapEnv" class="java.util.Hashtable" scope="prototype">
        <beans:constructor-arg>
            <beans:map key-type="java.lang.String" value-type="java.lang.String">
                <beans:entry key="java.naming.factory.initial" value="com.sun.jndi.ldap.LdapCtxFactory" />
                <beans:entry key="java.naming.provider.url" value="ldap://SERVERNAME.XPTO.BLAH:389" />
                <beans:entry key="java.naming.security.authentication" value="simple" />
                <beans:entry key="java.naming.security.principal" value="usrLogin" />
                <beans:entry key="java.naming.security.credentials" value="usrPwd" />
            </beans:map>
        </beans:constructor-arg>
    </beans:bean>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!