Well, I know you guys didn't ask for it, but I built this last year.  It
was done before I really started thinking about OO, but it works quite
well.  The gist is that I can pass an array of ldap server names and the
method will loop over each server until it finds one that is willing to
respond.

(I create the server array in the init() method.)

I also used the empty CFCATCH block, but look at the code and you will
see why.  Now that I look at it, I should have it log the ldap
connection failure, at least.

If you would like to see the rest of this component, let me know.

M!ke

<snip>

<cffunction name="LDAPQuery" returntype="query" access="public"
output="No" hint="Provides basic, read-only Active Directory queries.">
        <cfargument name="Start" type="string" required="Yes" hint="LDAP
query starts in this Active Directory container (OU). Ex: dc=evansville,
dc=edu">
        <cfargument name="Scope"  type="string" required="Yes"
hint="LDAP query is limited to BASE|ONELEVEL|SUBTREE.">
        <cfargument name="LDAPAttributes" type="string" required="Yes"
hint="LDAP query will return this comma-separated list of attributes.">
        <cfargument name="Filter" type="string" required="Yes"
hint="LDAP query results will be filtered according to this string.">
        <cfargument name="SortOrder" type="string" required="No"
default="cn" hint="LDAP query results will be sorted according to this
comma-separated list of attributes.">
        <cfargument name="Separator" type="string" required="No"
default="|" hint="LDAP query results that contain multi-value
attributes, such as &quot;memberOf&quot; will be separated by this
character.  It is recommended that the default &quot;pipe&quot;
character is used.">

        <cfset var Results = "">
        <cfset var ThisServer = "">

        <!--- Ensure the instance has been properly initialized prior to
calling this method. --->
        <cfif not IsDefined("Instance")>
                <cfthrow
                        message="LDAPQuery request could not be
executed."
                        detail="The Active Directory Service has not
been initialized. The Init() method must be called before calling the
LDAPQuery() method."
        
type="AceLink.Exception.ActiveDirectoryService.LDAPQuery.InstanceNotInit
ialized">
        </cfif>

        <!--- Ensure the Scope argument contains a valid value. --->
        <cfif not ReFindNoCase("(^Base$)|(^OneLevel$)|(^SubTree$)",
Arguments.Scope)>
                <cfthrow
                        message="The LDAPQuery request could not be
completed."
                        detail="An incorrect SCOPE argument value
passed.  Valid values are BASE, ONELEVEL and SUBTREE"
        
type="AceLink.Exception.ActiveDirectoryService.LDAPQuery.InvalidArgument
">
        </cfif>

        <!--- Attempt to perform the LDAP query against each server
until a successful query is performed. --->
        <cfloop from="1" to="#ArrayLen(Instance.LDAPServers)#"
index="ThisServer">
                <cftry>
                        <cfldap
                                action="query"
                                name="Results"
                                start="#Arguments.Start#"
                                scope="#Arguments.Scope#"
                                attributes="#Arguments.LDAPAttributes#"
                                separator="#Arguments.Separator#"
                                filter="#Arguments.Filter#"
                                sort="#Arguments.SortOrder#"
        
server="#Instance.LDAPServers[ThisServer]#"
                                port="389"
                                username="#Instance.LDAPUserName#"
                                password="#Instance.LDAPPassword#">

                        <cfreturn Results>

                        <cfcatch type="Any">
                                <!--- Do nothing in order to try all
ldap servers. --->
                        </cfcatch>
                </cftry>
        </cfloop>

        <!--- If we got here, we were not able to perform a successful
LDAP query. --->
        <cfthrow
                message="LDAPQuery request could not be completed."
                detail="A domain controller could not be contacted,
invalid Active Directory credentials were used or incorrect attributes
were passed to the LDAP query."
                extendedinfo="Ensure at least one domain controller is
available to the ColdFusion server.  Ensure the LDAPQuery account has
the appropriate permissions to query Active Directory.  Ensure a
properly-formed LDAP query is passed to the LDAPQuery method.  Some
attributes, such as 'memberOf' cannot be used to sort the results in
some instances."
        
type="AceLink.Exception.ActiveDirectoryService.LDAPQuery">
</cffunction>


----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email to 
[email protected] with the words 'unsubscribe cfcdev' as the subject of the 
email.

CFCDev is run by CFCZone (www.cfczone.org) and supported by CFXHosting 
(www.cfxhosting.com).

An archive of the CFCDev list is available at
www.mail-archive.com/[email protected]


Reply via email to