![]() ![]() ![]() |
The Query sample code can be copied to a ColdFusion application page and tested. The code examples for the Delete and ModifyDN actions use placeholders for the SERVER
, USERNAME
, and PASSWORD
values because these must be specified by the user.
This example uses CFLDAP to retrieve the name and telephone numbers for US organizations with a common name that starts with 'A' through 'E'. The search starts in the country: US. The filter is a regular expression that limits the search to expressions of any length that begin with "A," "B," "C," "D," or "E."
<CFLDAP NAME="OrgList" SERVER="ldap.itd.umich.edu" ACTION="QUERY" ATTRIBUTES="o,st,telephoneNumber" SCOPE="ONELEVEL" FILTER="(|(o=A*)(o=B*)(o=C*)(o=D*)(o=E*))" MAXROWS=200 SORT="o" START="c=US"> <HTML> <HEAD> <TITLE>LDAP Directory Example</TITLE> </HEAD> <BODY> <H3>US Organizations begining with the letter 'A' thru 'E':</H3> <CFFORM NAME="GridForm" ACTION="org_query.cfm"> <CFGRID NAME="grid_one" QUERY="OrgList" HEIGHT=250 WIDTH=620 HSPACE=20 VSPACE="6"> <CFGRIDCOLUMN NAME="o" HEADER="Organization" WIDTH=380> <CFGRIDCOLUMN NAME="st" HEADER="State" WIDTH=100> <CFGRIDCOLUMN NAME="telephoneNumber" HEADER="Phone ##" WIDTH=150> </CFGRID> </CFFORM> </BODY> </HTML>
This example executes a Delete based on the user selection, and then performs a query of the LDAP data source.
<!--- If the delete parameter is sent then run this update ---> <CFIF IsDefined(dn)> <CFLDAP Name="LDAPDelete" SERVER="ldap.com" USERNAME="cn=Directory Manager, o=Ace Industry, c=US" PASSWORD="testldap" ACTION="Delete" DN=#dn#> </CFIF> <!--- Use CFLDAP to retrieve the common name and distinguished name for all employees that have a surname that contains ens and a common name that is > K. Search starts in the country US and organization Ace Industry. ---> <CFLDAP Name="EntryList" SERVER="ldap.com" ACTION="Query" ATTRIBUTES="dn,cn, sn" SCOPE="SUBTREE" SORT="cn ASC" FILTER="(cn>=A)" START="o=Ace Industry, c=US" TIMEOUT=30>
This code determines whether an insert or an update to an entry in an LDAP data source was requested and executes an LDAP operation accordingly. Output is directed to pages that populate forms with data returned in the LDAP operation.
<!--- If the update parameter is sent then run this update ---> <!--- If the insert parameter is sent then run this insert ---> <CFIF IsDefined(rename_dn)> <CFLDAP Name="CustomerRename" SERVER="ldap.com" USERNAME="cn=Directory Manager, o=Ace Industry, c=US" PASSWORD="testldap" ACTION="MODIFYDN" ATTRIBUTES=#new_dn# DN=#rename_dn#> <CFELSE> <CFIF IsDefined(dn)> <CFSET #UPDATE_ATTRS#=#mailtag# & #email# & ";" & #phonetag# & #Phone#> <CFLDAP Name="CustomerModify" SERVER="ldap.com" USERNAME="cn=Directory Manager, o=Ace Industry, c=US" PASSWORD="testldap" ACTION="MODIFY" ATTRIBUTES=#UPDATE_ATTRS# DN=#dn#> <CFELSE> <!--- If the insert parameter is sent then run this insert ---> <CFIF IsDefined(Distinguished_Name)> <CFSET #ADD_ATTRS# = "objectclass=top, person,organizationalPerson,inetOrgPerson;" & #fullnametag# & #Fullname# & ";" & #surnametag# & #Surname# & ";" & #mailtag# & #Email# & ";" & #phonetag# & #Phone#> <CFLDAP Name="CustomerAdd" SERVER="ldap.com" USERNAME="cn=Directory Manager, o=Ace Industry, c=US" PASSWORD="testldap" ACTION="Add" ATTRIBUTES=#ADD_ATTRS# DN=#Distinguished_Name#> </CFIF> </CFIF> </CFIF> <!--- Use CFLDAP to retrieve the common name and distinguished name for all employees that have a surname that contains ens and a common name that is > K. Search starts in the country US and organization Ace Industry.---> <CFLDAP Name="EntryList" SERVER="ldap.com" ACTION="Query" ATTRIBUTES="dn,cn, sn" SCOPE="SUBTREE" SORT="sn ASC" FILTER="(&(sn=*ens*)(cn>=K))" START="o=Ace Industry, c=US" MAXROWS=50 TIMEOUT=30> <HTML> <HEAD> <TITLE>LDAP Directory Example</TITLE> </HEAD> <P>To modify the attributes of an entry, select the entry and click the <B>Update</B> button. To create a new entry, click the <B>Add</B> button. <CFFORM NAME="MyForm" ACTION="ldap_update.cfm" TARGET="Lower"> <CFSELECT NAME="dn" SIZE="5" REQUIRED="Yes" QUERY="EntryList" Value="dn" Display="cn"> </CFSELECT> <INPUT TYPE="Submit" VALUE="Update..."> </CFFORM> <FORM ACTION="ldap_add.cfm" METHOD="Post" TARGET="Lower"> <INPUT TYPE="Submit" VALUE="Add..."> </FORM> </BODY> </HTML>
![]() ![]() ![]() |
AllaireDoc@allaire.com
Copyright © 1998, Allaire Corporation. All rights reserved.