O'Reilly logo

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

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