casbin icon indicating copy to clipboard operation
casbin copied to clipboard

[Question] - Is it possible to enforce with 4 values that has policy with 5 or more fields?

Open sujit-baniya opened this issue 2 years ago • 2 comments
trafficstars

Want to prioritize this issue? Try:

issuehunt-to-marktext


What's your scenario? What do you want to achieve? I've 5 fields in policy (1 field extra with possibility to return this field if policy matches) and I am trying to match first 4 fields and upon enforced, it would return that extra field.

Your model:

[request_definition]
r = sub, dom, obj, act

[policy_definition]
p = sub, dom, obj, act

[role_definition]
g = _, _, _
g2 = _, _

[policy_effect]
e = some(where (p.eft == allow))

[matchers]
???

Your policy:

p, super_admin, *, *, GET, "field1,field2,field3"
p, admin, organizationA:*, *, POST, "field1,field2,field3"

g, bob, admin, organizationA:*
g, alice, super_admin, *

Is there anyway I could use 4 fields in request to match first 4 fields in policy and return the 5th field. I tried with EnforceEx() but it's failing with error panic: invalid policy rule size: expected 4, got 5, rule: [super_admin * * GET field1,field2,field3]

fmt.Println(enforcer.EnforceEx("bob", "organizationA:instituteB", "/blog", "POST"))
fmt.Println(enforcer.EnforceEx("bob", "organizationB:instituteA", "/blog", "POST"))
fmt.Println(enforcer.EnforceEx("alice", "organizationA:instituteA", "/blog", "GET"))

sujit-baniya avatar Apr 18 '23 12:04 sujit-baniya

@tangyang9464 @JalinWang

casbin-bot avatar Apr 18 '23 12:04 casbin-bot

@PokIsemaine

hsluoyz avatar Apr 18 '23 15:04 hsluoyz

@sujit-baniya you must define 5th element in model like:

[policy_definition]
p = sub, dom, obj, act, element

The error will gone

hsluoyz avatar Jun 09 '23 01:06 hsluoyz