node-casbin/sequelize-adapter

Two enforcers with two different adapters only load one set of policies.

yufeifan opened this issue · 10 comments

async function init(mode){
    let adapter = await SequelizeAdapter.newAdapter(`mysql://${mysql_user}:${mysql_password}@${mysql_host}:${mysql_port}/${mode}_casbin`,true);
    let enforcer = await Enforcer.newEnforcer(
        `${conf_uri}/${mode}.conf`,
        adapter
    );
    await enforcer.loadPolicy();
    return enforcer;
}

after init,set enforcer connecting in memory,
after init twice,use connecting in memory and two connecting only load one side policys.

I can't understand your question. Can you rephrase it?

@nodece @Chalin-Shi

我在使用时首先调用了init函数来初始化enforcer,并将返回的enforcer存在内存的一个map中。
比如
{
mode1:enforcer1,
mode2:enforcer2,
}
之后的请求取出map中相应的enforcer来操作policy。
问题是当map的子对象为2时,不管使用enforcer1还是enforcer2都将只会连接到其中一个enforcer的持续化存储。

@yufeifan Please join our QQ group for discussion: https://casbin.org/en/help

I have tested with:

const a = await SequelizeAdapter.newAdapter('mysql://root:@localhost:3306/1_casbin', true);

It works and uses different DB with something like casbin.

const a = await SequelizeAdapter.newAdapter('mysql://root:@localhost:3306/a_casbin', true);
const b = await SequelizeAdapter.newAdapter('mysql://root:@localhost:3306/b_casbin', true);
const enforcer = await Enforcer.newEnforcer(conf, a);


await enforcer.loadPolicy();    

only load policy from b.

I don't think it's possible, because enforcer has nothing to do with b in the code. @nodece @Chalin-Shi can you help follow up this issue and test it?

Now make sure this is a bug, We will fix it as soon as possible.

@yufeifan , this bug has been fixed in: #10

Thanks @nodece