Jump to content
Larry Ullman's Book Forums

Rbac Using Database Values


mint
 Share

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

Link to comment
Share on other sites

  • 2 weeks later...

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

Link to comment
Share on other sites

 Share

×
×
  • Create New...