Tuesday, 23 June 2015

Integrating Active Directory from Java

Firstly you will need to setup Active Directory so that you can run and test your code.

If (like me) you don't have a machine with Windows Server no worries, this is how you can set up Active Directory even on Mac OSX.

The first thing you want to do is set up a user a in AD.  Make sure that when you set up the user he doesn't have to change his password on the first login or you will get an LDAP error from your Java code.

Clearly you can change your code to prompt a password change but just something to be aware of.

Also create a couple of groups for your user and add them to their profile.

In the code below there is just one method, authenticate. It that takes as parameters a user, password and domain and returns a list of groups of which the user is a member. If the user does not exist or there is a problem with the password an exception is thrown.

The code is fairly self explanatory and you can use it as a template to experiment with adding different attributes to the search.

No comments:

Post a Comment