SQL Recipes (Beta II)
A FREE cookbook for SQL queries and examples
Register FAQ Search Today's Posts Mark Forums Read

Database Design Find articles on variouse database design topics

Go Back   SQL Recipes a FREE cookbook of SQL queries and examples > Articles > Database Design

Reply
 
LinkBack (27) Thread Tools Search this Thread Rating: Thread Rating: 2 votes, 5.00 average.
  27 links from elsewhere to this Post. Click to view. #1 (permalink)  
Old 05-29-2006, 01:45 PM
ben ben is offline
Administrator
 
Join Date: Mar 2007
Posts: 77
ben has disabled reputation
Default Fine Grained Role Based Access Control (RBAC) system

Here is a the database design for a "fine grained" Role Based Access Control (RBAC) system I am currently working on.



The general concept is that a user can have one or more roles.
  • Each role is defined in the in "rabac_roles_has_domain_privileges" table.
  • A role is defined as the right (or denial) to exert a privilege on a domain.
  • A role is given an 'importance', i.e. an integer value between 0 and 100. The higher the number the greater the importance.
  • A domain is a collection of objects a user may want to access (or perform an action on), such as a 'member page' or 'forum topic'.
  • A privilege is a collection of actions a user may want to perform on an object, such as 'view', 'add', 'delete', 'edit'.
Briefly (and I will be adding more information with time)
  • A domain can either be singular or plural.
  • A domain is "plural" if it is a collection of more than one object.
  • A domain is "singular" if it corresponds to only one object (so the object and domain name will be the same)
The same can be said about actions. (At this stage it is worth noting that plural domains will always finish with a 's'. Domains and objects are named by 'nouns' whereas, privileges and actions are named by 'verbs'.).

A role is defined by several domain-privilege pairs.
  • Domains that are singular have precedence over their corresponding object defined in a plural domain. This is important to define "fine-grained" role permissions.
For example, a singular domain defined by the action 'view' will have precedence over a plural domain defined by the actions 'add', 'edit', 'view'. (The plural domain also contains the action 'view' but will yield to the singular domain.)
The same can be said for privileges.

Here are somemore pictures that should hopefully clarify things:

Users has roles

This picture shows that the user 'ben' has the 'administrator' and the 'member' role. This is just an example since the 'administrator' role automatically has access to all objects and can perform all actions.

Roles definition

The administrator role is the most important, followed by moderator, then member and finally the last is public.
NOTE: Two different roles can have the same importance. This is allowed.

Roles as permissions

Take a look at the moderator role definition. You will see that the moderator can perform all_actions on all_objects, except for the 'admin_page', which he is only allowed to view.

Privileges has actions

This picture clarifies the idea of 'singular' and 'plural'. Hopefully it is self explanatory.

Domains has objects


This project (including the admin panel) is 95% complete. It is already useable and written in PHP, so if you would like to try it out send me an email at ben at sqlrecipes dot com (If you do try it out, I would appreciate your feedback and suggestions.)

The system is distributed under the BSD license and requires the ADODB database connection layer (ADOdb Database Abstraction Library for PHP (and Python) for MySQL, PostgreSQL, Microsoft SQL Server, Oracle, Firebird, Interbase, LDAP, Access, VFP, DB2 and many other databases) as well as a MySQL database server.

If you have any suggestions concerning this article please post your comment below.
Attached Files
File Type: zip RBAC.zip (21.0 KB, 400 views)
File Type: zip rbac_admin.zip (261.4 KB, 353 views)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 05-29-2006, 01:45 PM
ben ben is offline
Administrator
 
Join Date: Mar 2007
Posts: 77
ben has disabled reputation
Default Update

The project is now 95% complete, I still need to add a few more API methods and tidy things up. The admin Control Panel is completely finished though, so you can administer roles, privileges and domains using a GUI.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 09-17-2006, 03:38 AM
pcdinh
 
Posts: n/a
Default Need help

How can I check if an user A with role id 1 can perform action READ or EDIT from module ARTICLE on article_id 8 that was originally owned by user_id 4?

Thanks

Dinh
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Edit/Delete Message Reply With Quote
  #4 (permalink)  
Old 09-17-2006, 05:43 PM
ben ben is offline
Administrator
 
Join Date: Mar 2007
Posts: 77
ben has disabled reputation
Default RE: Need help

Hi Dinh,

There are several ways of doing this.

1) One Is to create a "super user" role that enables users to edit anyones articles. You then assign that role to user A.

