Skip to content

Latest commit

 

History

History
72 lines (46 loc) · 2.51 KB

README.adoc

File metadata and controls

72 lines (46 loc) · 2.51 KB

LdapAuth library

LdapAuth
badge

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.

If you nee a more comprehensive library to deal with LDAP, have a look at Apache Directory or UboundID LDAP SDK.

usage

dependency

Maven

<dependency>
 <groupId>net.hackergarten</groupId>
 <artifactId>ldapauth</artifactId>
 <version>1.0.2</version>
 <type>pom</type>
</dependency>

Gradle

compile 'net.hackergarten:ldapauth:1.0.2'

snippet

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 search method:

net/hackergarten/ldapauth/LdapAuthenticator.java
link:src/test/java/net/hackergarten/ldapauth/LdapAuthenticator.java[role=include]

examples

Please have a look at the unit tests (LdapAuthenticatorTest.java) for an example on how to use this library.

build it

Execute the following command to compile and package the project

./gradlew build