RBAC (Role Based Access Control) における 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 がそのコンテキストで指定された配列に設定されている bizRule を評価します。
セキュリティの観点から、これらのビジネス ルールは好きではありません。それを行うより良い方法はありますか?