Git Product home page Git Product logo

Comments (4)

leeqvip avatar leeqvip commented on May 22, 2024

没有问题的,Casbin中用户和角色都按 subject 算,src/RbacApi.php#L137

from think-authz.

MrXBear avatar MrXBear commented on May 22, 2024

之所以有这个问题,是因为昨天 试了以下代码,与预期结果不符

// 对eve用户添加 articles read 权限
Enforcer::addPermissionForUser('eve', 'articles', 'read');

// 对 writer 角色添加 articles edit 权限
Enforcer::addPermissionForUser('writer', 'articles','edit');

// 对eve用户添加 writer 角色
Enforcer::addRoleForUser('eve', 'writer');

// 至此 eve 应有 articles read 权限,以及 writer 所包含的 articles edit 权限
Enforcer::hasPermissionForUser('eve', 'articles', 'edit');    // 结果为 false

仔细看完readme.md后,发现实际上有两个方法:

// 决定某个用户是否拥有某个权限
Enforcer::hasPermissionForUser('eve', 'articles', 'edit');    // 结果为 false

// 检查一个用户是否拥有某个权限
Enforcer::enforce('eve', 'articles', 'edit');     // 结果为 true

按结果 来猜测:
hasPermissionForUser( ) 只检查“直接”赋予给 用户的权限;
enforce( ) 检查 赋予用户的权限 以及 用户所拥有的角色的所包含的权限。

仅从现有的中文注释来看,比较难区分二者的区别。

另外,想知道 这里的 第2参数 articles 与 第3参数 read 是 指代 一级权限 与 二级权限 吗?
谢谢

from think-authz.

leeqvip avatar leeqvip commented on May 22, 2024

@MrXBear hasPermissionForUser() 的确是检查直接权限,enforce() 则是根据 your-model.conf配置里的 matchers 表达式进行检查,可以使用 getImplicitPermissionsForUser() 方法 获取 所有权限(包括继承来的)

参数的顺序则是根据 your-model.conf 里的request_definition 里的配置一一对应,比如 eve articles edit 分别对应 sub obj act,可以配置更多的参数。

from think-authz.

MrXBear avatar MrXBear commented on May 22, 2024

明白了
谢谢🙏

from think-authz.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.