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

Policies with explicit integer priorities are not sorted correctly #326

Closed
nschwane opened this issue Oct 18, 2023 · 1 comment · Fixed by #327
Closed

Policies with explicit integer priorities are not sorted correctly #326

nschwane opened this issue Oct 18, 2023 · 1 comment · Fixed by #327
Assignees
Labels
bug Something isn't working

Comments

@nschwane
Copy link
Contributor

When using policies with explicit priorities that are integers, the policies are sorted as strings instead of as numbers. This will put a policy with priority 10 in front of a policy with priority 2.

Example

model.conf

[request_definition]
r = sub, obj, act

[policy_definition]
p = priority, sub, obj, act, eft

[role_definition]
g = _, _

[policy_effect]
e = priority(p.eft) || deny

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

policy.csv

p, 10, data1_deny_group, data1, read, deny
p, 10, data1_deny_group, data1, write, deny
p, 10, data2_allow_group, data2, read, allow
p, 10, data2_allow_group, data2, write, allow


p, 1, alice, data1, write, allow
p, 1, alice, data1, read, allow
p, 2, bob, data2, read, deny

g, bob, data2_allow_group
g, alice, data1_deny_group

Example Python

>>> import pprint
>>> from casbin import Enforcer
>>> enforcer = Enforcer('model.conf', 'policy.csv')
>>> enforcer.enforce_ex('bob', 'data2', 'read')
(True, ['10', 'data2_allow_group', 'data2', 'read', 'allow'])
>>> pprint.pprint(enforcer.model['p']['p'].policy)
[['1', 'alice', 'data1', 'write', 'allow'],
 ['1', 'alice', 'data1', 'read', 'allow'],
 ['10', 'data1_deny_group', 'data1', 'read', 'deny'],
 ['10', 'data1_deny_group', 'data1', 'write', 'deny'],
 ['10', 'data2_allow_group', 'data2', 'read', 'allow'],
 ['10', 'data2_allow_group', 'data2', 'write', 'allow'],
 ['2', 'bob', 'data2', 'read', 'deny']]
>>> 

The result of calling enforce() should be False.

@casbin-bot
Copy link
Member

@techoner @Nekotoxin

@casbin-bot casbin-bot added the question Further information is requested label Oct 18, 2023
@hsluoyz hsluoyz added bug Something isn't working and removed question Further information is requested labels Oct 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Development

Successfully merging a pull request may close this issue.

3 participants