enforcer.addGroupingPolicy
I am trying to do a basic authorization by adding a policy and a grouping policy. However the api to addGroupingPolicy does not seem to work for me. Can someone help if there is an issue or am I doing something wrong.
casbin version : 5.7.1
// For Node.js:
const { newEnforcer } = require('casbin');
const sub = 'alice';
const obj = 'data';
const act = 'read';
async function run() {
const enforcer = await newEnforcer('./examples/basic_model.conf');
const p = ['group1', 'data', 'read']
var added = await enforcer.addPolicy(...p)
console.log('Is Policy added = ', added);
const g = ['alice', 'group1']
var gpAdded = await enforcer.addGroupingPolicy(...g)
// const gpAdded = await enforcer.addNamedGroupingPolicy('g', 'alice', 'group1');
console.log('Is GroupingPolicy added = ', gpAdded);
const allPolicies = await enforcer.getPolicy()
console.log('All Policies : ', allPolicies);
// authorize alice
var res = await enforcer.enforce(sub, obj, act);
if (res) {
// permit alice to read data1
console.log('Access granted');
} else {
console.log('Access denied');
// deny the request, show an error
}
}
run();
@Murthybhat Are you using jcasbin?
No. I will move it to Node-Casbin
@Zxilly
working on this
@Murthybhat You should not use ./examples/basic_model.conf. Since it didn't include a so-called g section, which will make RBAC works.
You should use rbac_model.conf , which include
[role_definition]
g = _, _
Closed as resolved.