|
I’m about to begin a new project that will be my
second attempt at “real” OO within ColdFusion. (I’ve
been working w/ CF since 4.5 but was unfortunately working with PHP when MX
arrived on scene – been playing catch up lately.) I learned a
lot from my mistakes on the first app, and before I begin a new project I want
to be sure my understanding of CFCs is at least fundamentally sound. For starters will you please review the attached CFC and
point out any troublesome areas? It is a simple LDAP authentication CFC,
but I’d like feedback on the structure as a whole before I create many
more similarly structured components. TIA paul |
<cfcomponent>
<cfscript>
variables.instance=structNew();
variables.instance.server="";
variables.instance.attributes="";
variables.instance.domain="";
</cfscript>
<cffunction name="init">
<cfargument name="server" default="10.1.34.5" type="string">
<cfargument name="attributes" default="sAMAccountName, mail,
displayName, givenName, sn, memberOf" type="string">
<cfargument name="domain" default="redmond" type="string">
<cfscript>
setServer(arguments.server);
setAttributes(arguments.attributes);
setDomain(arguments.domain);
</cfscript>
<cfreturn this>
</cffunction>
<cffunction name="setServer" access="private" returntype="void">
<cfargument name="newValue" required="true" type="string">
<cfset variables.instance.server=arguments.newValue>
</cffunction>
<cffunction name="setAttributes" access="private" returntype="void">
<cfargument name="newValue" required="true" type="string">
<cfset variables.instance.attributes=arguments.newValue>
</cffunction>
<cffunction name="setDomain" access="private" returntype="void">
<cfargument name="newValue" required="true" type="string">
<cfset variables.instance.domain=arguments.newValue>
</cffunction>
<cffunction name="getServer" access="private" returntype="string">
<cfreturn variables.instance.server>
</cffunction>
<cffunction name="getAttributes" access="private" returntype="string">
<cfreturn variables.instance.attributes>
</cffunction>
<cffunction name="getDomain" access="private" returntype="string">
<cfreturn variables.instance.domain>
</cffunction>
<cffunction name="authenticate" access="public" returntype="query"
hint="I authenticate against LDAP and return a populated query object. If
authentication fails I return an empty query object.">
<cfargument name="username" required="true" type="string">
<cfargument name="password" required="true" type="string">
<cfset var qLDAP=queryNew(getAttributes())>
<cftry>
<cfldap action="query"
name="qLDAP"
start="cn=users, dc=mydomain, dc=com"
scope="oneLevel"
server="#getServer()#"
filter="sAMAccountName=#arguments.username#"
attributes="#getAttributes()#"
username="#getDomain()#\#arguments.username#"
password="#arguments.password#"
port="389">
<cfcatch type="Any"><!--- do nothing ---></cfcatch>
</cftry>
<cfreturn qLDAP>
</cffunction>
</cfcomponent>
----------------------------------------------------------
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]
