Skip to content
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

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

Open
cjz-lxg opened this issue Jan 23, 2024 · 1 comment
Open

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

cjz-lxg opened this issue Jan 23, 2024 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@cjz-lxg
Copy link

cjz-lxg commented Jan 23, 2024

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

@casbin-bot casbin-bot added the enhancement New feature or request label Jan 23, 2024
@casbin-bot
Copy link
Member

@nodece @Shivansh-yadav13

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Development

No branches or pull requests

3 participants