44.基于角色的访问控制(Role-Based Access Control)

44.基于角色的访问控制(Role-Based Access Control)_第1张图片
44.基于角色的访问控制(Role-Based Access Control)_第2张图片
44.基于角色的访问控制(Role-Based Access Control)_第3张图片
44.基于角色的访问控制(Role-Based Access Control)_第4张图片

$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');

$bizRule='return Yii::app()->user->id==$params["post"]->authID;';
$task=$auth->createTask('updateOwnPost','update a post by author himself',$bizRule);
$task->addChild('updatePost');

$role=$auth->createRole('reader');
$role->addChild('readPost');

$role=$auth->createRole('author');
$role->addChild('reader');
$role->addChild('createPost');
$role->addChild('updateOwnPost');

$role=$auth->createRole('editor');
$role->addChild('reader');
$role->addChild('updatePost');

$role=$auth->createRole('admin');
$role->addChild('editor');
$role->addChild('author');
$role->addChild('deletePost');

$auth->assign('reader','readerA');
$auth->assign('author','authorB');
$auth->assign('editor','editorC');
$auth->assign('admin','adminD');

44.基于角色的访问控制(Role-Based Access Control)_第5张图片
44.基于角色的访问控制(Role-Based Access Control)_第6张图片
44.基于角色的访问控制(Role-Based Access Control)_第7张图片


'components'=>array(
    'authManager'=>array( 
            'defaultRoles'=>array('guest'),
            'class'=>'RDbAuthManager',
            'assignmentTable'=>'authassignment',
            'itemTable'=>'authitem',
            'rightsTable'=>'rights',
            'itemChildTable'=>'authitemchild',
    ), 
drop table if exists `AuthAssignment`;
drop table if exists `AuthItemChild`;
drop table if exists `AuthItem`;

create table `AuthItem`
(
   `name`                 varchar(64) not null,
   `type`                 integer not null,
   `description`          text,
   `bizrule`              text,
   `data`                 text,
   primary key (`name`)
) engine InnoDB;

create table `AuthItemChild`
(
   `parent`               varchar(64) not null,
   `child`                varchar(64) not null,
   primary key (`parent`,`child`),
   foreign key (`parent`) references `AuthItem` (`name`) on delete cascade on update cascade,
   foreign key (`child`) references `AuthItem` (`name`) on delete cascade on update cascade
) engine InnoDB;

create table `AuthAssignment`
(
   `itemname`             varchar(64) not null,
   `userid`               varchar(64) not null,
   `bizrule`              text,
   `data`                 text,
   primary key (`itemname`,`userid`),
   foreign key (`itemname`) references `AuthItem` (`name`) on delete cascade on update cascade
) engine InnoDB;

http://www.yiichina.com/doc/guide/1.1/topics.auth

http://fkn.ktu10.com/?q=node/3007

http://www.yiichina.com/tutorial/58

http://www.yiiframework.com/extension/authbooster

http://www.yiichina.com/doc/guide/2.0/security-authorization

http://www.yiichina.com/tutorial/46

http://www.yiiframework.com/wiki/328/simple-rbac/

http://blog.sina.com.cn/s/blog_907043b30101emfk.html

你可能感兴趣的:(yii,1.1)