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 example.com sample directory included with the Netscape Directory Server.

Example 15-1. Querying an LDAP directory

<!--- query the LDAP server for all entries 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,mail,l" maxrows="100" start="dc=example,dc=com" scope="Subtree" filter="(&(sn=s*)(l=Santa Clara))" sort="sn, givenNnme" sortcontrol="nocase, ASC" timeout="90"> <html> <head> <title>Example 15-1: Querying an LDAP Directory</title> <style type="text/css"> th { background-color : #C0C0C0; font-weight : bold; text-align : center; } td { background-color : #9999FF; } </style> </head> <body> <!--- output the query results ---> <table cellspacing="3" cellspacing="1"> <tr> <th>Common Name (cn)</th> <th>Surname (sn)</th> <th>Given Name (givenname)</th> ...

Get Programming ColdFusion MX, 2nd Edition 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.