Get unlimited public & private packages + package-based permissions with npm Pro.Get started »

@elastic.io/casbin-mongoose-adapter

1.0.0 • Public • Published

casbin-mongoose-adapter

MongoDB policy storage, implemented as an adapter for node-casbin.

Getting Started

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.

Configuration

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

Filtered Adapter

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');

License

Apache-2.0

Install

npm i @elastic.io/casbin-mongoose-adapter

DownloadsWeekly Downloads

164

Version

1.0.0

License

Apache-2.0

Unpacked Size

38.3 kB

Total Files

17

Last publish

Collaborators

  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar