Handling errors with ColdFusion
117
<!--- Verify user name from cflogin.name and password from
cflogin.password
using your authentication mechanism. For example, you might store this
information in an LDAP database. --->
>
<cfif cflogin.name eq "bob">
<!--- In this example, bob is in the role of administrator. Typically, you
store user roles with authentication information. --->
<cfloginuser name="#cflogin.name#" password="#cflogin.password#"
roles="Admin">
</cfif>
</cflogin>
</cfsilent>
This example does not show how to perform user verification. For more information on
verification, see
Developing ColdFusion MX Applications with CFML
.
Assigning security roles to component functions
ColdFusion components offer roles-based security. The following example creates a component
method that deletes files:
<cfcomponent>
<cffunction name="deleteFile" access="remote"
roles="admin,manager"
>
<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 admin and manager role can access the function.
Multiple roles are delimited with a comma.
In the Application.cfm file, you use the
cfloginuser
tag to log in the user and assign the user to
a role. The user must be assigned to the correct role to access the component function. For more
information on roles, see
Developing ColdFusion MX Applications with CFML.
Handling errors with ColdFusion
ColdFusion pages and components can return error information to a Flash application if the
ColdFusion code fails. For example, the following Flash application calls a ColdFusion page
named causeError.cfm:
import mx.remoting.Service;
//…
var CFMService:Service = new Service(
"http://localhost/flashservices/gateway",
null,
"errorExample",
null,
null);
CFMService.causeError();