Note that there are some explanatory texts on larger screens.

plurals
  1. PORBAC in Yii - access checking
    primarykey
    data
    text
    <p>I have a role, task and operation hierarchy set up, and assigned to users, with operations mirroring controller:action.</p> <p>From the <a href="http://www.yiiframework.com/doc/guide/1.1/en/topics.auth#role-based-access-control" rel="nofollow">docs</a>, if I want to check that a user has access to an operation, I check, e.g:</p> <pre><code>if(Yii::app()-&gt;user-&gt;checkAccess('createPost')) </code></pre> <p>This gives the impression that I have to manually add code in every action to check if the user is authorised to the corresponding role. Am I missing something - surely there's a way of doing this automatically for each action.</p> <p>I could probably extend the base Controller class and add something (in preFilter?) that uses Yii::app()->controller and Yii::app()->controller->action to generate the role, and then checks the user is authorised to that role.</p> <p>But I'm sure there must be a way of doing this already?</p> <p>I know the accessRules filter allows you to pass roles in, but that seems to defeat the purpose of having a role>task>operation hierarchy, and having to assign such rules to each action is nearly as bad as doing the check in each function in the first place.</p> <p>Is there some other option I'm missing that will automatically check that a user performing e.g. /item/delete is authorised to the operation 'item:delete' (or whatever format is expected in the DB AuthItem table)?</p> <p><strong>EDIT</strong><br> Clarifying my issue with accessRules alongside database RBAC:</p> <p>I define a role structure in my database - a number of roles, each of which is authorised to multiple tasks, which in turn are composed of granular operations (e.g. role 'Reader' might be authorised to task 'Browse Posts', which is made up of 'post/index' and 'post/view'). I then assign a user to a role, which grants them authority to that role's tasks, and the operations within those tasks. If I then call <em>user->checkAccess</em> for a controller action (i.e. operation), it checks in the DB that the user is authorised to a role, which contains a task, which includes that operation.</p> <p>But, if I go through each controller and define what roles are authorised to each action, I'm duplicating the work I've already done in the database, possibly with conflicting rules.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload