I'd like anyone to critique this component to see if I've left out any important 
component-related information.  I plan to put this component in the application scope 
to be used by the rest of my intranet.

I do not plan on using this as a web service.  If anything, I would create a fa�ade 
component that would call this one.

(Please ignore the lack of a proper comment header block.)

Thanks
MAD

<cfcomponent displayname="Active Directory Service" hint="Provides Active Directory 
Communication" output="No">

<cffunction name="LDAPQuery" displayname="LDAP Query" hint="Provides basic Active 
Directory read-only queries" returntype="query" access="public" output="No">

        <cfargument name="Start" type="string" required="Yes" displayname="Search 
Start" hint="LDAP query starts in this Active Directory container (OU)">
        <cfargument name="Scope"  type="string" required="Yes" displayname="Search 
Scope" hint="LDAP query is limited to BASE|ONELEVEL|SUBTREE">
        <cfargument name="LDAPAttributes" type="string" required="Yes" 
displayname="LDAP Query Attributes" hint="LDAP query will return this comma-separated 
list of attributes">
        <cfargument name="Filter" type="string" required="Yes" displayname="Query 
Results Filter" hint="LDAP query results will be filtered according to this string">
        <cfargument name="SortOrder" type="string" required="Yes" displayname="Query 
Results Sort Order" hint="LDAP query results will be sorted according to this 
comma-separated list of attributes">
        <cfargument name="Separator" type="string" required="Yes" displayname="Query 
Results Value Separator Character" hint="LDAP query results that contain multi-value 
attributes will be separated by this character">

        <cfset var LDAPServer1 = "server1">
        <cfset var LDAPServer2 = "server2">
        <cfset var LDAPServer3= "server3">
        <cfset var LDAPUserName = "username">
        <cfset var LDAPPassword = "password">
        <cfset var LDAPPort = "389">
        <cfset var LDAPTimeOut = "10">

        <cfset var Results = "">

        <!--- Ensure the SCOPE argument contains a valid value. --->
        <cfif not ReFindNoCase("(^Base$)|(^OneLevel$)|(^SubTree$)", Arguments.Scope)>
                <cfthrow
                        message="LDAPQuery request could not be completed."
                        detail="Incorrect SCOPE argument value passed.  Valid values 
are 'BASE', 'ONELEVEL' and 'SUBTREE'"
                        type="AceLink.Exception.LDAPQuery.InvalidScopeValue">
        </cfif>
        
        <cftry>
                <!--- Bounce request off of the first domain controler. --->
                <cfldap
                        action="query"
                        name="Results"
                        start="#Arguments.Start#"
                        scope="#Arguments.Scope#"
                        attributes="#Arguments.LDAPAttributes#"
                        separator="#Arguments.Separator#"
                        filter="#Arguments.Filter#"
                        sort="#SortOrder#"
                        server="#LDAPServer1#"
                        port="#LDAPPort#"
                        username="#LDAPUserName#"
                        password="#LDAPPassword#"
                        timeout="#LDAPTimeOut#">

                <cfreturn Results>

                <!--- The first domain controller request failed. --->
                <cfcatch type="Any">
                        <!--- Bounce request off of the second domain controler. --->
                        <cftry>
                                <cfldap
                                        action="query"
                                        name="Results"
                                        start="#Arguments.Start#"
                                        scope="#Arguments.Scope#"
                                        attributes="#Arguments.LDAPAttributes#"
                                        separator="#Arguments.Separator#"
                                        filter="#Arguments.Filter#"
                                        sort="#SortOrder#"
                                        server="#LDAPServer2#"
                                        port="#LDAPPort#"
                                        username="#LDAPUserName#"
                                        password="#LDAPPassword#"
                                        timeout="#LDAPTimeOut#">
                
                                <cfreturn Results>
                                
                                <!--- The second domain controller request failed. --->
                                <cfcatch type="Any">
                                        <!--- Bounce request off of the third domain 
controler. --->
                                        <cftry>
                                                <cfldap
                                                        action="query"
                                                        name="Results"
                                                        start="#Arguments.Start#"
                                                        scope="#Arguments.Scope#"
                                                        
attributes="#Arguments.LDAPAttributes#"
                                                        
separator="#Arguments.Separator#"
                                                        filter="#Arguments.Filter#"
                                                        sort="#SortOrder#"
                                                        server="#LDAPServer3#"
                                                        port="#LDAPPort#"
                                                        username="#LDAPUserName#"
                                                        password="#LDAPPassword#"
                                                        timeout="#LDAPTimeOut#">
                                
                                                <cfreturn Results>

                                                <!--- The third domain controller 
request failed. --->
                                                <!--- It's time to give up and throw 
an error. --->
                                                <cfcatch type="Any">
                                                        <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.LDAPQuery">
                                                </cfcatch>
                                        </cftry>
                                </cfcatch>
                        </cftry>
                </cfcatch>
        </cftry>
</cffunction>

</cfcomponent>



M!chael A. Dawson
Group Manager, Programming and Software Development
Office of Technology Services
University of Evansville
1800 Lincoln Avenue
Evansville, IN 47722
812-479-2581
----------------------------------------------------------
You are subscribed to cfcdev. To unsubscribe, send an email
to [EMAIL PROTECTED] with the word 'unsubscribe cfcdev'
in the message of the email.

CFCDev is run by CFCZone (www.cfczone.org) and supported
by Mindtool, Corporation (www.mindtool.com).

Reply via email to