# [java] Authenticating Through AD Using Java

This topic is 3404 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

At work we use a MS active directory for authentication. I am in the process of creating a web application which will require user authentication but we would like to use the AD to avoid having to force people to have an additional username/password to remember. I've done a bit of googling on the subject but all solution I've found looked really convoluted when what I want to do can be done with a few single lines in C#:
private bool Authenticate(string userName,
{
bool authentic = false;
try
{
DirectoryEntry entry = new DirectoryEntry("LDAP://" + domain,
object nativeObject = entry.NativeObject;
authentic = true;
}
catch (DirectoryServicesCOMException) { }
return authentic;
}


I was wondering if there was an as simple way to do this in java seeing how I just want a true/false indication from the AD. I found a possible solution here but it looks like I need a bunch of parameters for the search which I'm not sure I can get. Maybe someone could help me demystify how the code works. More specifically I don't understand the parameters such as "dc=abbl,dc=org". Any help would be really appreciated [smile] edit: I figured I'd be a bit more specific in my query. Basically using the code in the page linked above I'm trying to figure out what parameters need to be fed to the object during initialization. In this case: domain, host, dn. Thing is, I do not have access to the active directory directly (it's handle by some other group and I have no clue who this group is) so I'm wondering if there's a way I can pull this information through either the command prompt or something else. [Edited by - Gazillion on May 19, 2009 1:42:15 PM]

##### Share on other sites
Had to do LDAP auth from a web app just the other day where we are also using Active Directory. I ended up using jCIFS which was amazingly simple to get up and running. If SmbSession.logon() does nothing, authorisation succeeded, if it does anything else, authorisation failed.

log.debug( "attempting login - uname = " + usernameText + ", pwd = " + passwordText );try{	UniAddress dc = UniAddress.getByName( "xxx.xxx.com.au" );	NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication( ";" + usernameText + ":" + passwordText );	SmbSession.logon( dc, auth );	log.debug( "LOGIN SUCCESS" );	passwordText = "";	authorised = true;}catch( Exception e ){	log.debug( e );	log.debug( "LOGIN FAILED" );	passwordText = "";	authorised = false;}

1. 1
2. 2
3. 3
Rutin
22
4. 4
frob
18
5. 5

• 33
• 13
• 10
• 10
• 12
• ### Forum Statistics

• Total Topics
632569
• Total Posts
3007120

×