Active Directory Lookup
Active Directory Lookup is an extremely simple Java API to access MS Active Directory for common tasks like user authentication and search. This lightweight library does not depend on any other library (No transitive dependencies) and is merely 17Kb in size. It also provides a minimal CLI for quick operations.
Quick Start
Assuming we know the values of these variables
String domain; // e.g. acme.org
String url; // e.g. ldap://somehost.acme.org or ldap://someotherhost.com
String searchBase; // e.g. dc=acme,dc=org
String username; // e.g. johndoe
String password; // e.g. password
Authenticating with Active Directory
authenticator = new ActiveDirectoryAuthenticator(domain, url); // check out other constructors
authenticator.authenticate(username, password);
Searching in Active Directory
searcher = new SimpleActiveDirectorySearcher(url, domain, username, password, searchBase);
searcher.searchByUsername("superman");
Building LdapContext
LdapContext ldapContext = ActiveDirectoryAuthenticator
.getDefaultActiveDirectoryBinder()
.getLdapContext(url, domain, username, password);
Installation
The built library can be consumed directly from jitpack repo
Using Gradle
Add this at the top of build.gradle
allprojects {
repositories {
maven { url 'https://jitpack.io' }
}
}
Add/merge the dependency in the dependencies
section
dependencies {
implementation "com.kdabir:active-directory-lookup:1.0.2"
}
Using Maven
Add this to the pom.xml
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Add this to the dependencies
section within pom.xml
<dependency>
<groupId>com.kdabir</groupId>
<artifactId>active-directory-lookup</artifactId>
<version>1.0.2</version>
</dependency>
API Documentation
Browse the JavaDoc for details. The key methods to look out for are:
ActiveDirectoryAuthenticator::authenticate(..)
ActiveDirectoryAuthenticator::isValid(..)
ActiveDirectorySearcher::search(..)
SimpleActiveDirectorySearcher::searchByUsername(..)
Building Locally
The project is built and packaged using Gradle.
Unit Testing
gradle test
Unit tests do not depend on any Active Directory instance and hence can be run without any configuration whatsoever.
Integration Testing
gradle integrationTests
You need to set the adl.properties
in the root of the project with the right configuration set in order to run Integration
Tests.
Installing to local Maven repo
gradle publishToMavenLocal
This make's the jar available in you local maven repository for usage.
References :
- http://docs.oracle.com/javase/8/docs/technotes/guides/jndi/jndi-ldap.html
- http://docs.oracle.com/javase/tutorial/jndi/ops/faq.html
- http://technet.microsoft.com/en-us/library/aa996205(v=exchg.65).aspx#BasicLDAPSyntax
Finding configuration
nslookup -type=srv _ldap._tcp.DOMAINNAME