Comments
Matt McLarty wrote: For more info... Follow me on Twitter See our website
Cloud Computing
Conference & Expo
November 2-4, 2009 NYC
Register Today and SAVE !..

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
In many cases, the end of the year gives you time to step back and take stock of the last 12 months. This is when many of us take a hard look at what worked and what did not, complete performance reviews, and formulate plans for the coming year. For me, it is all of those things plus a time when I u...
SYS-CON.TV
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.
SOA World Latest Stories
What do the CTO of the U.S. Dept. of Justice and the CIO of the National Reconnaissance Office have in common with the CEOs of Eucalyptus, GoGrid, ActiveState, Appcara, OpSource and Nortonworks, the CTOs of Rackspace, SoftLayer and AppZero, the Founder & General Manager of Dell Boomi, ...
The cloud has many benefits, but when it comes to application development, how does the cloud help enterprises and development teams create custom software and applications that end users actually care about? Using real world examples from Adobe, Herff Jones and Navy Federal Credit Uni...
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...
Hmm, apparently Samsung has pushed one too many of Apple’s buttons. According to DigiTimes Apple has bought up half of Elpida Memory’s total chip production of mobile DRAM rather than give the iPad and iPhone order to Samsung, its largest supplier, accused of ripping off its technolo...
The BYOD trend requires sweeping changes to the way devices are used in the workplace. Find out how to confront and manage those changes, provide a better user experience, and ensure security. Gartner Hosted BYOD VIDEO: Mobility and the Social Enterprise Technical Design Workshop VID...
Nearly every enterprise is evaluating cloud computing solutions either today or in the near term. Many have already made the leap, and many more are getting close to putting that first toe in the water. But there are key considerations that should be made, questions to be asked, and de...
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