public function testMostUsedWay()
 {
     // 角色 可以是多个
     $roles = array('Administrators', 'Users');
     $roles = array_merge(array("*"), $roles);
     // 访问控制列表 deny优先
     $acl['allow']['*'][] = 'Index/Index';
     $acl['deny']['*'][] = '';
     $acl['allow']['Administrators'][] = 'admin/*';
     $acl['allow']['Administrators'][] = 'User/*';
     $acl['allow']['Users'][] = 'User/View';
     $acl['allow']['Users'][] = 'User/Signin';
     $acl['allow']['Users'][] = 'User/DoSignin';
     $acl['deny']['Users'][] = 'User/AddUser';
     $configHandle = new LtConfig();
     $configHandle->addConfig(array('rbac.acl' => $acl));
     $rbac = new LtRbac();
     $rbac->configHandle = $configHandle;
     $rbac->init();
     $this->assertTrue($rbac->checkAcl($roles, 'admin/test'));
     $this->assertFalse($rbac->checkAcl($roles, 'User/AddUser'));
 }
示例#2
0
 /**
  * Check if current user have privilege to do this
  * 
  * @return boolean
  */
 protected function checkPrivilege()
 {
     $allow = true;
     if (!empty($this->roles) && class_exists('LtRbac')) {
         $module = $this->context->uri["module"];
         $action = $this->context->uri["action"];
         $roles = array_merge(array("*"), $this->roles);
         $rbac = new LtRbac();
         $rbac->init();
         $allow = $rbac->checkAcl($roles, "{$module}/{$action}");
     }
     return $allow;
 }