elasticio / casbin-mongoose-adapter Goto Github PK
View Code? Open in Web Editor NEWMongoose adapter for Casbin
License: Apache License 2.0
Mongoose adapter for Casbin
License: Apache License 2.0
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
casbin-mongoose-adapter/src/adapter.js
Line 141 in 4a87b7a
Now the problem is that when a filtered adapter is first created casbin internally calls loadPolicy(model)
casbin-mongoose-adapter/src/adapter.js
Line 126 in 4a87b7a
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.
I think it makes sense to give this adapter ability to reuse existing mongoose connection during creation, because it usually already exists in the application using this adapter.
https://github.com/elasticio/casbin-mongoose-adapter/blob/master/src/adapter.js#L197
General idea of this function is to save whole policy file or nothing. Now it will save part of it if it fails a half way through.
However standard mongoDB multi-document transaction is only supported by replicas and/or shards. I'm not sure whether to fix it by using different outsourced library (mongoose-transaction), just use a try-catch-finally setup to just delete already saved documents or just disable this function if replica / shard is not found.
Firstly thanks for putting this together, works really well!
I'm using the adapter in some tests and the tests fail to exit because the mongodb connection is still open, i'd like a way to call something like adapter.close()
on the instance.
This would also be useful outside of automated tests to allow for graceful shutdown of an app.
Hi guys, the original author ghaiklor of this repo has left elasticio and this repo is left unmaintained for long time.
Therefore, the official Casbin team has forked this repo to: https://github.com/node-casbin/mongoose-adapter and is actively maintaining it for fixing bugs, add new features. But it seems there are still some people come to this repo, create issues with no feedback.
So for the better of Casbin users, can we move this repo to Casbin officially? (given that Casbin has a working fork now, it's similar like deleting this repo, making it private or at least archiving this repo and make some pointer to the new one). So people will not get lost. What do you say? Thanks!
Hello,
Thanks you for your work.
Could you tag the last master version please ?
At least the version which includes the close()
method which is required for most of integration in order to properly close the mongodb connection ?
Thanks a lot.
Hi, i've used this mongoose adapter to handle rules in mongodb, I can't delete roles, what i'm doing wrong?
static async getInstance() {
const adapter = await Adapter.newAdapter(db.uri, db.config);
const model = `${process.env.STORAGE_PATH}/casbin/rbac.conf`;
return casbin.newEnforcer(model, adapter);
}
Assign roles works properly.
static async assignRole(identifier, role, domain = '*') {
const enforcer = await Enforcer.getInstance();
return enforcer.addRoleForUser(identifier, role, domain);
}
deleteRoleForUser returns false
static async revokeRole(identifier, role, domain = 'admin') {
const enforcer = await Enforcer.getInstance();
console.log(identifier, role, domain);
return enforcer.deleteRoleForUser(identifier, role);
}
deleteRolesForUser returns false
static async revokeRoles(identifier) {
const enforcer = await Enforcer.getInstance();
return enforcer.deleteRolesForUser(identifier);
}
Is possible to upgrade mongoose from 5.9.16 to 5.10.8 ? We need to make use of mongo authentication mechanism MONGODB-AWS and that version doesn't support it.
If not, is there any workaround?
thanks in advance
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.