User Guide

Table Of Contents
236 Chapter 10: Building and Using ColdFusion Components
The following example creates a component method that deletes files:
<cfcomponent>
<cffunction
name="deleteFile" access="remote" roles="admin,manager" output=”no”>
<cfargument name="filepath" required="yes">
<cffile action="DELETE" file=#arguments.filepath#>
</cffunction>
</cfcomponent>
In the example, the cffunction tag includes the roles attribute to specify the user roles allowed
to access it. In this example, only users in the role
admin and manager can access the function.
Notice that multiple roles are delimited by a comma.
For information on ColdFusion security, including the
cflogin tag and role-based security in
ColdFusion MX, see Chapter 16, “Securing Applications,” on page 373.
Using programmatic security
You can implement your own security within a method to protect resources. For example you can
use the ColdFusion function
IsUserInRole to determine if a user is in particular role, as the
following example shows:
<cffunction name="foo">
<cfif IsUserInRole("admin")>
… do stuff allowed for admin
<cfelseif IsUserInRole("user")>
… do stuff allowed for user
<cfelse>
<cfoutput>unauthorized access</cfoutput>
<cfabort>
</cfif>
</cffunction>
Using introspection to get information about components
ColdFusion provides several ways for you to get information about components:
Requesting a component page from the browser
Using the ColdFusion component browser
Using the Dreamweaver MX 2004 component panel
Using the GetMetaData function
Development teams can use the information about components as up-to-date API reference
information.
Note: For information about how to include documentation in CFCs for display using introspection,
see “Documenting CFCs” on page 214.