O'Reilly logo

Programming ColdFusion by Rob Brooks-Bilson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required