【发布时间】:2010-12-11 18:58:30
【问题描述】:
RBAC(基于角色的访问控制)中的 BizRules 的想法让我感到恶心。它基本上是一种定义脚本以在授权期间针对数据运行的方法。
例如Yii框架支持:http://www.yiiframework.com/doc/api/1.1/CAuthManager#createRole-detail
public CAuthItem createRole(string $name, string $description='', string $bizRule=NULL, mixed $data=NULL)
这是执行业务规则的源代码:
/**
* Executes the specified business rule.
* @param string $bizRule the business rule to be executed.
* @param array $params parameters passed to {@link IAuthManager::checkAccess}.
* @param mixed $data additional data associated with the authorization item or assignment.
* @return boolean whether the business rule returns true.
* If the business rule is empty, it will still return true.
*/
public function executeBizRule($bizRule,$params,$data)
{
return $bizRule==='' || $bizRule===null || ($this->showErrors ? eval($bizRule)!=0 : @eval($bizRule)!=0);
}
因此,您可以执行以下操作:
// Assume this bizRule: $bizRule='return Yii::app()->user->id==$params["post"]->authID;';
Yii::app()->user->checkAccess('createUser', array('post' => $post));
它基本上对 bizRule 进行评估,其中 $params 在其上下文中设置为给定数组。
我不喜欢那些安全方面的业务规则。有没有更好的方法?
【问题讨论】:
-
为什么不在SecuritySE 上问这个问题?
-
事实上检查这个slightly related question。