当前位置: 首页 > 文档资料 > Casbin 中文文档 >

域内基于角色的访问控制 API

优质
小牛编辑
120浏览
2023-12-01

一个更友好的域内基于角色的访问控制的API。 这个API是Management API的子集。 RBAC用户可以使用这个API来简化代码。

参考

全局变量 e 是 Enforcer 实例。

GoNode.jsPHP.NETRust
e, err := NewEnforcer("examples/rbac_model.conf", "examples/rbac_policy.csv")
const e = await newEnforcer('examples/rbac_model.conf', 'examples/rbac_policy.csv')
$e = new Enforcer('examples/rbac_model.conf', 'examples/rbac_policy.csv');
var e = new Enforcer("path/to/model.conf", "path/to/policy.csv");
let mut e = Enforcer::new("examples/rbac_model.conf", "examples/rbac_policy.csv").await?;

GetUsersForRoleInDomain()

GetUsersForRoleInDomain 获取具有域内角色的用户。

例如:

Go
res := e.GetUsersForRoleInDomain("alice", "domain1")

GetRolesForUserInDomain()

GetRolesForUserInDomain 获取域内用户的角色

例如:

Go
res := e.GetRolesForUserInDomain("admin", "domain1")

GetPermissionsForUserInDomain()

GetPermissionsForUserInDomain 获取域内用户或角色的权限。

例如:

Go
res := e.GetPermissionsForUserInDomain("alice", "domain1")

AddRoleForUserInDomain()

AddRoleForUserInDomain 在域内为用户添加角色 如果用户已经拥有该角色,则返回false。

例如:

Go
ok, err := e.AddRoleForUserInDomain("alice", "admin", "domain1")

DeleteRoleForUserInDomain()

DeleteRoleForUserInDomain 在域内删除用户的角色 如果用户没有该角色,则返回false。

例如:

Go
ok, err := e.DeleteRoleForUserInDomain("alice", "admin", "domain1")

DeleteRolesForUserInDomain()

DeleteRolesForUserInDomain 删除域内用户的所有角色 如果用户没有任何角色,则返回false。

For example:

Go
ok, err := e.DeleteRolesForUserInDomain("alice", "domain1")

GetAllUsersByDomain()

GetAllUsersByDomain将获得所有与该域相关联的用户。 如果模型中没有定义域名,将返回空字符串。

例如:

Go
res := e.GetAllUsersByDomain("domain1")

DeleteAllUsersByDomain()

DeleteAllUsersByDomain 将删除与该域相关的所有用户 如果模型中没有定义域名,则返回 false。

例如:

Go
ok, err := e.DeleteAllUsersByDomain("domain1")

DeleteDomains()

DeleteDomains 将删除所有相关的用户和角色。 如果没有提供参数,它会删除所有域。

例如:

Go
ok, err := e.DeleteDomains("domain1", "domain2")
note

如果您正在处理类似于 name::domain的域,这可能会导致意外的行为。 在 Casbin里, :: 是一个倒置的关键词, 就像编程语言中的关键字 for, if 一样,我们不应该在一个域中放置 ::

← RBAC APIRoleManager API →