# 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 Ownercasbin/casbin
Primary LanguageGo
Program languageGo (Language Count: 2)
PlatformLinux, Mac, Windows
License:Apache License 2.0
Release Count252
Last Release Namev2.77.2 (Posted on )
First Release Namev0.0.1 (Posted on )
Created At2017-04-08 07:51:23
Pushed At2023-10-08 10:25:31
Last Commit At2023-09-25 19:23:35
Stargazers Count15.8k
Watchers Count232
Fork Count1.6k
Commits Count1.1k
Has Issues Enabled
Issues Count760
Issue Open Count28
Pull Requests Count340
Pull Requests Open Count4
Pull Requests Close Count134
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private