I am using the Spring Security ActiveDirectoryLdapAuthenticationProvider
with Spring Boot (annotation based config) to authenticate with Active Directory and generate tokens. All works fine.
I wish to add some integration tests that simulate the whole process, and I was thinking of maybe using the Spring embedded LDAP server for that.
I added this ldif file that I got from another example I found online.
#Actual test data
dn: dc=test,dc=com
objectclass: top
objectclass: domain
objectclass: extensibleObject
dc: local
# Organizational Units
dn: ou=groups,dc=test,dc=com
objectclass: top
objectclass: organizationalUnit
ou: groups
dn: ou=people,dc=test,dc=com
objectclass: top
objectclass: organizationalUnit
ou: people
# Create People
dn: uid=testuser,ou=people,dc=test,dc=com
objectclass: top
objectclass: person
objectclass: organizationalPerson
objectclass: inetOrgPerson
cn: Test
sn: User
uid: testuser
password: secret
# Create Groups
dn: cn=developers,ou=groups,dc=test,dc=com
objectclass: top
objectclass: groupOfUniqueNames
cn: developers
ou: developer
uniqueMember: uid=testuser,ou=people,dc=test,dc=com
dn: cn=managers,ou=groups,dc=test,dc=com
objectclass: top
objectclass: groupOfUniqueNames
cn: managers
ou: manager
uniqueMember: uid=testuser,ou=people,dc=test,dc=com
But this of course does not include any of the Active Directory schema stuff.
Each user needs to have a sAMAccountName
and needs to have the memberOf
attribute to determine which groups it is in.
Is there any way to make this behave similar to active directory so that the Spring ActiveDirectoryLdapAuthenticationProvider
binds to it with the user's username and password and gets its group membership to populate its authorities?
Otherwise if this is not viable, is there any other way to mock this and have a proper test?