
Product
Introducing Socket Fix for Safe, Automated Dependency Upgrades
Automatically fix and test dependency updates with socket fix—a new CLI tool that turns CVE alerts into safe, automated upgrades.
@elastic.io/casbin-mongoose-adapter
Advanced tools
MongoDB policy storage, implemented as an adapter for node-casbin.
Install the package as dependency in your project:
npm install --save @elastic.io/casbin-mongoose-adapter
Require it in a place, where you are instantiating an enforcer (read more about enforcer here):
const path = require('path');
const { newEnforcer } = require('casbin');
const MongooseAdapter = require('@elastic.io/casbin-mongoose-adapter');
const model = path.resolve(__dirname, './your_model.conf');
const adapter = await MongooseAdapter.newAdapter('mongodb://your_mongodb_uri:27017');
const enforcer = await newEnforcer(model, adapter);
That is all what required for integrating the adapter into casbin. Casbin itself calls adapter methods to persist updates you made through it.
You can pass mongooose-specific options when instantiating the adapter:
const MongooseAdapter = require('@elastic.io/casbin-mongoose-adapter');
const adapter = await MongooseAdapter.newAdapter('mongodb://your_mongodb_uri:27017', { mongoose_options: 'here' });
Additional information regard to options you can pass in you can find in mongoose documentation
You can create an adapter instance that will load only those rules you need to.
A simple case for it is when you have separate policy rules for separate domains (tenants). You do not need to load all the rules for all domains to make an authorization in specific domain.
For such cases, filtered adapter exists in casbin.
const MongooseAdapter = require('@elastic.io/casbin-mongoose-adapter');
const adapter = await MongooseAdapter.newFilteredAdapter('mongodb://your_mongodb_uri:27017');
FAQs
Mongoose adapter for Casbin
The npm package @elastic.io/casbin-mongoose-adapter receives a total of 6 weekly downloads. As such, @elastic.io/casbin-mongoose-adapter popularity was classified as not popular.
We found that @elastic.io/casbin-mongoose-adapter demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Automatically fix and test dependency updates with socket fix—a new CLI tool that turns CVE alerts into safe, automated upgrades.
Security News
CISA denies CVE funding issues amid backlash over a new CVE foundation formed by board members, raising concerns about transparency and program governance.
Product
We’re excited to announce a powerful new capability in Socket: historical data and enhanced analytics.