Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Discrepancy in response from editor and golang sdk #885

Closed
aravindakumarbootlabs opened this issue Sep 4, 2021 · 2 comments · Fixed by casbin/casbin-website#277
Closed
Assignees
Labels

Comments

@aravindakumarbootlabs
Copy link

aravindakumarbootlabs commented Sep 4, 2021

Describe the bug
The policy and evaluation done on editor is working as intended, but with the same policy and evaluation in golang is not working properly

To Reproduce
Steps to reproduce the behavior:

  1. Tried running the following go code
package main

import (
	"fmt"
	"github.com/casbin/casbin/v2"
	defaultrolemanager "github.com/casbin/casbin/v2/rbac/default-role-manager"
	"github.com/casbin/casbin/v2/util"
)

func main() {
	e, err := casbin.NewEnforcer("rbac/model.conf", "rbac/policies.csv")
	if err != nil {
		panic(err)
	}

	r := e.GetRoleManager()
	r.(*defaultrolemanager.RoleManager).AddDomainMatchingFunc("KeyMatch4", util.KeyMatch4)

	t, _:= e.Enforce("user1", "organizations/org1", "read")
	fmt.Println(t)
}

rbac/model.conf:

[request_definition]
r = sub, obj, act

[policy_definition]
p = sub, act

[role_definition]
g = _, _, _

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

[matchers]
m = g(r.sub, p.sub, r.obj) && r.act == p.act

rbac/policies.csv

p, org_owner, write
p, org_reader, read

g, org_owner, org_reader, organizations/{org}

g, user1, org_owner, organizations/org1
g, user2, org_owner, organizations/org2

Expected behavior
Should return true for request: user1, organizations/org1, read
But returns false

The same setup is working on the online editor, I have added screenshots of both
Using version: v2.36.2

Screenshots
editor setup:
image

go setup:
image

Disclaimer:
I think I am not adding the domainmatchingfunction properly, can you please check

@casbin-bot
Copy link
Member

@closetool @tangyang9464

@tangyang9464
Copy link
Member

@aravindakumarbootlabs you should add e.BuildRoleLinks() to build again after add match func

e.AddNamedDomainMatchingFunc("g","",util.KeyMatch4)
e.BuildRoleLinks()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants