Under Construction!

Click for Home

LDAP Server...

The LDAP server is an emerging standard for keeping track of people's data.  Many server companies such as Netscape are relying on it to deliver a complete solution.  With the LDAP server, you have a sing point of administration for the users in your office or in this case for your users.  Therefore adding a user is as easy as adding an entry into the LDAP server and deleting one is just as easy.

Here is a typical LDAP query using the CFLDAP tag:

<CFLDAP name="customerquery" server="aserver"
username="cn=Directory Manager"
password="xxxxx"
action="query"
attributes="cn"
scope="subtree"
start="ou=customers, ou=#session.variable#, o=Company"
sort="cn asc"
filter="(description=active)">

The above query will return the common name of all the customers in the company/(whatever session.variable is)/ customers directory with the description attribute = active.  More information on the CFLDAP tag and how the filters work in the cfdocs.

Since the LDAP server allows multiple attributes (for instance, there could be two or more description attributes for one single entry), a problem occurs.  What if you had an entry with the multiple description fields, say descritpion=active, description=user and you tried to return the description field?  Well, the output looks something like this:  active,user.  Now if I wanted to use that to populate a select box, I could not use the CFSELECT tag because it is a string.  So I came up with the following custom tag called CF_LDAPSELECT, which creates a select box from a query of this kind.

Here is the code:

<!-- CFLDAPselect.cfm
This page allows a user to make a select box with an LDAP query of multiple
attributes. -->

<CFIF IsDefined("ATTRIBUTES.querystring")>
<cfset myquery= "#ATTRIBUTES.querystring#">
<CFELSE>
<CFEXIT>
</CFIF>

<CFIF IsDefined("ATTRIBUTES.selected")>
<cfset selected= #Trim("#ATTRIBUTES.selected#")#>
<CFELSE>
<cfset selected="">
</cfif>

<CFPARAM NAME="thelist" DEFAULT="">

<cfset thelist= "#myquery#">

<cfloop condition="#ListLen(thelist)# is not 0">
<cfset element=#ListFirst(thelist)#>
<cfif element is "#selected#">
<cfoutput><option selected value="#Trim("#element#")#">#Trim("#element#")#</cfoutput>
<cfelse>
<cfoutput><option value="#Trim("#element#")#">#Trim("#element#")#</cfoutput>
</cfif>
<cfset thelist = #ListDeleteAt("#thelist#", 1)#>
</cfloop>

And here is how you use it:

<SELECT NAME="Plat">
<CFLOOP query="platformquery">
<CF_ldapselect selected="Windows" querystring="#cn#">
</cfloop>
</SELECT>

The LDAP server is a useful tool if you know how to use it, but before you try to use it, be sure you have a through understanding of how it works.  You must know the basic structure of how it is set up and understand DN's, queries and server administration.


UPDATE...

I have had a request to show how to do inserts and modifies with CFLDAP, so here it goes.

Without going into the details of how an LDAP server works, basically the two import attributes to have are the dn and the objectclass attributes.  Every entry must have a unique dn and the objectclass=top attribute in it.

Add example:
<cfset attibutetemp= "cn=#name#;sn=#sirname#;objectclass=top,person,organizationalPerson,inetOrgPerson;teleph onenumber=#phoneNumber#;facsimiletelephonenumber=#faxnumber#;ou=#unit#,customers;d escription=bla;uid=#tempid#">
<CFSET tempdn= "cn=#name#, ou=#unit#, ou=users, o=Company">

<CFLDAP name="adduser" server="aserver"
username="cn=Directory Manager"
password="xxxx"
action="add"
attributes="#attibutetemp#"
DN="#tempdn#">

Using HTML is not a good example, because sometimes you have to watch out for the attributes running on another line.  It might be worth putting all the attributes on the same line if you have errors.  Any further errors could be because you are not binding correctly as the directory manager.  A Modify action is the same as above, except for the variable attributetemp holds the attributes you want to modify.  For more information on the LDAP server, check out the following URL:

http://developer.netscape.com/tech/directory/index.html

You Must know about how the LDAP server works before you even think of trying to program with it.


   Continue to Next Page                                                   Previous Page

This page hosted by Get your own Free Homepage