Open ulanmurzatayev opened 5 years ago
Strange, but MongoDB adapter for casbin allows to change it in runtime - https://github.com/casbin/mongodb-adapter/blob/master/adapter.go#L186-L190
Actually, these chunks of code you provided is a direct port from there.
well it could be that there is a bug in mongodb-adapter as well. @ghaiklor do you agree that this should not happen?
after some investigation into internals - agreed.
we should set the filtered flag to true only when calling from newFilteredAdapter
and do not change it in runtime.
If the adapter was created as filtered one, it should stay that way and otherwise.
When creating a
FilteredAdapter
withMongooseAdapter.newFilteredAdapter(config.db)
it is expected to stay as FilteredAdapter. However current behaviour is that it changes dynamically during execution https://github.com/elasticio/casbin-mongoose-adapter/blob/4a87b7ac0401e024016bee18145a0db9bddbda3a/src/adapter.js#L141Now the problem is that when a filtered adapter is first created casbin internally calls
loadPolicy(model)
https://github.com/elasticio/casbin-mongoose-adapter/blob/4a87b7ac0401e024016bee18145a0db9bddbda3a/src/adapter.js#L126which switches it back to an ordinary adapter. Then if a user calls
enforcer.loadFilteredPolicy()
casbin throws an error, as it does not recognize the adapter to be filtered anymore https://github.com/casbin/node-casbin/blob/40dd90a6dd7a023746bc3c15593d96d802c612ab/src/coreEnforcer.ts#L164I think
loadPolicy()
should work without changing the adapter type.