I had the same question, I also need to know what the approach would be ? Probably adding some index to improve read performance since there are more reads then writes. Probably add some cache layer to query that instead. These are some ideas but not sure how that might work in production intensive applications.
I have a question, I have setup casbin with prisma adapter and watcher. When casbin makes an enforce policy call, does it have all the policies in memory or it queries on db or is a hybrid model ?
Already solved, matcher should be in one line
I have another issue
model.conf
[request_definition]
r = sub, act, obj, type, dom
[policy_definition]
p = sub, act, obj, type, dom, eft
[role_definition]
g = _, _, _
[policy_effect]
e = some(where (p.eft == allow)) && !some(where (p.eft == deny))
[matchers]
m = (g(r.sub, p.sub, r.dom) || p.sub == "*") &&
(r.dom == p.dom || p.dom == "*") &&
(g(r.obj, p.obj, r.dom) || r.obj == p.obj) &&
r.act == p.act &&
(r.type == p.type || p.type == "*")
when I try to enforce a policy I get this error
Error: Expected expression after && at character 43
at throwError (/Users/kejvidoko/dev/goteacher/casbin-demo/node_modules/jsep/build/jsep.js:38:16)
at gobbleBinaryExpression (/Users/kejvidoko/dev/goteacher/casbin-demo/node_modules/jsep/build/jsep.js:217:7)
at gobbleExpression (/Users/kejvidoko/dev/goteacher/casbin-demo/node_modules/jsep/build/jsep.js:142:17)
at Object.jsep [as default] (/Users/kejvidoko/dev/goteacher/casbin-demo/node_modules/jsep/build/jsep.js:563:17)
at Object.exports.compileAsync (/Users/kejvidoko/dev/goteacher/casbin-demo/node_modules/expression-eval/index.ts:262:31)
at Enforcer.getExpression (/Users/kejvidoko/dev/goteacher/casbin-demo/node_modules/casbin/lib/cjs/coreEnforcer.js:59:59)
at Enforcer.privateEnforce (/Users/kejvidoko/dev/goteacher/casbin-demo/node_modules/casbin/lib/cjs/coreEnforcer.js:416:43)
at privateEnforce.next (<anonymous>)
at Object.generatorRunAsync (/Users/kejvidoko/dev/goteacher/casbin-demo/node_modules/casbin/lib/cjs/util/util.js:157:36)
at Enforcer.enforce (/Users/kejvidoko/dev/goteacher/casbin-demo/node_modules/casbin/lib/cjs/coreEnforcer.js:562:23) {
index: 43,
description: 'Expected expression after &&'
I am using casbin prisma adapter, I noticed that when I call save policy it recreates all the raws, if you can see here from the first photo to the second the index of primary column has changed, looks like it has auto created all the policies and add the a news one. ( there were 49 policies on the first phot, there are 50 on the second) .
Setup is simple:
@Global()
@Module({
exports: [RbacService, "ENFORCER_SERVICE"],
providers: [
DefaultRolePermissionSeed,
RbacService,
{
provide: "ENFORCER_SERVICE",
useFactory: async () => {
const adapter: PrismaAdapter = await PrismaAdapter.newAdapter();
const enforcer: Enforcer = await newEnforcer(join(__dirname, "rbac.model.conf"), adapter);
enforcer.enableLog(true);
return enforcer;
},
},
],
})
export class RbacModule {}
simple seeding script:
const initialPolicies = DefaultMAPolicies.concat(
DefaultOOPolicies,
DefaultOAPolicies,
DefaultSAPolicies,
DefaultTCHPolicies,
DefaultSTPolicies,
);
const policyExistenceResult = await Promise.all(
initialPolicies.map(async (policy) => {
const exists = await this.rbacService.DoesPolicyExists(policy);
return { exists, policy };
}),
);
console.log(policyExistenceResult);
await this.rbacService.GrantPermissionBulk(policyExistenceResult.filter((p) => !p.exists).map((p) => p.policy));
}
"casbin": "^5.27.1",
"casbin-prisma-adapter": "^1.4.0",
Is something wrong here or is the intended behaviour
Before_Adding_one_policy
After_Adding_one_policy
