简体   繁体   中英

Java LDAP password authentication

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM