2

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 设置为给定数组的 bizRule。

在安全性方面,我不喜欢那些业务规则。有更好的方法吗?

4

1 回答 1

2

也许它会对某人有所帮助,如果你有 php 5.3 我认为你可以使用 LambdaFunctions

$bizRule = function ($param) { return $param[1] = $param[2]};
于 2011-02-11T11:48:26.013 回答