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

FilteredAdapter should not dynamically change to ordinary Adapter #2

Open
ulanmurzatayev opened this issue Feb 22, 2019 · 3 comments
Open
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@ulanmurzatayev
Copy link

When creating a FilteredAdapter with MongooseAdapter.newFilteredAdapter(config.db) it is expected to stay as FilteredAdapter. However current behaviour is that it changes dynamically during execution

this.setFiltered(false);

Now the problem is that when a filtered adapter is first created casbin internally calls loadPolicy(model)

async loadPolicy (model) {

which 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#L164

I think loadPolicy() should work without changing the adapter type.

@ghaiklor
Copy link
Contributor

ghaiklor commented Apr 8, 2019

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.

@ulanmurzatayev
Copy link
Author

well it could be that there is a bug in mongodb-adapter as well. @ghaiklor do you agree that this should not happen?

@ghaiklor
Copy link
Contributor

ghaiklor commented Apr 9, 2019

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.

@ghaiklor ghaiklor added bug Something isn't working help wanted Extra attention is needed labels Apr 9, 2019
Sefriol pushed a commit to Sefriol/casbin-mongoose-adapter that referenced this issue Feb 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants