Jump to content
  • Advertisement
Sign in to follow this  
sanch3x

[java] Authenticating Through AD Using Java

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

If you intended to correct an error in the post then please contact us.

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,
    string password, string domain)
{
    bool authentic = false;
    try
    {
        DirectoryEntry entry = new DirectoryEntry("LDAP://" + domain,
            userName, password);
        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 this post


Link to post
Share on other sites
Advertisement
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;
}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!