User Guide

Table Of Contents
Implementing user security 399
if (IsUserInRole("Manager"))
WriteOutput("Managers see this message.<br><br>");
if (IsUserInRole("Employee"))
WriteOutput("Employees see this message.<br><br>");
if (IsUserInRole("Contractor"))
WriteOutput("Contractors see this message.<br><br>");
</cfscript>
</body>
</html>
Reviewing the code
The following table describes the securitytest.cfm page CFML code and its function:
Using an LDAP directory for security information
LDAP directories are often used to store security information. The following example of a
cflogin tag checks an LDAP directory to authenticate the user and retrieve the users roles.
For more information on using LDAP directories with ColdFusion, see Chapter 23, “Managing
LDAP Directories,” on page 515.
<cfapplication name="Orders" sessionmanagement="Yes" loginstorage="Session">
<cflogin>
<cfif isDefined("cflogin")>
<!--- setting basic attributes --->
Code Description
<cfoutput>
<h2>Welcome #GetAuthUser()#!</h2>
</cfoutput>
Displays a welcome message that
includes the user’s login ID.
ALL Logged-in Users see this message.<br>
<br>
Displays this message in all cases. The
page does not display until a user is
logged in.
<cfscript>
if (IsUserInRole("Human Resources"))
WriteOutput("Human Resources members
see this message.<br><br>");
if (IsUserInRole("Documentation"))
WriteOutput("Documentation members see
this message.<br><br>");
if (IsUserInRole("Sales"))
WriteOutput("Sales members see this
message.<br><br>");
if (IsUserInRole("Manager"))
WriteOutput("Managers see this
message.<br><br>");
if (IsUserInRole("Employee"))
WriteOutput("Employees see this
message.<br><br>");
if (IsUserInRole("Contractor"))
WriteOutput("Contractors see this
message.<br><br>");
</cfscript>
Tests whether the user belongs to each
of the valid roles. If the user is in a role,
displays a message with the role name.
The user sees one message per role to
which he or she belongs.