casbin / jcasbin

An authorization library that supports access control models like ACL, RBAC, ABAC in Java
https://casbin.org
Apache License 2.0
2.38k stars 461 forks source link

Why use the first one when there are multiple [policy_effects] #284

Closed 2140345 closed 2 years ago

2140345 commented 2 years ago

Model:

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

[policy_definition]
p = sub, obj, act
p2 = sub_rule, obj, act, eft

[role_definition]
g = _, _

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

[matchers]
#RABC
m = g(r.sub, p.sub) && r.obj == p.obj && r.act == p.act
#ABAC
m2 = eval(p2.sub_rule) && r2.obj == p2.obj && r2.act == p2.act

The following is the java test code:

@Test
    public void testMultiplePolicyDefinitions() {
        Enforcer e = new Enforcer("examples/multiple_policy_definitions_model.conf", "examples/multiple_policy_definitions_policy.csv");
        EnforceContext enforceContext = new EnforceContext("2");
        enforceContext.seteType("e");
        testEnforce(e, "alice", "data2", "read", true);
        testEnforceWithContext(e, enforceContext, new AbacAPIUnitTest.TestEvalRule("alice", 70), "/data1", "read", false);
        testEnforceWithContext(e, enforceContext, new AbacAPIUnitTest.TestEvalRule("alice", 30), "/data1", "read", true);
    }

I want to use enforceContext.seteType("e2"), but I can only use e. Because the push in the defaultstreameffector class threw an unsupported operation exception seek help!

casbin-bot commented 2 years ago

@tangyang9464 @closetool @sagilio

casbin-bot commented 2 years ago

@tangyang9464 @seriouszyx @elfisworking @fangzhengjin

hsluoyz commented 2 years ago

@imp2002

/cc @tangyang9464

imp2002 commented 2 years ago

@2140345 I'm ok for this. Could you provide your INFO log?

image image

2140345 commented 2 years ago

@imp2002 the issue has gone after upgrading jCasbin to v1.24.2 , resolved

2140345 commented 2 years ago

The problem has been solved. Thank you!