views:

62

answers:

1

The below search term seems to return match if a user simply exists in the active directory:

NamingEnumeration<SearchResult> ne = dirContext.search(
                        baseDN,
                        userObjectQuery,
                        new String[] { userName },
                        SearchControls)

The userObjectQuery is like userObjectQuery=(&(sAMAccountName=%u)(objectclass=user))

Where %u above will be substituted by the username.

How do I make sure that the users password also matches and only then return true?

+3  A: 

Once you find the user using your search code, you can get the user's full DN with getNameInNamespace()

Then you can bind as that full DN and password to authenticate.

karoberts
Is it not possible to validate a user's password without binding? For instance we want to have users with bind capability as a special group who can authenticate other less privileged users.
JavaRookie
I have a copy of the user password and just want to ensure that it matches with the password on the AD server. So with the user name I have I want to procure the AD password and then match it with what I have locally. Can that be done with dirContextSearch or is there some other call?
JavaRookie
It would be a very poorly designed LDAP server that let you "acquire" a user's password. Anybody who could bind could grab all the passwords. Many LDAP implementations do a one way hash on the password so they don't even keep it. Binding is the only way I know of to authenticate.
karoberts