Comments
Matt McLarty wrote: For more info... Follow me on Twitter See our website
Cloud Expo on Google News


2008 West
DIAMOND SPONSOR:
Data Direct
SOA, WOA and Cloud Computing: The New Frontier for Data Services
PLATINUM SPONSORS:
Red Hat
The Opening of Virtualization
GOLD SPONSORS:
Appsense
User Environment Management – The Third Layer of the Desktop
Cordys
Cloud Computing for Business Agility
EMC
CMIS: A Multi-Vendor Proposal for a Service-Based Content Management Interoperability Standard
Freedom OSS
Practical SOA” Max Yankelevich
Intel
Architecting an Enterprise Service Router (ESR) – A Cost-Effective Way to Scale SOA Across the Enterprise
Sensedia
Return on Assests: Bringing Visibility to your SOA Strategy
Symantec
Managing Hybrid Endpoint Environments
VMWare
Game-Changing Technology for Enterprise Clouds and Applications
Click For 2008 West
Event Webcasts

2008 West
PLATINUM SPONSORS:
Appcelerator
Get ‘Rich’ Quick: Rapid Prototyping for RIA with ZERO Server Code
Keynote Systems
Designing for and Managing Performance in the New Frontier of Rich Internet Applications
GOLD SPONSORS:
ICEsoft
How Can AJAX Improve Homeland Security?
Isomorphic
Beyond Widgets: What a RIA Platform Should Offer
Oracle
REAs: Rich Enterprise Applications
Click For 2008 Event Webcasts
SYS-CON.TV
Top Links You Must Click On


Getting Started With CFLDAP In ColdFusion
A step-by-step guide to the basics

The <cfldap> can be very simple or very complicated. It all depends on what you're looking to do and how you want to authenticate your users.

For quite some time I wanted to authenticate the users on my intranet through Active Directory. I spent countless hours searching the Web for someone to explain the basics in a way I could understand being a basic ColdFusion developer. Most articles and tutorials I came across were for intermediate or advanced users.

I wound up learning most of it on my own after getting an LDAP browser and snooping around in Active Directory for what I was looking for. To my surprise accessing Active Directory wasn't as complicated as it may seem. There are tutorials out on the Web that show you different ways to access Active Directory and references that show the different attributes of Active Directory that you can query.

Every time I ask someone about accessing Active Directory using the <cfldap> tag, they're like "No Way, that's too complicated for me." Or they respond with "I know nothing about Active Directory."

Well, this article will show you how to authenticate through Active Directory with little or no <cfldap> or Active Directory experience.

I have a Windows 2000 Server and Windows 2003 Server and had to change my code for each domain because of the differences in Active Directory. Trial and error led me to find a way to use the same code for both Windows 2000 and Windows 2003 domain controllers, so I decided to pass on my knowledge.

<cfldap> can be very simple or very complicated. It all depends on what you're looking to do and how you want to authenticate your users. I'm going to show you how you can use <cfldap> to authenticate your users using just the basics. Nothing complicated!

Let's Get Started
First you should understand the basics of the <cfldap> tag. Im only going to show you the basic options to use for this example.

First let's assume that I have a domain controller called "ns1" and my domain is "adtest.com."

Here's a snapshot of a cfldap query that I used to find a user in my Active Directory:

<cfldap action="QUERY"
   name="GetUserInfo"
   attributes="dn"
   start="dc=adtest,dc=com"
   scope="subtree"
   filter="(&(objectclass=user)(samaccountname=#form.cfusername#))"
   server="ns1.adtest.com"
   username="administrator@adtest.com"
   password="password"
>

Let's start with the attributes, the attributes are the information that we want to query from Active Directory. Think of this like a "Select" statement in a regular query. In this case we just want "dn". (distinguishedName).

In the start field, you only need to define the "dc" (dc means domain content rather than domain controller in this context). Notice I used "adtest" as the first dc and "com" as the second dc. So if you have a .NET domain, just replace the dc="com" with dc="net."

The next item is the "scope." I think this is where some users make the mistake of not defining. The first time I tried to access my Active Directory I thought I didn't need to define the "scope." My Active Directory is set up with many OUs and with about three levels. The default option for "scope" is "onelevel." If you let it default you will only be querying one level below entry. So in my case, users within the one-level OUs could authenticate just fine; the other users could not. Imagine my headache figuring that out!"

So now I like to use the "subtree" option. The "subtree" option queries the entry and all levels below it.

The next item is filter. In the cfldap query above notice that I used the "objectclass=user." This is what we are querying for. If I just wanted to query the Active Directory for a computer name, I would have "computer" instead of "user." There are many other objectclass types to choose from, but I don't want to confuse you with objectclasses we don't need for this example.

The next filter is the samaccountname. This is the same account name as in the Windows Active Directory. It's basically the user login name. Here we put the login name that came from the form (#form.cfusername#).

Next is the "server." This is straightforward. Just put in your complete server name including the domain name like this "ns1.adtest.com".

The username is where I found the difference between Windows 2000 and Windows 2003 domain controllers. Windows 2000 requires you to have the "@adtect.com" at the end of all names and Windows 2003 doesn't. I found that if I just add it into my code like I did above I wouldn't have to worry about either domain since Windows 2003 accepts it. Notice that I used the administrator to authenticate to Active Directory. You can use whatever username and password you want that has access rights to query your Active Directory.

