Skip to content

Simplest Java API (and CLI) for authenticating and searching in Active Directory

License

Notifications You must be signed in to change notification settings

balasubramanian-rengasamy/active-directory-lookup

 
 

Repository files navigation

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 {
    compile 'com.github.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.github.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:

Building Locally

Build Status

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 :

Finding configuration

nslookup -type=srv _ldap._tcp.DOMAINNAME

About

Simplest Java API (and CLI) for authenticating and searching in Active Directory

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 100.0%