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
Adapter API
| Method | Type | Description |
|---|---|---|
| LoadPolicy() | basic | โหลดกฎนโยบายทั้งหมดจากที่เก็บข้อมูล |
| SavePolicy() | basic | บันทึกกฎนโยบายทั้งหมดไปยังที่เก็บข้อมูล |
| AddPolicy() | optional | เพิ่มกฎนโยบายไปยังที่เก็บข้อมูล |
| RemovePolicy() | optional | ลบกฎนโยบายออกจากที่เก็บข้อมูล |
| RemoveFilteredPolicy() | optional | ลบกฎนโยบายที่ตรงกับตัวกรองออกจากที่เก็บข้อมูล |