begin
最近再琢磨 casbin,支持多种 models 的权限管理方案,类似第三方类库吧,但是文档看着很难受,基于 go 写的。
question
- 大佬们一般如何选型或者说设计权限管理的方案呢?
- 有人关注过或者说使用过 casbin 可交流一下。
code
model:模型 policy:规则
$path =realpath(__DIR__ . '/../config/casbin');
$modelPath = $path.'/model.conf';
$policyPath = $path .'/policy.csv';
$casbin = new Enforcer($modelPath,$policyPath);
$sub = 'tester';
$obj = 'backend';
$act = 'read';
if (true === $casbin->enforce($sub, $obj, $act)) {
// permit alice to read data1x
} else {
throw new \Exception('deny the request');
}
上面的例子就是简单 match:用户 tester 是否有 backend 后台读取的权限
talk
casbin: https://github.com/casbin/casbin
gayhub: https://github.com/BinZhiZhu