2
RBAC(基於角色的訪問控制)中的BizRules的想法讓我感覺不舒服。它基本上是一種定義腳本以在授權期間針對數據運行的方式。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));
它基本上是對企業在其上下文中將$ params設置爲給定數組的規則。
我不喜歡安全性方面的業務規則。有沒有更好的方法來做到這一點?
爲什麼在[SecuritySE(http://security.stackexchange.com/)不問這個了? – AviD 2010-12-12 09:00:23
其實檢查這個[有點問題](http://security.stackexchange.com/q/346/33)。 – AviD 2010-12-12 09:01:18