Commit 7b374c41 by Qiang Xue

Fixes #3230: Added `yii\filters\AccessControl::user` to support access control…

Fixes #3230: Added `yii\filters\AccessControl::user` to support access control with different actors
parent cc217e7b
......@@ -30,6 +30,7 @@ Yii Framework 2 Change Log
- Enh #3132: `yii\rbac\PhpManager` now supports more compact data file format (qiangxue)
- Enh #3154: Added validation error display for `GridView` filters (ivan-kolmychek)
- Enh #3222: Added `useTablePrefix` option to the model generator for Gii (horizons2)
- Enh #3230: Added `yii\filters\AccessControl::user` to support access control with different actors (qiangxue)
- Enh: Added support for using sub-queries when building a DB query with `IN` condition (qiangxue)
- Enh: Supported adding a new response formatter without the need to reconfigure existing formatters (qiangxue)
- Enh: Added `yii\web\UrlManager::addRules()` to simplify adding new URL rules (qiangxue)
......
......@@ -10,6 +10,7 @@ namespace yii\filters;
use Yii;
use yii\base\Action;
use yii\base\ActionFilter;
use yii\di\Instance;
use yii\web\User;
use yii\web\ForbiddenHttpException;
......@@ -56,6 +57,10 @@ use yii\web\ForbiddenHttpException;
class AccessControl extends ActionFilter
{
/**
* @var User|string the user object representing the authentication status or the ID of the user application component.
*/
public $user = 'user';
/**
* @var callable a callback that will be called if the access should be denied
* to the current user. If not set, [[denyAccess()]] will be called.
*
......@@ -89,6 +94,7 @@ class AccessControl extends ActionFilter
public function init()
{
parent::init();
$this->user = Instance::ensure($this->user, User::className());
foreach ($this->rules as $i => $rule) {
if (is_array($rule)) {
$this->rules[$i] = Yii::createObject(array_merge($this->ruleConfig, $rule));
......@@ -104,7 +110,7 @@ class AccessControl extends ActionFilter
*/
public function beforeAction($action)
{
$user = Yii::$app->getUser();
$user = $this->user;
$request = Yii::$app->getRequest();
/** @var AccessRule $rule */
foreach ($this->rules as $rule) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment