Aide memoire: Remote LDAP access with ColdFusion

When attempting to extract user data from Active Directory or some other LDAP server you need to have the full account details (username and password) of a user with read (and write if making updates) access to the server for the record(s) you want to retrieve. This would be supplied by a network admin or similar.

On IIS where using basic authentication, you can access CGI.AUTH_USER and CGI.AUTH_PASSWORD. This is bad practise as passwords are sent in plain text. On IIS when using integrated NT authentication only CGI.AUTH_USER is populated. On IIS with anonymous access neither field is populated. CGI.AUTH_USER uses the format DOMAIN\username.

To retrieve the information of a specific individual use the username and password of an authorised account and filter using the CGI.AUTH_USER variable. Using ColdFusion against Active Directory the format is as follows:

<cfset domain = listFirst(CGI.AUTH_USER,'\')>
<cfset username = listLast(CGI.AUTH_USER,'\')>

<cfset adminDomian = "ADdomain">
<cfset adminUsername = "joeblogs">
<cfset adminPassword = "joeblogs123">

<cfldap action="QUERY"
	name="auth"
	attributes="c,cn,company,department,displayName,dn,givenName,homeDrive,l,mail,objectCategory,objectClass,physicalDeliveryOfficeName,postalCode,sAMAccountName,sn,st,streetAddress,telephoneNumber,title,userPrincipalName"
	start="DC=subdomain,DC=domain,DC=com"
	scope="SUBTREE"
	filter="sAMAccountName=#username#"
	sort="userPrincipalName"
	server="ldap.server.address"
	username="#adminDomian#\#adminUsername#"
	password="#adminPassword#">

Getting the LDAP server address using DOS:

echo %LOGONSERVER%

Some LDAP Distinguished Name (DN) Attributes:

  • c
  • cn
  • company
  • department
  • displayName
  • dn
  • givenName
  • group-Type
  • homeDrive
  • l
  • location
  • mail
  • mS-SQL-Database
  • o
  • objectCategory
  • objectClass
  • organizational-Unit-Name
  • ou
  • physicalDeliveryOfficeName
  • postalCode
  • primary-Group-ID
  • sAMAccountName
  • sAM-Account-Type
  • service-Principal-Name
  • sn
  • st
  • street
  • streetAddress
  • telephoneNumber
  • title
  • user-Account-Control
  • userPrincipalName

References:
http://www.tek-tips.com/viewthread.cfm?qid=877247
http://www.houseoffusion.com/groups/cf-newbie/thread.cfm/threadid:728
http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:55463
http://www.adobe.com/devnet/server_archive/articles/integrating_cf_apps_w_ms_active_directory.html#intra

Leave a comment