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.
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
authenticator = new ActiveDirectoryAuthenticator(domain, url); // check out other constructors
authenticator.authenticate(username, password);
searcher = new SimpleActiveDirectorySearcher(url, domain, username, password, searchBase);
searcher.searchByUsername("superman");
LdapContext ldapContext = ActiveDirectoryAuthenticator
.getDefaultActiveDirectoryBinder()
.getLdapContext(url, domain, username, password);
The built library can be consumed directly from jitpack repo
Add this at the top of build.gradle
allprojects {
repositories {
maven { url 'https://jitpack.io' }
}
}
Add/merge the dependency in the dependencies
section
dependencies {
compile 'com.github.kdabir:active-directory-lookup:1.0.2'
}
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.github.kdabir</groupId>
<artifactId>active-directory-lookup</artifactId>
<version>1.0.2</version>
</dependency>
Browse the JavaDoc for details. The key methods to look out for are:
ActiveDirectoryAuthenticator::authenticate(..)
ActiveDirectoryAuthenticator::isValid(..)
ActiveDirectorySearcher::search(..)
SimpleActiveDirectorySearcher::searchByUsername(..)
The project is built and packaged using Gradle.
gradle test
Unit tests do not depend on any Active Directory instance and hence can be run without any configuration whatsoever.
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.
gradle publishToMavenLocal
This make's the jar available in you local maven repository for usage.
- 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
nslookup -type=srv _ldap._tcp.DOMAINNAME