Casbin

Casbin

  • 文档
  • API
  • 编辑器
  • IDE 插件
  • Single Sign-On (SSO)
  • 论坛
  • 帮助
  • 博客
  • Pricing
  • Contact Sales
  • Languages icon中文
    • English
    • 한국어
    • Русский
    • Français
    • Deutsch
    • 日本語
    • 参与翻译
  • GitHub

›API

基础知识

  • 概述
  • 开始使用
  • 工作原理
  • 教程

Model

  • 支持的Models
  • Model语法
  • 效果器
  • 函数
  • 基于角色的访问控制
  • RBAC with Pattern
  • 域内RBAC
  • Casbin RBAC v.s. RBAC96
  • ABAC
  • 优先级模型
  • 超级管理员

存储

  • Model存储
  • Policy存储
  • 政策子集加载

扩充功能

  • Enforcers
  • 适配器
  • 观察者
  • 调度器
  • 角色管理器
  • 中间件
  • Graphql 中间件
  • 云端原生中间值

API

  • API 概述
  • 管理 API
  • RBAC API
  • 域内基于角色的访问控制 API
  • RoleManager API
  • 数据权限

高级用法

  • 多线程
  • 基准测试
  • 性能优化
  • Kubernetes的授权
  • 通过特使核准服务网格。

管理

  • 管理员门户
  • Casbin 服务
  • 日志 & 错误处理
  • 前端使用

编辑器

  • 在线编辑器
  • IDE 插件

更多

  • 本项目使用者
  • 贡献中
  • 隐私政策
  • 服务条款
Translate

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

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

参考

全局变量 e 是 Enforcer 实例。

Go
Node.js
PHP
Python
.NET
Rust
Java
e, err := NewEnforcer("examples/rbac_with_domains_model.conf", "examples/rbac_with_domains_policy.csv")
const e = await newEnforcer('examples/rbac_with_domains_model.conf', 'examples/rbac_with_domains_policy.csv')
$e = new Enforcer('examples/rbac_with_domains_model.conf', 'examples/rbac_with_domains_policy.csv');
e = casbin.Enforcer("examples/rbac_with_domains_model.conf", "examples/rbac_with_domains_policy.csv")
var e = new Enforcer("examples/rbac_with_domains_model.conf", "examples/rbac_with_domains_policy.csv");
let mut e = Enforcer::new("examples/rbac_with_domains_model.conf", "examples/rbac_with_domains_policy.csv").await?;
Enforcer e = new Enforcer("examples/rbac_with_domains_model.conf", "examples/rbac_with_domains_policy.csv");

GetUsersForRoleInDomain()

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

例如:

Go
Node.js
Python
res := e.GetUsersForRoleInDomain("admin", "domain1")
const res = e.getUsersForRoleInDomain("admin", "domain1")
res = e.get_users_for_role_in_domain("admin", "domain1")

GetRolesForUserInDomain()

GetRolesForUserInDomain 获取域内用户的角色

例如:

Go
Node.js
Python
Java
res := e.GetRolesForUserInDomain("admin", "domain1")
const res = e.getRolesForUserInDomain("alice", "domain1")
res = e.get_roles_for_user_in_domain("alice", "domain1")
List<String> res = e.getRolesForUserInDomain("admin", "domain1");

GetPermissionsForUserInDomain()

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

例如:

Go
Java
res := e.GetPermissionsForUserInDomain("alice", "domain1")
List<List<String>> res = e.getPermissionsForUserInDomain("alice", "domain1");

AddRoleForUserInDomain()

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

例如:

Go
Python
Java
ok, err := e.AddRoleForUserInDomain("alice", "admin", "domain1")
ok = e.add_role_for_user_in_domain("alice", "admin", "domain1")
boolean ok = e.addRoleForUserInDomain("alice", "admin", "domain1");

DeleteRoleForUserInDomain()

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

例如:

Go
Java
ok, err := e.DeleteRoleForUserInDomain("alice", "admin", "domain1")
boolean ok = 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")

GetAllDomains()

GetAllDomains would get all domains.

For example:

Go
res, _ := e.GetAllDomains()
note

If you are handling a domain like name::domain, it may lead to unexpected behavior. In Casbin, :: is a reversed keyword, just like for, if in a programming language, we should never put :: in a domain.

← RBAC APIRoleManager API →
  • 参考
    • GetUsersForRoleInDomain()
    • GetRolesForUserInDomain()
    • GetPermissionsForUserInDomain()
    • AddRoleForUserInDomain()
    • DeleteRoleForUserInDomain()
    • DeleteRolesForUserInDomain()
    • GetAllUsersByDomain()
    • DeleteAllUsersByDomain()
    • DeleteDomains()
    • GetAllDomains()
Casbin
Docs
Getting StartedManagement APIRBAC APIMiddlewares
Community
Who's using Casbin?Stack Overflow
Casbin          jCasbin
Node-Casbin   PHP-CasbinPyCasbin          Casbin.NETCasbin-CPP        Casbin-RS
Follow @casbinHQ
Copyright © 2022 Casbin Organization