ColdFusion Tips and Tutorials

ColdFusion Tips and Tutorials. Tips on ColdFusion, AJAX, CSS, JavaScript, HTML, Design, and more.

CFUnited Developer Conference 2010
Use this code TIPSCUST to get $100 off your registration @ CFUnited! We'll see you There!


ColdFusion Tips
Page 1 2 3
148 ColdFusion, Ajax, FuseBox, Tips, and Tut
147 Included Point of View
146 Javascript - OnFocus
145 Nathan's Rules of Professional Web Desig
144 Universal Server-Side Check | Bandwidth
143 Meeting Schedule | Identification Sessio
142 Breaking Frames Without Javascript
141 Unreal Forms
140 Screen Resolution
139 Human Help
138 Better Server-Side Validation
137 Automatic Server-Side Validation
136 Regular Expression Laboratory,ColdFusion
135 Rank-Ordered Site Search
134 Building Cryptograms
133 Well-Formed Includes
132 Grouping Families for Visits
131 Display Families on a Map Grid
130 Slide Shows
129 Determine Your Database Engine
128 ColdFusion in Context: Maxlength Lies
127 Something Extra
126 Parsing Database Structure from Data Def
125 Valid Values Maintenance
124 Print 1
123 Hide Session Id
122 Downsizing Data to Access
121 Time to Load a Page, FuseBox 4
120 Order and Rank by Subset
119 Warn through E-mail & Update on Paste Sp
118 Paste Spreadsheets, ColdFusion Component
117 Review Files Having Fixed-Length Fields
116 Organized Help
115 Sequence Slider
114 Bad Bits
113 Logical Deduction
112 Whiteout
111 Forced Navigation
110 Managing Permissions
109 Time Travel
108 Test First
107 Get Distance Between Map Coordinates
106 Validating Checkboxes
105 Matrix Manipulation
104 Field Help
103 Fake Object Not Found
102 Rank Order Correlation Coefficient
101 From Calling Pairs to Calling Tree
100 Posting Notice
99 Logout Persuasion
98 Release Session Memory
97 Use Identically Named Fields
96 Web Bug
95 Password Generation
94 Core Queries
93 Use CFFTP
92 Insert, Update, and Delete
91 Stack
90 T-Value
89 Bulk Data Entry and E-mail Validation
88 Quick Reset
87 Design 1
86 Use CFFTP
85 Support Login with AutoPost
84 Login and Site Protection
83 XY Graphs in a Graphing Calculator
82 Read Encrypted Files
81 Showing Progress
80 Frugal Cross-Browser Javascript
79 Tabbed Folders
Page 1 2 3



Custom Search
ColdFusion TIPS PLUS


Issue 00110 http://www.cftipsplus.com

I. My Comments

II. ColdFusion In Context: Managing Permissions
By R. Martin Ladner
martin.ladner@charter.net



See our sponsors at the bottom of this e-mail.

I. Comments:

Hope your doing well. If you would like to donate to CFTipsPlus.com Simply click on this link.

https://www.paypal.com/xclick/business=admin%40nsnd.com&item_name=CFTipsPlus



Keep Coding,
Nathan Stanford
http://www.cftipsplus.com

If you have suggestions for articles send them to us.
If you would like to write for cftipsplus.com
send us an email to:

NathanS<at>nsnd.com

IF YOU WANT TO BE AN AUTHOR SEND IN YOUR COLDFUSION TIPS.

Remember this is a great way to get your name known in the
ColdFusion Community.



II. ColdFusion in Context: Managing Permissions
By R. Martin Ladner
martin.ladner@charter.net


Suppose that not everyone who logs into your Web site should be able to change it or to read sensitive information. Here's a example of how you might make the permission information queried at login available to each page that needs it within the Web site.
Build a "Login" Page
Put this code in login.cfm. Simply invoke session management. Pretend that the login process has built a structure consisting of available functions and the user's access to those functions. Lock the session and copy the permission data to session memory. Let the cfdump tag demonstrate the new state of session memory. A simple form lets you leave this page when you're satisfied.

This is a pretend login page. It shows a way to invoke session management and set session variables as a result of a real login process.

<!--- Invoke session management --->
<cfapplication name="Permitdemo"
sessionmanagement="yes">

Here are the session variables after "login".

<!--- Set permissions as if by login --->
<cfset Temp=structNew()>
<cfset dummy=structInsert(Temp, "WELCOME", "RU")>
<cfset dummy=structInsert(Temp, "ARTICLES", "A")>
<cfset dummy=structInsert(Temp, "USERS", "R")>