If it is important that the article_id be 8 and that the user who created the article be user_id = 4, you will have to make these checks manually as this is not related to the RBAC logic.

One you have done the test your pseudo code would look something like:

$user_id = 1

if ( isAllowedTo($user_id, 'read_edit', 'article')){
Do what ever you want here
}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 09-22-2006, 12:20 PM
ben ben is offline
Administrator
 
Join Date: Mar 2007
Posts: 77
ben has disabled reputation
Default Somemore info

You may be wondering whether it is possible to find out all the privileges a user is allowed to perform with just one query. The answer is YES.
This means you could find out all the privileges a user has when they login, store the information in $_SESSION and you won't have to query the database again. Doing it this way, checking a users right to perform a certain action is extremely fast.


You will also be able to find out all the users that are able to perform a certain action on a given object with just one query as well.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 09-22-2006, 10:34 PM
ben ben is offline
Administrator
 
Join Date: Mar 2007
Posts: 77
ben has disabled reputation
Default It is all in the design

The critical part of the RBAC implementation is the database design. Everything flows from there. (So take the time to study the design. Once you get it, everything else falls into place). Once your design is right you should be able to obtain all the infromation you need with just one query (and perhaps a little post processing to find out which privilege has priority over another.).

So there are really no secrets... all the information is on this page, which means you should be able to implement an RBAC system in any programming language. If you want to see how I did it in PHP send me an email. I would be interested to hear from people who want to port it to other languages.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 11-20-2006, 06:52 AM
ben ben is offline
Administrator
 
Join Date: Mar 2007
Posts: 77
ben has disabled reputation
Default Interesting email with answers

> I followed most of the article that you wrote on your site and the
> document that you published about Authorize_bv, but there is a couple of
> things that I do not get.
>
> Firstly, the data model that you provided with the article does not seem
> to allow/disallow certain permissions directly to the user. What I mean
> is that lets say the user belongs to a "moderator" role, that has "read"
> access to "all_pages", how would you take read access away from this
> user without making modifications to the role "moderator"? I see you use
> something similar to this in the PDF document of Authorize_bv, but I
> fail to see how it will fit in the current data model.
>
Yes, Authorize_bv did this on the 'user' level, which means each user would have personal privileges assigned to them. Even though it seems at first more flexible it is not efficient and requires more database entries. That is when I moved to the role based approach. Rather than assign privileges to each user, you now assign the privileges to a 'role' and then each user is assigned a role. This makes it a lot more flexible to modify and administer. (i.e. instead of changing each users priviliges, which could run in the thousands..., you now only need to change one role definition.)

The way to achieve your aim using the role based approach is to create a new role called 'moderator_read_disabled' and give it an importance greater than the 'moderator' role. You could then define the new role as 'read'action 'disabled' on 'all_pages'.
You then assign this new role to the users (i.e. moderators) you want. Since it has a higher importance than the standard 'moderator' it will take precedence, but only for the 'read' action that affects the 'all_pages' domain. The other moderator privileges will work as normal.

> How would you handle groups of users? Lets say we have 10 users in a
> department, and these 10 must have access to "moderator". Is there some
> functionality to allow me to put these 10 in a group and then assign the
> "moderator" role only to the group?
>
This would be easy to implement. All you would need to do is instead of assigning roles to individual users you would assign roles to 'groups'. If you look at the first image on this thread you will see the second table from the top is called 'rbac_users_has_roles'. Instead of storing user_ids you would store group_ids and just change the field and table names accordingly.

You would also need 2 more tables to define your groups and another to keep the many-to-many relationship between the users and the groups. However if these tables already exist in your system the rbac_bv class can easily be integrated into it.

This would only require minor changes to the API, namely changing a few field names and table names in the SQL queiries.

> I would like to see what your final product looks like as I am also
> doing some research in this area. I also went through LiveUser, but to
> be quite honest, it looks a bit dodgy and heavy. I like your version
> more, but I am just curious about the above questions.
>
I hope these explanations help. Please feel free to ask more questions.
In reality there isn't much to a role based access control system. Once the database design is done all you are really doing is querying the database to find out if a user can peform a certain action on a given object.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 12-21-2006, 08:35 PM
ben ben is offline
Administrator
 
Join Date: Mar 2007
Posts: 77
ben has disabled reputation
Default Intersting questions concerning articles

I received an email the other day asking whether the RBAC system can be used to manage numerous articles, and whether it is possible to find out which articles a person is allowed to read the moment they log into a system.


The answer to both these questions is 'yes'.

