我试图理解rbac中的授权,并对一些事情感到困惑。
在accessControl规则中,我使用的角色如下:
return array(
array('allow', // allow all users to perform 'index' and 'view' actions
'actions'=>array('index', 'view'),
'roles'=>array('user'),
),
array('allow', // allow authenticated user to perform 'create' and 'update' actions
'actions'=>array('create','update'),
'roles'=>array('author'),
),
array('allow', // allow admin user to perform 'admin' and 'delete' actions
'actions'=>array('admin','delete'),
'roles'=>array('admin'),
),
array('deny', // deny all users
'users'=>array('*'),
),
);我还使用了以下设置:
$auth = Yii::app()->authManager;
$auth->createOperation('createPost', 'create a post');
$auth->createOperation('readPost', 'Read a post');
$auth->createOperation('updatePost', 'update a post');
$auth->createOperation('deletePost', 'delete a post');
$role = $auth->createRole('user');
$role->addChild('readPost');
$role = $auth->createRole('author');
$role->addChild('user');
$role->addChild('createPost');
$role = $auth->createRole('admin');
$role->addChild('author');
$role->addChild('updatePost');
$role->addChild('deletePost');
$auth->assign('user', 3);
$auth->assign('author', 2);
$auth->assign('admin', 1);
$auth->save();有4种不同的名称操作(createPost、deletePost、readPost、udpatePost)。然而,在控制器中,动作名是不同的,例如actionIndex、actionView、actionCreate、actionDelete、actionUpdate和actionAdmin。
问题:
如何将操作映射到控制器操作。
是否应该创建更多的操作,如IndexPost、ViewPost等?
在使用rbac时,我们是否应该像我在这里所做的那样保留访问控制过滤器和规则?
我不确定我做得对不对。很多困惑和迷失。请放点光。干杯。
发布于 2014-04-06 05:36:34
https://stackoverflow.com/questions/22889282
复制相似问题