<cflock scope="session" timeout="30" throwontimeout="yes" type="exclusive">
<cfset session.Permit = Temp>
<cfdump var="#session#">
</cflock>

<form method="post" action="Work/Demo.cfm">
<input name="doit" type="submit" value="Go">
</form>

Create Application.cfm
Application.cfm gets included by every attempt to browse a ColdFusion page. That makes it a useful place to retrieve permissions from session memory. To avoid conflicts with the code in the login page, create a work directory and put Application.cfm (and the code that actually performs the functions of your site) in that directory rather than in the root directory.

Put the following code in Work/Application.cfm. Invoke session management, making sure to use the same application name as you used for the login function. Structcopy would just copy pointers. Use the duplicate function instead to copy the actual values from session scope to request scope. The entire structure gets copied by just one line of code (inside of a cflock tag). This time, a readonly lock is good enough; you're not writing to memory.

The access function will make it easy for the individual pages to get information out of the permission structure. You don't have to declare the function's variables (var...), but if you don't, they will be visible to and may interfere with other ColdFusion functions. Check to see if the key exists to avoid throwing an error. If it does exist, find the associated value. If the value is "A" or contains the needed access, return true.


<!--- Invoke session management --->
<cfapplication name="Permitdemo"
sessionmanagement="yes">

<!--- Write variables from session memory to disk (request scope) --->
<cflock scope="session" timeout="30" throwontimeout="yes" type="readonly">
<cfset request=duplicate(session)>
</cflock>

<!--- Define access function --->
<cfscript>
function allow(TheAction, TheAccess) {
var Answer = "";
var Verdict = false;
if (structKeyExists(request.Permit, TheAction)) {
Answer = structFind(request.Permit, TheAction);
if (Answer contains TheAccess) {
Verdict = true;
}
else if (Answer contains "A") {
Verdict = true;
}
}
return Verdict;
}
</cfscript>

Make a Demonstration Page
Place this code in Work/Demo.cfm. The cfdump tag comes to the rescue again, this time to demonstrate that the session data was successfully copied to the request scope. You would usually use the access function in a decision statement to permit or deny the use of a given function based on the relationship between the user's access and the access required by the code for this function. To show how the access function works with various combinations of data, its output is simply dispayed for this demonstration. Note that user permission of "A" covers all bases, while if the activity to be performed is not named in the user's permission variable (Permit) at all - see CALENDAR - the access function returns a value of false to block access.

Here are the request variables available without locks to all pages browsed in this directory.
<cfdump var="#request#">
<p>
Can this user...
<p>
<cfoutput>
Read the welcome banner? #allow("WELCOME","R")#<br>
Update the welcome banner? #allow("WELCOME","U")#
<p>
Create new articles? #allow("ARTICLES","C")#<br>
Read articles? #allow("ARTICLES","R")#<br>
Update articles? #allow("ARTICLES","U")#<br>
Take other actions with articles
(delete, archive, mail, etc.)? #allow("ARTICLES","A")#
<p>
Create user accounts? #allow("USERS","C")#<br>
Read user accounts? #allow("USERS","R")#<br>
Update user accounts? #allow("USERS","U")#<br>
Take other actions with user accounts? #allow("USERS","A")#<br>
<p>
Create calendar items? #allow("CALENDAR","C")#<br>
Read calendar items? #allow("CALENDAR","R")#<br>
Update calendar items? #allow("CALENDAR","U")#<br>
Take other actions with calendar items?
#allow("CALENDAR","A")#
</cfoutput>

Have Fun
Details have been glossed over here. We took the defaults for session management. This tip doesn't get in to the mechanics of getting the permission data out of the database in the first place. However, there's enough information here for you to readily control any site function based on user permissions determined at login.
=Marty=



SPONSOR ADS:
This e-mail is sponsored by the following ads.


Books For Sale
http://nsnd.vstorelibrary.com/



Advanced, Intensive ColdFusion Training!
Visit this site. If you have plans to get training here is a company
that provides Advanced, Intensive ColdFusion Training. Check them out.
http://www.coldfusiontraining.com/index.cfm?ref=cftipsplus



Publisher and Creator:
Nathan Stanford,
NathanS<at>nsnd.com
http://www.cftipsplus.com

Macromedia and ColdFusion are U.S. registered trademarks.


Copyright (c) 2000 - 2002
CFTIPSPLUS.COM and NSND.COM

Permission is granted to circulate this publication via
MANUAL forwarding by email to friends provided that the text is
forwarded in its entirety and no fee is charged.

Photo of Nathan Stanford
Nathan Stanford
LinkedIn

R. Marty Ladner's
Site