Skip to content

Commit b5327b0

Browse files
Copilothsluoyz
andcommitted
refactor: match Go Casbin implementation exactly
- Reverted to single pType evaluation per enforce call - Added pType reference check like Go: expString.includes(pType+"_") - Added Go's example files: multiple_policy_definitions and rbac_with_multiple_policy - Added test matching Go's TestMultiplePolicyDefinitions - Removed custom implementation that iterated all policy types Co-authored-by: hsluoyz <3787410+hsluoyz@users.noreply.github.com>
1 parent 2f12694 commit b5327b0

12 files changed

+175
-484
lines changed

IMPLEMENTATION_NOTES.md

Lines changed: 0 additions & 160 deletions
This file was deleted.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[request_definition]
2+
r = sub, obj, act
3+
r2 = sub, obj, act
4+
5+
[policy_definition]
6+
p = sub, obj, act
7+
p2= sub_rule, obj, act, eft
8+
9+
[role_definition]
10+
g = _, _
11+
12+
[policy_effect]
13+
e = some(where (p.eft == allow))
14+
15+
[matchers]
16+
#RABC
17+
m = g(r.sub, p.sub) && r.obj == p.obj && r.act == p.act
18+
#ABAC
19+
m2 = eval(p2.sub_rule) && r2.obj == p2.obj && r2.act == p2.act
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
p, data2_admin, data2, read
2+
p2, r2.sub.Age > 18 && r2.sub.Age < 60, /data1, read, allow
3+
p2, r2.sub.Age > 60 && r2.sub.Age < 100, /data1, read, deny
4+
5+
g, alice, data2_admin
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[request_definition]
2+
r = user, thing, action
3+
4+
[policy_definition]
5+
p = role, thing, action
6+
p2 = role, action
7+
8+
[policy_effect]
9+
e = some(where (p.eft == allow))
10+
11+
[matchers]
12+
m = g(r.user, p.role) && r.thing == p.thing && r.action == p.action
13+
m2 = g(r.user, p2.role) && r.action == p.action
14+
15+
[role_definition]
16+
g = _,_
17+
g2 = _,_
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
p, user, /data, GET
2+
p, admin, /data, POST
3+
4+
p2, user, view
5+
p2, admin, create
6+
7+
g, admin, user
8+
g, alice, admin
9+
g2, alice, user

examples/test_multiple_p_model.conf

Lines changed: 0 additions & 12 deletions
This file was deleted.

examples/test_multiple_p_policy.csv

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)