Jump to content
Larry Ullman's Book Forums
Sign in to follow this  
mint

Rbac Using Database Values

Recommended Posts

I have created Rbac with superadmin,admin1,normaluser. I want to check weather the user is logged in as superadmin, admin1,normaluser depending on the database column "access" value in tbl_user table, if "access"=0 then user should be superadmin, if "access"=1 then user should be admin1 and if "access"=2 then user should be normaluser. RBAC authorization hierarchy was created by yiic shell, all the database schema has been defined. I cannot figure out how to proceed further than creating authorization hierarchy and how to write code to check a user according to roles.

 

 

Here is RbacCommand.php

http://pastebin.com/BKdYM4eg

Share this post


Link to post
Share on other sites

Thanks, the problem is solved.

I did this in the UserIdentity

 

if($user->access==='0')
 {
  if(!Yii::app()->authManager->isAssigned('superadmin',$this->_id))
  {
   Yii::app()->authManager->assign('superadmin', $this->_id);
  }
 }
 else if($user->access==='1')
 {
  if(!Yii::app()->authManager->isAssigned('admin1',$this->_id))
  {
   Yii::app()->authManager->assign('admin1', $this->_id);
  }
 }
 else if($user->access==='2')
 {
  if(!Yii::app()->authManager->isAssigned('normaluser',$this->_id))
  {
   Yii::app()->authManager->assign('normaluser', $this->_id);
  }
 }

 

And Checked if the user has the permission in the respective action

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...