Skip to content

Why I can't use enforcer to judge the req using the rbac modle?  #470

Open
@cjz-lxg

Description

@cjz-lxg

I save the policy in the mysql , and I have init the enforcer by rbac_model.conf . but I find it doesn't successed , it was return true only
when sub, obj,act are same in the p policy in the db , doesn't check the g policy, how can I modify my code to achieve the result of rbac?

export const authorizeUser = async (
  sub: string,
  obj: string,
  act: string
) => {
  const enforcer = await CasbinManager.getEnforcer();
  // console.log("sub: ", sub, "dom: ", dom, "obj: ", obj, "act: ", act);
  // console.log(await enforcer?.getPolicy());
  // console.log(await enforcer?.getGroupingPolicy());
  const res = enforcer?.enforceEx(
    sub,
    obj,
    act
  );
  console.log(await res);
  return true;
};
[request_definition]
r = sub,  obj, act

[policy_definition]
p = sub,  obj, act

[role_definition]
g = _, _

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

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

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

Status

Node-Casbin Easy Tasks

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions