My linux world » Java Spring Security – LDAP

Java Spring Security - LDAP


Contents

Prerequistes

Please read Java Spring Security – Database User

Configuration

SecurityConfiguration.java

Override configure method from WebSecurityConfigurerAdapter :

@Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.ldapAuthentication()
        .userSearchBase("ou=people")
        .userSearchFilter("(uid={0})")
        .groupSearchBase("ou=groups")
        .groupSearchFilter("(member={0})")
        .contextSource().root("dc=MYDOMAIN,dc=LOCAL")
        .ldif("classpath:users.ldif");
    }

users.ldif

In src/main/resources, you can create users.ldif :

dn: ou=groups,dc=MYDOMAIN,dc=LOCAL
objectclass: top
objectclass: organizationalUnit
ou: groups
 
dn: ou=people,dc=MYDOMAIN,dc=LOCAL
objectclass: top
objectclass: organizationalUnit
ou: people
 
dn: uid=user1,ou=people,dc=MYDOMAIN,dc=LOCAL
objectclass: top
objectclass: person
objectclass: organizationalPerson
objectclass: inetOrgPerson
cn: User Number1
sn: userSN1
uid: user1
userPassword: user1Password
 
dn: cn=admin,ou=groups,dc=MYDOMAIN,dc=LOCAL
objectclass: top
objectclass: groupOfNames
cn: admin
member: uid=user1,ou=people,dc=MYDOMAIN,dc=LOCAL
 
dn: cn=user,ou=groups,dc=MYDOMAIN,dc=LOCAL
objectclass: top
objectclass: groupOfNames
cn: user
member: uid=user1,ou=people,dc=MYDOMAIN,dc=LOCAL

You will be able to connect using :


Copyright © 2024 My linux world - by Marc RABAHI
Design by Marc RABAHI and encelades.