You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+37Lines changed: 37 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,6 +8,13 @@ Casbin-CPP
8
8
9
9
**News**: Are you still worried about how to write the correct Casbin policy? ``Casbin online editor`` is coming to help! Try it at: http://casbin.org/editor/
10
10
11
+
## Build Availability on Platforms:
12
+
Operating Systems | Availability status
13
+
----------------- | -------------------
14
+
Windows (VS C++) | :heavy_check_mark: Available
15
+
Linux and MacOS | :wrench: Under-Development
16
+
17
+
11
18

12
19
13
20
## All the languages supported by Casbin:
@@ -100,6 +107,36 @@ You can also use the online editor (https://casbin.org/editor/) to write your Ca
100
107
101
108
https://casbin.org/docs/en/tutorials
102
109
110
+
## Get started
111
+
112
+
1. New a Casbin enforcer with a model file and a policy file:
113
+
114
+
```c++
115
+
Enforcer* e = Enforcer :: NewEnforcer("<path to model.conf>", "<path to policy.csv>");
116
+
```
117
+
118
+
Note: you can also initialize an enforcer with policy in DB instead of file, see [Policy-persistence](#policy-persistence) section for details.
119
+
120
+
2. Add an enforcement hook into your code right before the access happens:
121
+
122
+
```c++
123
+
string sub = "alice"; // the user that wants to access a resource.
124
+
string obj = "data1"; // the resource that is going to be accessed.
125
+
string act = "read"; // the operation that the user performs on the resource.
126
+
127
+
if(e->Enforce({ sub, obj, act })) {
128
+
// permit alice to read data1
129
+
} else {
130
+
// deny the request, show an error
131
+
}
132
+
```
133
+
134
+
3. Besides the static policy file, Casbin also provides API for permission management at run-time. For example, You can get all the roles assigned to a user as below:
0 commit comments