What this query does is find the user in the Active Directory. It does a lookup to determine if there's a samaccountname that matches the #form.cfusername#. If the user exists then we can move on to the next section. If not, then we should kick an error saying that the username wasn't found. I do a recordcount against the "GetUserInfo" query. If it comes back with a 0, then it didn't find the user in AD.

Authenticating a User
Okay, here we're going to assume we got a 1 with our recordcount "cfif" statement. Here's the next query example that actually authenticates the user:

<cfif #getuserinfo.recordcount# gt 0>
  <cftry>
   <cfldap action="QUERY"
   name="AuthenticateUser"
   attributes="givenname,samaccountname,dn,cn,mail"
   start="dc=adtest,dc=com"
   maxrows="1"
   scope="subtree"
   filter="(&(objectclass=user)(samaccountname=#form.cfusername#))"
   server="ns1.adtest.com"
   username="#form.cfusername#@adtest.com"
   password="#form.cfpassword#">
   <cfset LoginMessage = "User Authentication Passed">
   <cfcatch type="any">
   <cfset LoginMessage = "User Authentication Failed">
   </cfcatch>
  </cftry>
<cfelse>
   <cfset LoginMessage = "Username not found">
</cfif>

In order to post a comment you need to be registered and logged in.

Register | Sign-in

Reader Feedback: Page 1 of 1

Ok, I know this is cliche, but...

YOU ARE THE MAN!!!!!!

Thanks!

Excellent article! I got the log in to work and authenticate from my Active Directory server, but, what about integrated authentication? Anyone have any idea on how to authenticate the user without having them log in? I know IE has integrated windows authentication.

Getting Started With CFLDAP In ColdFusion. The can be very simple or very complicated. It all depends on what you're looking to do and how you want to authenticate your users. I wound up learning most of it on my own after getting an LDAP browser and snooping around in Active Directory for what I was looking for. To my surprise accessing Active Directory wasn't as complicated as it may seem. There are tutorials out on the Web that show you different ways to access Active Directory and references that show the different attributes of Active Directory that you can query.


Your Feedback
Johnny wrote: Ok, I know this is cliche, but... YOU ARE THE MAN!!!!!! Thanks!
Demetrius Pinder wrote: Excellent article! I got the log in to work and authenticate from my Active Directory server, but, what about integrated authentication? Anyone have any idea on how to authenticate the user without having them log in? I know IE has integrated windows authentication.
ColdFusion Developer's Journal wrote: Getting Started With CFLDAP In ColdFusion. The can be very simple or very complicated. It all depends on what you're looking to do and how you want to authenticate your users. I wound up learning most of it on my own after getting an LDAP browser and snooping around in Active Directory for what I was looking for. To my surprise accessing Active Directory wasn't as complicated as it may seem. There are tutorials out on the Web that show you different ways to access Active Directory and references that show the different attributes of Active Directory that you can query.
Enterprise Open Source Magazine Latest Stories . . .
New tools and services for swift software-as-a-service integration in the cloud lowers the barrier to SaaS adoption for SaaS providers and developers. MuleSoft this week launched Mule iON SaaS Edition, providing a broad set of new tools and services for swift software-as-a-Service (Sa...
All the buzz surrounding OpenStack over the past few months may beg the question of whether Openstack can repeat for Cloud what Linux has done for server operating systems over the past several years. With an enthusiastic following and a compelling, if not industry-leading set of funct...
Virtual Desktop Infrastructure (VDI) has been a hot topic in the IT community for years but delivery models have limited its use. Today there are real options for using the technology to truly replace the existing desktop infrastructure to realize tangible benefits. Today’s cloud-sourc...
VMware hypervisors of the ESX family (3.x, 4.x and 5.0) are fully, out-of-the box supported by the latest versions of OpenNebula(3.0+). If you have a server farm based on any of the ESX versions, then you can make use of OpenNebula to better manage your physical (and virtual) resources...
Data centers today are stretched to the limits with fast-paced business demands. On top of that, integrating and managing IT infrastructures can pose major challenges. Organizations need a new solution that consolidates servers and workloads without breaking the bank—and Linux, togethe...
Atlantis Computing, a provider of Virtual Desktop Infrastructure (VDI) storage and performance optimization solutions,has announced the release of Atlantis ILIO Diskless VDI 3.2, a solution that enables VMware View customers to deploy virtual desktops with no storage. Atlantis ILIO Dis...
Subscribe to the World's Most Powerful Newsletters
Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
Click to Add our RSS Feeds to the Service of Your Choice:
Google Reader or Homepage Add to My Yahoo! Subscribe with Bloglines Subscribe in NewsGator Online
myFeedster Add to My AOL Subscribe in Rojo Add 'Hugg' to Newsburst from CNET News.com Kinja Digest View Additional SYS-CON Feeds
Publish Your Article! Please send it to editorial(at)sys-con.com!

Advertise on this site! Contact advertising(at)sys-con.com! 201 802-3021


SYS-CON Featured Whitepapers
ADS BY GOOGLE