Skip to content
Advertisement

Spring authentication using ActiveDirectoryLdapAuthenticationProvider and embedded ldif

one of my clients requirement was to authenticate users against his corporate ActiveDirectory (LDAP). So I used standard ActiveDirectoryLdapAuthenticationProvider and it works like a charm.

JavaScript

Problem is that clients AC is hidden behind firewall. It works after deployment, but I cannot reach AC during local development due to cleints security policy. So, I had an idea that maybe for dev profile I will use embedded LDAP server (UnboundID LDAP SDK for Java). I’m not an LDAP expert, but I somehow composed simple ldif file, and it looks like this:

JavaScript

I also configured embedded ldap properties:

JavaScript

UnboundID had no problem with that, but as you guess I encounter problem during authentication:

JavaScript

To show you whole picture I add that error occurs during authentication attempt (in custom authentication service):

JavaScript

I presume that it is caused by the fact that my ldif file is too simple. It would work with vanilla Ldap authentication provider, but not with ActiveDirectoryLdapAuthenticationProvider.

Is there anyone who knows how to “mock” ActiveDirectory(LDAP) in ldif file so ActiveDirectoryLdapAuthenticationProvider could use it during authentication?

Advertisement

Answer

I had the same problem and found a solution that works, but I am not very happy with it. Here is how it works for me:

  1. Adjust the .ldif file

    Add the userPrincipalName attribute to your .ldif file and fill it with the same value as the dn, in your case:

    JavaScript
  2. Use the dn instead of the email address for authentication

    You use john@test.local in your test for authentication. To make it work, you have to use the dn: uid=john,ou=people,dc=test,dc=local

After these changes, the authentication against embedded LDAP worked in the tests. Better solutions are welcome!

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement