366
Chapter 16: Securing Applications
Using an LDAP Directory for security information
LDAP directories are often used to store security information. The following example of an
Application.cfm page with a
cflogin
tag checks an LDAP directory to authenticate the user and
retrieve the user’s roles.
This example queries the LDAP directory twice, first as the directory manager, then with the
user’s identity:
•
The first query uses the identity of the directory manager as the
username
attribute. This
query gets the distinguished name that corresponds to the user-supplied user ID. Using the
directory manager’s identity ensures that there will be a valid response for any user ID in the
directory.
•
The second query accesses the directory with the distinguished name from the first query as
the
username
attribute, and the user-supplied password as the
password
attribute. This query
succeeds, and thereby authenticates the user, only if the user’s password allows that user to
access the directory. In other words, the application uses the user’s LDAP directory password as
its own password.
For more information on using LDAP directories with ColdFusion, see
Chapter 23, “Managing
LDAP Directories,” on page 477
.
<cfapplication name="Orders" sessionmanagement="Yes" loginStorage="Session">
<cflogin>
<cfif isDefined("cflogin")>
<!--- setting basic attributes --->
<cfset LDAP_root = "o=mycompany.com">
<cfset LDAP_server ="ldap.mycompany.com">
<cfset LDAP_port="389">
<!--- These attributes are used in the first search. --->
<!--- This filter will look in the objectclass for the user's ID. --->
<cfset userfilter = "(&(objectclass=*)(uid=#cflogin.name#))">
<!--- Need directory manager's cn and password to get the user's
password from the directory --->
<cfset LDAP_username = "cn=Directory Manager">
<cfset LDAP_password = "password">
<!--- Search for the user's dn information. This is used later to
authenticate the user.
NOTE: Do this as the Directory Manager to ensure access to the
information --->
<cftry>
<cfldap action="QUERY"
name="userSearch"
attributes="dn"
start="#LDAP_root#"
scope="SUBTREE"
server="#LDAP_server#"
port="#LDAP_port#"
filter="#userfilter#"
username="#LDAP_username#"
password="#LDAP_password#"
>
<cfcatch type="Any">
<cfset UserSearchFailed = true>
</cfcatch>
</cftry>
<!--- If user search failed or returns 0 rows, abort --->
<cfif NOT userSearch.recordcount OR isDefined("UserSearchFailed")>
Summary of Contents for COLDFUSION MX 61-DEVELOPING COLDFUSION MX
Page 1: ...Developing ColdFusion MX Applications...
Page 22: ...22 Contents...
Page 38: ......
Page 52: ...52 Chapter 2 Elements of CFML...
Page 162: ......
Page 218: ...218 Chapter 10 Writing and Calling User Defined Functions...
Page 250: ...250 Chapter 11 Building and Using ColdFusion Components...
Page 264: ...264 Chapter 12 Building Custom CFXAPI Tags...
Page 266: ......
Page 314: ...314 Chapter 14 Handling Errors...
Page 344: ...344 Chapter 15 Using Persistent Data and Locking...
Page 349: ...About user security 349...
Page 357: ...Security scenarios 357...
Page 370: ...370 Chapter 16 Securing Applications...
Page 388: ...388 Chapter 17 Developing Globalized Applications...
Page 408: ...408 Chapter 18 Debugging and Troubleshooting Applications...
Page 410: ......
Page 426: ...426 Chapter 19 Introduction to Databases and SQL...
Page 476: ...476 Chapter 22 Using Query of Queries...
Page 534: ...534 Chapter 24 Building a Search Interface...
Page 556: ...556 Chapter 25 Using Verity Search Expressions...
Page 558: ......
Page 582: ...582 Chapter 26 Retrieving and Formatting Data...
Page 668: ......
Page 734: ...734 Chapter 32 Using Web Services...
Page 760: ...760 Chapter 33 Integrating J2EE and Java Elements in CFML Applications...
Page 786: ...786 Chapter 34 Integrating COM and CORBA Objects in CFML Applications...
Page 788: ......