В Active Directory редко разрешено анонимное чтение, поэтому необходимо выполнить привязку перед выполнением любого поиска. Для этого я использую специальную «системную» учетную запись (вы можете использовать свою, но в следующий раз все изменится, когда вы смените пароль). Ниже то, что я использую для формы, которая обрабатывает аутентификацию пользователя. Это LDAPS, который требует, чтобы ваш экземпляр Java доверял подписывающему лицу сертификата каталога - часто проще начать с открытого текста LDAP, заставить все работать, затем переключиться на SSL.
<!--- If the server has been defined, run the query --->
<CFIF IsDefined("form.server")>
<!--- check to see that there is a name listed --->
<CFIF form.name is not "">
<!--- make the LDAP query --->
<cfldap action="QUERY"
server="my.server.com"
port="636"
username="cn=YOURSYSTEMIDGOESHERE,ou=systemids,dc=my,dc=server,dc=com"
password="YOURPASSWORDGOESHERE"
name="getldap"
start="CN=Users,DC=my,DC=server,DC=com"
attributes="dn"
scope="subtree"
filter="(&(objectclass=user)(sAMAccountName=#form.uid#))"
secure="CFSSL_BASIC"
maxrows="10">
<CFIF getldap.RecordCount GT 1>
<!--- Too many accounts exist in LDP, throw message to call the help desk --->
<CFELSEIF getldap.RecordCount EQ 0>
<!--- User does not exist in directory, fail auth --->
<CFELSE>
<!--- Attempt Authentication using supplied credentials --->
<cfldap action="QUERY"
server="my.server.com"
port="636"
username="#getldap.dn#"
password="#form.password#"
name="attemptauth"
secure="CFSSL_BASIC"
start="CN=Users,DC=my,DC=server,DC=com"
attributes="dn"
>
<!--- Do something here to catch errors, on return code 0, auth is successful --->
<!--- Error code 19, hex 0x13) is a locked out account and fail auth --->
<!--- Error code 49, hex 0x31) is an invalid password error and fail auth --->
<!--- Other errors are system-type problems, throw try again / call help desk type error --->
</CFIF>
</CFIF>
</CFIF>
asdfa