跳到主内容

配置权限

本页描述权限编辑页面的字段,您在其中定义组织的策略。

要打开该页面,请转到 Casdoor 管理控制台的 Permissions 页面,添加一个权限或打开一个现有权限。

Permission edit page

基本字段​

FieldDescription
OrganizationThe organization that owns the permission. An organization can have many permissions
NameUnique name of the permission in the organization. The Casbin APIs refer to the permission by it
Display nameName shown in the UI

模型和适配器​

FieldDescription
Model用于评估权限的模型,例如 ACL、RBAC 或 ABAC。您在 Models 页面上创建模型。请参阅 supported models
适配器The database table in which Casdoor stores the policy rules of the permission. If empty, the rules go to the permission_rule table. If the table doesn't exist, Casdoor creates it
注意事项

为每个模型提供其自己的适配器表。结构不同但共享同一表的模型在 Casdoor 加载策略时会产生冲突。

模型定义了权限具有哪些特性。如果 RBAC 字段(如 Sub users 或 Sub roles)在权限页面上不可用,则所选模型没有 role_definition。请编辑模型以支持角色。另请参阅 Adapters。

主体​

这些字段定义权限适用于谁。

FieldDescription
订阅用户Users that the permission applies to, for example alice and bob. 留空表示不按用户限制
包含角色Roles that the permission applies to, for example admin and editor. Casdoor adds a rule such as g, user, role for each user of the roles
包含群组Groups that the permission applies to, for example dev-team. Every member inherits the permission. * matches all groups of the organization
包含域Domains that the permission applies to, for multi-tenant models. Leave empty if your model has no domains

主体是累加的:如果用户被直接列出,或者拥有其中一个角色,或者是其中一个群组的成员,则该用户拥有此权限。角色可以包含群组,因此群组也可以通过角色授予权限。

资源和操作​

这些字段定义权限控制什么。

FieldDescription
资源类型Application, TreeNode, Custom, or API. With Application, Casdoor itself uses the permission to decide who may sign in to the applications in Resources. See Restrict who can sign in to an application
资源What you protect. With Application, select applications, or All (*) for every application. With API, select paths of the Casdoor API. With Custom, enter any strings, such as URLs (/api/users), file names (document.pdf), or identifiers (project:123). These aren't the files on the Resources page of Casdoor
动作Any strings that name what users do, such as HTTP methods (GET, POST), operations (read, write), or your own verbs (approve, publish)

Casdoor 为资源和操作的每种组合创建一个规则。

注意事项

Casdoor 在存储之前将操作转换为小写,并将每个操作应用于每个资源。若仅允许对某些资源执行某操作,请在模型中表达,或创建单独的权限。

效果​

Effect 仅在 Casdoor 使用权限来控制对其自身应用的访问时适用。当您的应用调用 Casbin API 时,该字段无效:请改为在模型中表达 allow 和 deny。

限制谁可以登录到应用​

Resource type 为 Application 的权限控制谁可以登录到其 Resources 中的应用。Casdoor 在每次登录时以及在用户的 Apps 页面上列出应用时检查这些权限。

Casdoor 仅在 Is enabled 开启且 State 为 Approved 时才考虑权限。对于主体中包含该用户的每个权限,Casdoor 会强制执行请求 (<user-id>, <application-name>, "Read"),并对该用户的每个匹配角色执行相同的请求。然后:

  1. 如果 Effect 为 Deny 的权限匹配,则拒绝登录。
  2. 否则,如果 Effect 为 Allow 的权限匹配,则允许登录。
  3. 否则,如果应用只有 Allow 权限且没有任何权限覆盖该用户,则拒绝登录。
  4. 否则,例如当没有权限针对该应用时,允许登录。

被拒绝的登录会以 Unauthorized operation 失败。

对于共享应用,Casdoor 从登录用户所属的组织读取权限,而不是从应用所属的组织读取。

built-in 组织的用户和组织的管理员(Is admin 开启的用户)始终通过此检查。这防止管理员将自己锁定在外。

过期时间​

Expire time (expireTime) 用于自动结束权限,例如授予几小时的访问权限,或满足 ISO/IEC 27001 控制项 5.18 要求的限时访问。选择日期和时间,或点击 1 hour、1 day、7 days 或 30 days 以设置从现在起的相应时长。Never 会清除该值,使权限永不过期。通过 API,expireTime 是一个 RFC 3339 时间戳,例如 2026-12-31T23:59:59+08:00。

Casdoor checks the permissions at startup and then every minute. For every enabled permission whose expire time has passed, it removes the Casbin policies of the permission and turns off Is enabled. An expired permission can therefore still apply for up to a minute.

要再次授予访问权限,请设置较晚的过期时间或清除它,然后重新开启 Is enabled。

注意事项

如果过期时间不是有效的 RFC 3339 格式,Casdoor 会忽略它,因此权限永远不会过期。请检查格式,包括时区偏移量。

示例​

以下权限使用包含 (sub, obj, act) 请求的模型:

FieldValue
Modelrbac_model
Sub rolesadmin, editor
Resources/api/users, /api/posts
Actionsread, write

拥有 admin 或 editor 角色的用户可以 read 和 write /api/users 及 /api/posts。

另请参阅​