-
-
Notifications
You must be signed in to change notification settings - Fork 218
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
Multiple policies config? #311
Comments
@Zxilly @Gabriel-403 @closetool @tangyang9464 |
It seems that node-casbin does not support this feature now. |
@yamilfrich your |
I think so,and this seems that I wrote this part |
Not sure, I couldn't make it work anyway, so I couldn't validate if I need to reference to r2, p2, etc.
So, how would you solve this? Different configs + Different Enforcers? If so, can they still share the same adapter + db_table? |
@yamilfrich |
Ok thank you 😄 , but I have node, so I need to find a way to make this work with node. Should it be with multiple configs and multiple enforcers? Can they share the same db_table? |
node-casbin is implementing this feature. It should be consistent with go-casbin |
@Zxilly @Gabriel-403 plz implement it |
ok! |
This function has been added and can be used later |
Thank you, how can we implement it? Is there any code example? 🙏🏻 I'll look in the changes and the code and see if I can manage my way. |
@yamilfrich Full discussion can be found at casbin/casbin.js#172 casbin/casbin.js#176. If that PR got merged, we will apply it to node-casbin immediately. |
any ETA on this? We have a need for this soon. |
@rashid301 An early bird version is available at |
hey, can I work on this? it is in the docs but not present. |
how's the progress? |
https://github.com/Gabriel-403/node-casbin/blob/master/src/coreEnforcer.ts#L378 I find you fixed it, but why not merged it to master branch? |
Can we merge this code to origin? @Gabriel-403 @Shivansh-yadav13 |
I'm not sure of it's working import { newEnforcer, newModel, MemoryAdapter, EnforceContext } from 'casbin';
const ec = new EnforceContext('r2', 'p2', 'e', 'm2');
const model = newModel(`
[request_definition]
r = sub, obj
r2 = sub, obj, act
[policy_definition]
p = sub, obj
p2 = sub, obj, act
[policy_effect]
e = some(where (p.eft == allow))
[matchers]
m = r.sub == p.sub && r.obj == p.obj
m2 = r.sub == p.sub && r.obj == p.obj && r.act == p.act
`);
const adapter = new MemoryAdapter(`
p2, alice, data1, read
p2, bob, data2, write
`);
const enforcer = await newEnforcer(model, adapter);
const res = await enforcer.enforce(ec, 'alice', 'data2', 'read');
console.log(res); |
@Shivansh-yadav13 Could you cherry-pick the cc58c57 and 33c784c to your branch, then make a PR? |
This should be returned
|
@nodece sorry it should be |
Hi, I'm new with Casbin and I'm trying to configure it with multiple policies like:
Feature policy (for each subscription plan, it will contain or not certain features):
For example, for the subscription plan "professional" it will have the feature "insights"
My policy config for this would be probably just:
p = sub, obj
Roles policy (basic ACL, like: admin, users, write):
My policy config would be:
p2 = sub, obj, act
I read on https://casbin.org/docs/en/syntax-for-models#policy-definition that it's actually possible to define multiple policies and you have some examples below, but I can't find the way to make it work on node-casbin.
When adding the policy in the DB (I'm using
casbin-sequelize-adapter
) it allows you to use "named" policies by using:e.addNamedPolicies
.But when you want to
enforce
and choose which namedPolicy you want to use, I can't find how to do so.This is the config I'm trying (I'm repeating all just in case based on the docs):
Hope this is clear, thanks in advance.
The text was updated successfully, but these errors were encountered: