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

How to use function pass multiple params in policy? #843

Closed
tonitrnel opened this issue Jul 19, 2021 · 7 comments · Fixed by casbin/casbin-website#257
Closed

How to use function pass multiple params in policy? #843

tonitrnel opened this issue Jul 19, 2021 · 7 comments · Fixed by casbin/casbin-website#257
Assignees
Labels

Comments

@tonitrnel
Copy link

Your model:

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

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

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

[matchers]
m = eval(p.sub_policy) && r.dom == p.dom && r.obj == p.obj && r.act == p.act

Your policy:

p, roleMatch('Author', r.sub.Roles), d01, /data1, read

Your request(s):

{ Rules: ["Author"] }, d01, /data1, read

I cannot use the roleMatch('Author', r.sub.Roles), It says Unclosed ( at character 75 after run the test, I guess it conflict with policy separator, How should i solve this problem?

@hsluoyz
Copy link
Member

hsluoyz commented Jul 19, 2021

@closetool @tangyang9464

@tonitrnel
Copy link
Author

I use space instead of comma, it works.

@tangyang9464
Copy link
Member

tangyang9464 commented Jul 20, 2021

@piecego
Why don't you use it like this m = roleMatch('Author', r.sub.Roles)

@tonitrnel
Copy link
Author

@tangyang9464 Because it is dynamic.

@hsluoyz
Copy link
Member

hsluoyz commented Jul 20, 2021

I use space instead of comma, it works.

@piecego what do you mean by this?

@tonitrnel
Copy link
Author

I use space instead of comma, it works.

@piecego what do you mean by this?

p, roleMatch('Author' r.sub.Roles), d01, /data1, read

Use space symbol in after 'Author'

@kilosonc
Copy link
Contributor

@piecego In fact, we don't know why it works, cause it shouldn't be.
Casbin parses csv file through https://pkg.go.dev/encoding/csv, you can find escape grammer here.
So the recommanded policy should be like this

p, "roleMatch('Author', r.sub.Roles)", d01, /data1, read

We will add this into docs too

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