A very light weight library to provide LDAP authentication.
Inspired by npm ldapauth package.
Intended to provide a much simpler API to lookup user details and authenticate user against a LDAP directory.
<dependency> <groupId>net.hackergarten</groupId> <artifactId>ldapauth</artifactId> <version>1.0.2</version> <type>pom</type> </dependency>
To authenticate a user against your LDAP, you need to know your LDAP ServerName and the search base the users you want to allow to authenticate are located in your LDAP structure.
To do the actual authentication, you also need the full DN for the user to authenticate.
To get this from a single identifying attribute, you need to do a search first.
You can use
setUidProperty to define the property to be used for the lookup. Given this, the resulting code would look like:
LdapAuthenticator ldapAuthenticator = new LdapAuthenticator("dc=example,dc=com", "ldap://ldap.forumsys.com:389/"); ldapAuthenticator.setUidProperty("cn"); String dn = ldapAuthenticator.getDn("read-only-admin"); boolean authenticated = ldapAuthenticator.testBind(dn, "password");
To read some more information about the user, you can use the
Please have a look at the unit tests (LdapAuthenticatorTest.java) for an example on how to use this library.
Execute the following command to compile and package the project