Skip to content

Commit 30941e0

Browse files
authored
Merge pull request #59 from divy9881/get_started
feat: add Get-Started section.
2 parents d1840a0 + efeeb34 commit 30941e0

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ Casbin-CPP
88

99
**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/
1010

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+
1118
![casbin Logo](casbin-logo.png)
1219

1320
## 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
100107

101108
https://casbin.org/docs/en/tutorials
102109

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:
135+
136+
```c++
137+
vector<string> roles( e->GetImplicitRolesForUser(sub) );
138+
```
139+
103140
## Policy management
104141

105142
Casbin provides two sets of APIs to manage permissions:

0 commit comments

Comments
 (0)