An article is just an 'object'. You can group articles that belong to a certain category into a 'domain'.

Let say there are two types of articles. Ones that are for the public and others that are private (or sensitive.)
We can then create two domains named 'public articles' and 'private articles' and assign the various articles to them.

We then create a role called 'view public articles' that defines the privilige to 'view' 'public articles'.
Let's say we want to play it safe and make sure that the 'view public articles' role is not allowed to view 'private articles', so we add this requirement to the 'view public article' role. (We would only do this if there is a chance of making a mistake and assigning an already marked private article to the public domain.)

We then need to assign users to roles so that we can determine which users are allowed to read what.

Once this is done we can then find out which articles a person can read the moment they login with just one query.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 02-06-2007, 09:23 AM
ben ben is offline
Administrator
 
Join Date: Mar 2007
Posts: 77
ben has disabled reputation
Default Some Help?

If any of yo would like to contribute some documentation, or perhaps some notes that would help others get up to speed with the system please post them here.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 02-14-2007, 06:53 AM
Cem Gencer
 
Posts: n/a
Default thanks & best regards...

thank you very much for sharing this package with us; i will check the whole class out and try to port it to CodeIgniter with maybe removing Adodb...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Edit/Delete Message Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may post new threads
You may post replies
You may not post attachments
You may edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

LinkBacks (?)
LinkBack to this Thread: http://www.sqlrecipes.com/database_design/fine_grained_role_based_access_control_rbac_system-3/
Posted By For Type Date
Rechtensysteem voor website - Software Engineering & Architecture - GoT This thread Refback 02-08-2008 03:12 PM
Rechtensysteem voor website - Software Engineering & Architecture - GoT This thread Refback 02-05-2008 08:17 AM
atakan.dogan's bookmarks tagged with This thread Refback 01-10-2008 06:16 AM
Pages tagged with This thread Refback 01-08-2008 12:01 PM
atakan.dogan's bookmarks on del.icio.us This thread Refback 01-07-2008 08:26 AM
heberm's bookmarks tagged with This thread Refback 01-06-2008 09:12 PM
Rechtensysteem voor website - Software Engineering & Architecture - GoT - Powered by React This thread Refback 01-06-2008 06:05 PM
qWikiOffice Blog » Blog Archive » Database Design This thread Refback 01-05-2008 06:03 PM
Rechtensysteem voor website - Software Engineering & Architecture - GoT - Powered by React This thread Refback 12-25-2007 09:00 AM
Rechtensysteem voor website - Software Engineering & Architecture - GoT - Powered by React This thread Refback 12-22-2007 01:39 PM
amii's bookmarks on del.icio.us This thread Refback 12-21-2007 01:02 PM
ECRM:AccessControl - FaithHighway Wiki This thread Refback 12-19-2007 09:34 PM
Which is best for ACL? | CodeIgniter Forums This thread Refback 12-02-2007 02:45 AM
Rechtensysteem voor website - Software Engineering & Architecture - GoT - Powered by React This thread Refback 11-10-2007 02:26 PM
StumbleUpon » deepakpradhan's web site reviews and blog This thread Refback 11-03-2007 11:18 PM
scorpiol's bookmarks on del.icio.us This thread Refback 10-21-2007 09:23 AM
Rechtensysteem voor website - Software Engineering & Architecture - GoT - Powered by React This thread Refback 10-19-2007 01:26 PM
Rechtensysteem voor website - Software Engineering & Architecture - GoT - Powered by React This thread Refback 10-18-2007 08:38 PM
Rechtensysteem voor website - Software Engineering & Architecture - GoT - Powered by React This thread Refback 10-18-2007 08:36 PM
mithras86's bookmarks tagged with This thread Refback 09-28-2007 09:06 PM
mithras86's bookmarks on del.icio.us This thread Refback 09-24-2007 01:22 PM
heberm's bookmarks on del.icio.us This thread Refback 08-30-2007 12:46 PM
onisemus' bookmarks tagged with This thread Refback 08-14-2007 09:15 PM
onisemus' bookmarks on del.icio.us This thread Refback 08-02-2007 02:40 PM
Scaffolding | CodeIgniter Forums This thread Refback 07-06-2007 09:41 AM
konvergal's bookmarks on del.icio.us This thread Refback 06-29-2007 10:06 PM
dynasync's bookmarks tagged with This thread Refback 06-26-2007 01:39 AM


All times are GMT. The time now is 08:46 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0
Copyright (c) 2006-2007 SQL Recipes

1 2 3 4 5 6 7