You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to use domains to load only a subset of policies per these instructions. I have copied the example model.conf and policy.csv from the online editor's "RBAC with domains/tenants" example. I have a main.py to test things.
model.conf
[request_definition]
r = sub, dom, obj, act
[policy_definition]
p = sub, dom, obj, act
[role_definition]
g = _, _, _
[policy_effect]
e = some(where (p.eft == allow))
[matchers]
m = g(r.sub, p.sub, r.dom) && r.dom == p.dom && r.obj == p.obj && r.act == p.act
importcasbinif__name__=="__main__":
adapter=casbin.persist.adapters.filtered_file_adapter.FilteredFileAdapter(
"f_policy.csv"
)
adapter.filter.P= ["", "domain1", "", ""]
adapter.filter.G= ["", "", "domain1"]
model=casbin.Enforcer.new_model("model.conf")
filtered_enforcer=casbin.Enforcer(model, adapter)
filtered_enforcer.load_filtered_policy(filtered_enforcer.adapter.filter)
print(f"filtered_enforcer.get_policy(): {filtered_enforcer.get_policy()}") # prints lines 1 and 2 from `policy.csv` as a list - this is expectedunfiltered_enforcer=casbin.Enforcer("model.conf", "policy.csv")
print(f"unfiltered_enforcer.get_policy(): {unfiltered_enforcer.get_policy()}") # prints lines 1-4 of `policy.csv` as a list - this is expectedrequest_vals= ["alice", "domain1", "data1", "read"]
print(f"request to filtered_enforcer: {filtered_enforcer.enforce(*request_vals)} (expected True)") # prints False - this is unexpectedprint(f"request to unfiltered_enforcer: {unfiltered_enforcer.enforce(*request_vals)} (expected True)") # prints True - this is expected
Problem
As you can see from the comments above, I am not getting the expected result when calling enforce() on the filtered_enforcer. I am not sure where I have gone wrong. I would guess that I have not translated the given Go example to Python properly but I'm not sure. When I give the same request values in the online editor, I get True (expected). I would guess this is because the enforcer instance is not being filtered.
Please let me know if you can give me any insight.
The text was updated successfully, but these errors were encountered:
I am trying to use domains to load only a subset of policies per these instructions. I have copied the example
model.conf
andpolicy.csv
from the online editor's "RBAC with domains/tenants" example. I have amain.py
to test things.model.conf
policy.csv
main.py
Problem
As you can see from the comments above, I am not getting the expected result when calling
enforce()
on thefiltered_enforcer
. I am not sure where I have gone wrong. I would guess that I have not translated the given Go example to Python properly but I'm not sure. When I give the same request values in the online editor, I get True (expected). I would guess this is because the enforcer instance is not being filtered.Please let me know if you can give me any insight.
The text was updated successfully, but these errors were encountered: