Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Security and multiple ldap configuration

I use Spring Security to manage user and group securities.

All datas are stored in a ldap server. My configuration is the following:

  <authentication-manager alias="authenticationManager">
         <ldap-authentication-provider 
           user-search-filter="(mail={0})"
           user-search-base=""
           group-search-filter="(uniqueMember={0})"
           group-search-base="ou=groups"
           group-role-attribute="cn"
           role-prefix="ROLE_"
           user-context-mapper-ref="contextMapper">
         </ldap-authentication-provider>
         <lda
  </authentication-manager>

  <beans:bean id="contextMapper" class="com.mycompany.CustomContextMapper">
    <beans:property name="indexer" ref="entityIndexer" />
  </beans:bean>

  <ldap-user-service  server-ref="ldapServer" user-search-filter="(mail={0})" />

  <ldap-server manager-dn="cn=admin,dc=springframework,dc=org" manager-password="password" url="ldap://server/dc=springframework,dc=org" id="ldapServer" />

All runs like a charm. Now, I want to add a second ldap server if the first one is down (fallback). I can't find an easy way to do it.

So, my question si simple: how to add a second ldap server in this config to provide a fallback if the first one is down ?

like image 234
Jerome Cance Avatar asked May 30 '12 08:05

Jerome Cance


People also ask

How do I use LDAP security?

First; the two dependencies below will be added to the pom. xml to enable Spring Security. You can do this also when generating the project structure in spring initializer by adding Spring Security Component. Apart from these, we need to add additional dependencies for LDAP.

What is LDAP spring?

Spring LDAP is a library to simplify LDAP programming in Java, built on the same principles as Spring Jdbc. The LdapTemplate class encapsulates all the plumbing work involved in traditional LDAP programming, such as creating, looping through NamingEnumerations, handling Exceptions and cleaning up resources.


2 Answers

Use space delimited value for url attribute:

url="ldap://server1/dc=springframework,dc=org ldap://server2/dc=springframework,dc=org"

Ref: LDAP & LDAPS URLs

like image 99
Ritesh Avatar answered Sep 17 '22 20:09

Ritesh


The previous answers are correct.

I wanted to add information on LDAP server redundancy. Since that is the objective for adding multiple LDAP urls, hope it is useful.

I tested few scenarios:

For LDAP Server urls(url1, url2)

If both LDAP servers specified by urls are down, application login will fail.

If one LDAP server is down. Consider server1 as url1 : ldap://url1 (irrespective of url1 position 1st or 2nd), application works fine.

If either url is syntactically malformed: url1 : ldap://MALFORMED_URL , the application will fail to startup.

like image 38
aces. Avatar answered Sep 18 '22 20:09

aces.