Querying an LDAP Directory

The CFLDAP tag can query an LDAP directory and return the results as a ColdFusion query object. This gives you tremendous flexibility in how you use the data. The query object can be output to the browser using CFOUTPUT or used to feed directory information to other functions or templates.

Performing an LDAP Query

Once you know the available attributes of a given LDAP server, you can easily perform a basic query against the directory and output the results to the browser. Example 15-1 shows how to perform a simple query against the airius.com sample directory included with the Netscape Directory Server.

Example 15-1. Querying an LDAP Directory

<!--- query the LDAP server for all entries under the airius.com organization where the surname of the person begins with 's' and their location is 'Santa Clara'. Sort the results by surname and given name. ---> <CFLDAP ACTION="QUERY" NAME="MyLDAPQuery" SERVER="localhost" PORT="389" ATTRIBUTES="cn,sn,givenName,ou,l" MAXROWS="100" START="o=airius.com" SCOPE="Subtree" FILTER="(&(sn=s*)(l=Santa Clara))" SORT="SN, givenName" SORTCONTROL="nocase, ASC" TIMEOUT="90"> <!--- output the query results ---> <TABLE CELLPADDING="3" CELLSPACING="1"> <TR bgcolor="#CoCoCo"> <TH>Common Name (cn)</TH><TH>Surname (sn)</TH><TH>Given Name (givenName)</TH> <TH>Organizational Unit (ou)</TH><TH>Locality (l)</TH> </TR> <CFOUTPUT QUERY="MyLDAPQuery"> <TR bgcolor="##9999FF"> <TD><CFIF cn IS "">&nbsp;<CFELSE>#cn#</CFIF></TD> <TD><CFIF sn IS ...

Get Programming ColdFusion now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.