views:

630

answers:

5

I'am working on a PHP + MySQL Social Networking application, now i need to setup different access control (read,create,edit,delete) for global (all items) and/or self items (item which created by themselves) for each module to group or specific user.

Does anyone has suggestions in doing this (table structures, etc)?

+5  A: 

That's a pretty broad question, so you're likely to only get very broad answers.

Most CMS systems have a table that lists the types of content that can be produced on the system.

Another table describes how each type of content is displayed (on the front page, on individual blog pages, etc).

Another table gives each user one or more "user types" or "groups" such as admin, unregistered, moderator, etc.

A last table is an access table of sorts - it shows what each group has power to do, including the types of content it can create, edit, publish, etc.

I recommend you spend a little time studying the database schemas of other CMS software, such as Slashcode, Drupal, or one of the other millions of CMS systems.

Adam Davis
+1  A: 

It is in fact a very broad question. Assuming you have a clear separation of application tiers (eg, using MVC), then this is the sort of stuff going in the business layer.

Taking your direct requirements, it could be fairly simple. In your users table, have a hasEdit, hasView, etc. For each item, attach a userid to it representing the creator. In the business layer, the rule is they have edit permission if they are the creator, or they have hasEdit = true.

Taking it up a notch, if you have different types, and the hasEdit permission is per-type, you need another entity for that.

userPermission

  • userPermissionId
  • userId (FK)
  • typeId (FK)
  • hasEdit (boolean)
  • hasView
  • etc..

To find out if they have permission to edit, you check if either they're the owner, or look up that items type and the current user in the userPermission table, and check hasEdit. You could make additional rules, like putting a global hasEdit in the user table. Or representing global hasEdit by an entry in userPermissionId with a NULL typeId.

This can get way more complex, using roles and variable numbers of permissions.. it all comes down to your requirements. You need to carefully spec out your business requirements (come up with a bunch of use cases), and then you can design from there. As is, there's really not enough information to come up with anymore than I've outlined here (and even this is probably not exactly what you need).

gregmac
A: 

I like to use a kind of firewall rules approach or similarly a mysql tables rules approach: you can grant users or groups of users certain rights on certain objects or groups of objects. Make each rule be a row in your rules table. When you need to do an action like edit, you can inner join on your rules table for the current user, current user's group, the boolean edit column and the object id or object group. If you get any rows back then the permission is granted.

MattSmith
A: 

There are quite a few ways of designing security, and I've liked quite a few for different situations. There's UNIX-style user-group-other. I happen to like PmWiki's security model.

I developed a website which used user-role-permissions structure similar to Apache. With that website, I used a template system that used a header include file and a footer include file to wrap the page contents with the "standard stuff". A page with restricted content could set a variable to the required permission, that the header script looks for, and if set, calls an auth function that checks the user belongs to a role that permission.

The nice thing about using the user-role-permissions model is if most of your users fall into neat categories of authorization, setting the authorization for a user is a simple matter of adding the right role to that user. The permissions are linked to roles, not users directly, so you can adjust the permissions of entire classes of users easily.

dj_segfault
A: 

okay here i provide more detail, currently i have a tbl_module, tbl_user, and tbl_user_role. Each user and role can have different access to specific module.

  • read
  • update
  • create
  • delete

and devided by global access or self only (own account or records created by themselves).

and my current approach: i create another table to hold the access detail:

  • acl_uid
  • mod_id (fk module uid)
  • target_id (fk user uid or role uid)
  • acl_type (user/role to identify the target id reference)
  • acl_read
  • acl_update
  • acl_create
  • acl_delete

acl_read, acl_update, acl_create, acl_delete value ranges:

  • 0 deny
  • 1 allow
  • 2 refer to lower priority check (if user has value 2 then refer to role)
  • 3 self only

i believe that theres more efficient way to solve this, or may an improvement to my current approach.

thanks for your responses.

Ariel