Skip to content

Commit

Permalink
Merge pull request #59 from divy9881/get_started
Browse files Browse the repository at this point in the history
feat: add Get-Started section.
  • Loading branch information
hsluoyz authored Jul 14, 2020
2 parents d1840a0 + efeeb34 commit 30941e0
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ Casbin-CPP

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

## Build Availability on Platforms:
Operating Systems | Availability status
----------------- | -------------------
Windows (VS C++) | :heavy_check_mark: Available
Linux and MacOS | :wrench: Under-Development


![casbin Logo](casbin-logo.png)

## All the languages supported by Casbin:
Expand Down Expand Up @@ -100,6 +107,36 @@ You can also use the online editor (https://casbin.org/editor/) to write your Ca

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

## Get started

1. New a Casbin enforcer with a model file and a policy file:

```c++
Enforcer* e = Enforcer :: NewEnforcer("<path to model.conf>", "<path to policy.csv>");
```

Note: you can also initialize an enforcer with policy in DB instead of file, see [Policy-persistence](#policy-persistence) section for details.

2. Add an enforcement hook into your code right before the access happens:

```c++
string sub = "alice"; // the user that wants to access a resource.
string obj = "data1"; // the resource that is going to be accessed.
string act = "read"; // the operation that the user performs on the resource.

if(e->Enforce({ sub, obj, act })) {
// permit alice to read data1
} else {
// deny the request, show an error
}
```

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:

```c++
vector<string> roles( e->GetImplicitRolesForUser(sub) );
```

## Policy management

Casbin provides two sets of APIs to manage permissions:
Expand Down

0 comments on commit 30941e0

Please sign in to comment.