From f43144ff1d59b6559c2332b7b7bf705187d9d99f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=87=E5=B0=91=E6=B3=A2?= <756684177@qq.com> Date: Wed, 1 Jun 2022 16:20:21 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E7=AE=80=E5=8C=96=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E8=AF=BB=E5=8F=96=202=E3=80=81=E7=AD=96?= =?UTF-8?q?=E7=95=A5=E6=A8=A1=E5=9E=8B=E6=94=AF=E6=8C=81=E5=A4=9A=E4=B8=AA?= =?UTF-8?q?=EF=BC=8C=E9=BB=98=E8=AE=A4=E4=B8=BA=E7=AC=AC=E4=B8=80=E4=B8=AA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Permission.php | 13 +++++---- .../casbin/webman-permission/permission.php | 28 +++++++++++++++++-- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/src/Permission.php b/src/Permission.php index cff8dd3..1165d0c 100644 --- a/src/Permission.php +++ b/src/Permission.php @@ -61,15 +61,16 @@ class Permission implements Bootstrap public static function start($worker) { if ($worker) { - $configType = config('plugin.casbin.webman-permission.permission.basic.model.config_type'); + $driver = config('plugin.casbin.webman-permission.permission.default'); + $config = config('plugin.casbin.webman-permission.permission.'.$driver); $model = new Model(); - if ('file' == $configType) { - $model->loadModel(config('plugin.casbin.webman-permission.permission.basic.model.config_file_path')); - } elseif ('text' == $configType) { - $model->loadModel(config('plugin.casbin.webman-permission.permission.basic.model.config_text')); + if ('file' == $config['model']['config_type']) { + $model->loadModel($config['model']['config_file_path']); + } elseif ('text' == $config['model']['config_type']) { + $model->loadModel($config['model']['config_text']); } if (is_null(static::$_manager)) { - static::$_manager = new Enforcer($model, Container::get(config('plugin.casbin.webman-permission.permission.basic.adapter')),false); + static::$_manager = new Enforcer($model, Container::get($config['adapter']),false); } $watcher = new RedisWatcher(config('redis.default')); diff --git a/src/config/plugin/casbin/webman-permission/permission.php b/src/config/plugin/casbin/webman-permission/permission.php index 069abad..72b3433 100644 --- a/src/config/plugin/casbin/webman-permission/permission.php +++ b/src/config/plugin/casbin/webman-permission/permission.php @@ -6,20 +6,42 @@ */ return [ 'default' => 'basic', + // 基础配置 'basic' => [ - # Model 设置 + // 策略模型Model设置 'model' => [ 'config_type' => 'file', 'config_file_path' => config_path() . '/plugin/casbin/webman-permission/rbac-model.conf', 'config_text' => '', ], - # 适配器 + // 适配器 'adapter' => Casbin\WebmanPermission\Adapter\DatabaseAdapter::class, // ThinkORM 适配器 // 'adapter' => Casbin\WebmanPermission\Adapter\LaravelDatabaseAdapter::class, // Laravel 适配器 + // 数据库设置 'database' => [ 'connection' => '', 'rules_table' => 'casbin_rule', 'rules_name' => null ], - ] + ], + // 其他扩展配置 + 'abac' => [ + // 策略模型Model设置 + 'model' => [ + 'config_type' => 'file', + 'config_file_path' => config_path() . '/plugin/casbin/webman-permission/abac-model.conf', + 'config_text' => '', + ], + // 适配器 + 'adapter' => Casbin\WebmanPermission\Adapter\LaravelDatabaseAdapter::class, + // 数据库设置 + 'database' => [ + // 数据库连接名称,不填为默认配置 + 'connection' => '', + // 策略表名(不含表前缀) + 'rules_table' => 'casbin_rule', + // 策略表完整名称 + 'rules_name' => null + ], + ], ]; \ No newline at end of file