casbin / mongodb-adapter

MongoDB adapter for Casbin
https://github.com/casbin/casbin
Apache License 2.0
260 stars 53 forks source link

Error encountered when creating an Enforcer based on the ABAC model: extraneous or missing "in quoted field" #63

Open Harris-H opened 10 months ago

Harris-H commented 10 months ago

I found that the first time I created an Enforcer when the database was empty and checked if the request was fulfilled without any issues, but when the database included these policies, creating an Enforcer would result in an error message: extraneous or missing "in quoted field". What is the problem? Please help me.

I am using an adapter based on MongoDB

    a, err := mongodbadapter.NewAdapterWithClientOption(mongoClientOption, databaseName)
    if err != nil {
        panic(err)
    }

    e, err := casbin.NewEnforcer("../conf/abac_model.conf", a)

My model:

[request_definition]
r = sub, obj, act

[policy_definition]
p = sub_rule, obj, act

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

[matchers]
m = eval(p.sub_rule) && r.obj == p.obj && r.act == p.act

My policy: image

My request(s):

models.UserRole{
        Role: "test_admin",
    }, index, read ---> true
hsluoyz commented 10 months ago

@Harris-H can you provide a full example? Which API did you call? and paste the IDE error directly

Harris-H commented 10 months ago

@Harris-H can you provide a full example? Which API did you call? and paste the IDE error directly

image When I call the NewEnforcer() function API, I will report an error: extraneous or missing "in quoted field". However, I will not report an error when I do not have a policy in the database. Testing with request also runs normally, and creating an Enforcer again after adding a policy will report an error.

image