# Request definition
[request_definition]
r = sub, obj, act
# Policy definition
[policy_definition]
p = sub, obj, act
# Policy effect
[policy_effect]
e = some(where (p.eft == allow))
# Matchers
[matchers]
m = r.sub == p.sub && r.obj == p.obj && r.act == p.act
p, alice, data1, read
p, bob, data2, write
# Matchers
[matchers]
m = r.sub == p.sub && r.obj == p.obj \
&& r.act == p.act
# Matchers
[matchers]
m = r.obj == p.obj && r.act == p.act || r.obj in ('data2', 'data3')
go get github.com/casbin/casbin/v2
e, _ := casbin.NewEnforcer("path/to/model.conf", "path/to/policy.csv")
sub := "alice" // the user that wants to access a resource.
obj := "data1" // the resource that is going to be accessed.
act := "read" // the operation that the user performs on the resource.
if res, _ := e.Enforce(sub, obj, act); res {
// permit alice to read data1
} else {
// deny the request, show an error
}
roles, _ := e.GetImplicitRolesForUser(sub)
Overview
Name With Owner | casbin/casbin |
Primary Language | Go |
Program language | Go (Language Count: 2) |
Platform | Linux, Mac, Windows |
License: | Apache License 2.0 |
Release Count | 252 |
Last Release Name | v2.77.2 (Posted on ) |
First Release Name | v0.0.1 (Posted on ) |
Created At | 2017-04-08 07:51:23 |
Pushed At | 2023-10-08 10:25:31 |
Last Commit At | 2023-09-25 19:23:35 |
Stargazers Count | 15.8k |
Watchers Count | 232 |
Fork Count | 1.6k |
Commits Count | 1.1k |
Has Issues Enabled |
Issues Count | 760 |
Issue Open Count | 28 |
Pull Requests Count | 340 |
Pull Requests Open Count | 4 |
Pull Requests Close Count | 134 |
Has Wiki Enabled |
Is Archived |
Is Fork |
Is Locked |
Is Mirror |
Is Private |