Policy Storage
Casbin implements policy storage through adapters.
从.CSV文件加载策略
Loading from a CSV file is the standard approach. This method is straightforward for beginners and convenient when seeking help from the Casbin team.
Here's an example CSV file examples/rbac_policy.csv:
p, alice, data1, read
p, bob, data2, write
p, data2_admin, data2, read
p, data2_admin, data2, write
g, alice, data2_admin
备注
When CSV fields contain commas, wrap them in double quotes:
p, alice, "data1,data2", read --correct
p, alice, data1,data2, read --incorrect (the whole phrase "data1,data2" should be wrapped in double quotes)
When fields contain both commas and double quotes, wrap the field in double quotes and escape embedded quotes by doubling them:
p, alice, data, "r.act in (""get"", ""post"")" --correct
p, alice, data, "r.act in ("get", "post")" --incorrect (you should use "" to escape "")
相关问题:casbin#886
适配器API
| 方法 | 类型 | 描述 |
|---|---|---|
| LoadPolicy() | 基础 | 从存储中加载所有策略规则 |
| SavePolicy() | 基础 | 将所有策略规则保存到存储中 |
| AddPolicy() | 可选 | 向存储中添加策略规则 |
| RemovePolicy() | 可选 | 从存储中移除策略规则 |
| RemoveFilteredPolicy() | 可选 | 从存储中移除与过滤器匹配的策略规则 |