| By Kelly Brown | Article Rating: |
|
| August 23, 2000 12:00 AM EDT | Reads: |
8,432 |
Most commercial Web sites have secure areas that are accessible only to authorized users. Here's one schema for managing access control for a Web site.
Many times you need to limit access to particular templates on your site, either for customers who must purchase enhanced capabilities or for administrative functions available to a select few. The framework described in this article gives you a flexible access control scheme that can easily be added to your Web site.
Database Design
Like all good dynamic systems, this one starts with the database design. It boils down to two simple concepts: users and permissions, where permissions regulate access to various features. We'll have two main tables in our schema: USERS and PERMISSIONS.
The USERS table contains information about the users such as their login name and password. The PERMISSIONS table contains a list of permissions that govern which features a user may or may not access. Each user can be assigned numerous permissions so we need an additional table, USER_PERMISSIONS, to represent this many-to-many relationship (see Figure 1).
This structure gives us a great deal of flexibility. We may only want to define permissions to distinguish between administrative and normal users, or we may want a finer-grained approach with permissions for each ColdFusion template on our site. With this database design we can define as many permissions as we need.
Using Session Variables
We've defined our permissions, but how do we use them? This is where our old friend the session variable comes into play. Typically, when you log in we set a flag in a session variable to track your login. We'll add an additional variable to your session that keeps a list of your permissions. Once this session variable is set, we can check it in our templates to see if you have access.
Code Walk-Through
The two steps to implementing this permission framework in ColdFusion are:
- Setting the permissions as part of the login process
- Checking the permissions in our templates
Checking for permissions in our template is straightforward. We examine the list of permissions in your session variable to see if it contains the one needed to access this template. If the permission isn't found, we display a message stating this, then we stop the remainder of the template from running.
<CFIF ListFind(Session.permissions, "Admin") IS 0>We can also use the permissions in other ways. For instance, we may not want to display links to pages you don't have permission to access. In the following example we'll show the link to the administrative report only if you have the "Admin" permission.
<CFINCLUDE TEMPLATE="NoAccessMessage.cfm">
<CFABORT>
</CFIF>
<CFIF ListFind(Session.permissions, "Admin") IS 1>Conclusion
<A HREF="AdminReport.cfm">Administrative Report</A>
</CFIF>
This framework is straightforward and can easily be incorporated into most sites. It gives you the flexibility to have simple or complex permissions as needed, and can be used in many types of sites from an intranet with administrative privileges to an e-commerce site in which customers can purchase additional permissions. Try it out!
Published August 23, 2000 Reads 8,432
Copyright © 2000 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By Kelly Brown
Kelly Brown is the CTO of About Web (www.aboutweb.com), an Internet solutions provider in the Washington, DC, area. He has a BS and MS in computer science and is a Microsoft-certified systems engineer.
- Adobe’s Aiming ColdFusion at Multiple Clouds
- Cloud Computing Journal: Adobe to Deliver ColdFusion in the Cloud
- Adobe Reader Sued
- Adobe May Cooperate with Apple to Transplant Flash Player to iPhone
- Adobe Flex Developer Earns $100K in New York City
- Adobe LiveCycle Enterprise Suite 2 for Cloud Computing
- Adobe Cans Another 9% of its Workforce
- Adobe Betas Target RIAs and Cloud Computing
- Adobe MAX 2009 Online
- Thinking of Flex in London
- Moyea DVD4Web Converter V2.0 Converts DVD to FLV Fast and Synchronously with Watermarks
- Adobe & Salesforce Cut Cloud Deal
- Adobe’s Aiming ColdFusion at Multiple Clouds
- Eval JavaScript in a Global Context
- Fig Leaf Software to Exhibit at Government IT Conference & Expo
- Is Microsoft as Free as Open Source?
- Cloud Computing Journal: Adobe to Deliver ColdFusion in the Cloud
- Adobe Reader Sued
- The Planet Named “Bronze Sponsor” of Cloud Computing Expo
- Microsoft Expression Web Has Got Game
- Adobe May Cooperate with Apple to Transplant Flash Player to iPhone
- Bruce Chizen Joins Voyager Capital as Venture Partner
- My Top Seven Wishes From Adobe MAX 2009
- Adobe Flex Developer Earns $100K in New York City
- The Next Programming Models, RIAs and Composite Applications
- Where Are RIA Technologies Headed in 2008?
- Constructing an Application with Flash Forms from the Ground Up
- AJAX World RIA Conference & Expo Kicks Off in New York City
- CFEclipse: The Developer's IDE, Eclipse For ColdFusion
- Personal Branding Checklist
- Adobe Flex 2: Advanced DataGrid
- Has the Technology Bounceback Begun?
- Building a Zip Code Proximity Search with ColdFusion
- i-Technology Viewpoint: We Need Not More Frameworks, But Better Programmers
- The Asynchronous CFML Gateway
- Web Services Using ColdFusion and Apache CXF



































