Code Monkey home page Code Monkey logo

casbin-mongodb-adapter's People

Contributors

17bit avatar fdorantesm avatar halidm avatar juicycleff avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

casbin-mongodb-adapter's Issues

Update npm package

First off, thanks to all contributors for creating and maintaining this adapter!

I am getting the this.adapter.isFiltered bug, using version v1.1.11, which is the most recent version on npm. Could you update the npm package to include the recent changes to the codebase?

removePolicies, and removeGroupingPolicies not able to delete document actually

In my code, I try to delete a policies via casbin's removePolicies([["GROUP-1", "DOMAIN-A", "POLICY-A1", "ACT-BIND"], ...]), but this document not be deleted from database actually. I found the adapter calling the MongoDb deleteOne() function with current timestamp as below, but that document with different timestamp in my database, and that causes deleting failed.

{ createdAt: '2023-11-15T10:02:18.402Z', updatedAt: '2023-11-15T10:02:18.402Z', ptype: 'p', v0: 'GROUP-1, v1: 'DOMAIN-A', v2: 'POLICY_A1', v3: 'ACT-BIND' }

Please remove the timestamp from the deletion condition.

It that possible to support data updating with mongoDB transaction?

In my code, I update mongo DB documents with transaction, which could guaranty my updating would not leak or conflict. However, my transaction seems not able to apply to the casbint documents updating. Is that possible to let me to pass my client session to the adapter?

TyperError: this.adapter.isFiltered is not a function

I was attempting to use the RBAC management api and noticed that the delete was not persisting (autosave I guess doesn't work for deleteUser). So I attempted to use savePolicy and got the following error:

    TypeError: this.adapter.isFiltered is not a function

      46 |     const enforcer = await getInstance();
      47 |     const result = await enforcer.deleteUser(user.id);
    > 48 |     await enforcer.savePolicy();
         |                    ^
      49 |     return result;
      50 |   },
      51 | 

      at Enforcer.isFiltered (node_modules/casbin/lib/coreEnforcer.js:175:33)
      at Enforcer.<anonymous> (node_modules/casbin/lib/coreEnforcer.js:185:22)
      at node_modules/casbin/lib/coreEnforcer.js:21:71
      at __awaiter (node_modules/casbin/lib/coreEnforcer.js:17:12)
      at Enforcer.savePolicy (node_modules/casbin/lib/coreEnforcer.js:184:16)
      at Object.removeUser (api/services/AuthorizationService.js:48:20)
      at Object.<anonymous> (tests/services/authorization.test.js:79:3)

Diving deeper I noticed that node-casbin expects isFiltered to be a function see https://github.com/casbin/node-casbin/blob/master/src/coreEnforcer.ts#L184.

  public isFiltered(): boolean {
    if ('isFiltered' in this.adapter) {
      return this.adapter.isFiltered();
    }
    return false;
  }

Current state of isFiltered in the adapter.

Workaround for those interested:

  adapter = await MongoAdapter.newAdapter({
    // config for mongo here
  });
  // workaround
  delete adapter.isFiltered;
  // casbin initialization
  enforcer = await casbin.newEnforcer(model, adapter);

I'm not currently using filtered yet... so I'm not sure how useful this will be to anyone.

Is not possible to use removeFilteredPolicy properly

The removeFilteredPolicy creates a new object using the CasbinRule class,

const line = new CasbinRule();

which create a instance with the properties createdAt and updatedAt

this.createdAt = new Date().toISOString();

providing a object which will use to in the deleteMany in the following format

{
 createdAt: '2021-06-18T20:47:52.585Z',
 updatedAt: '2021-06-18T20:47:52.585Z',
 ptype: 'p',
 v0: 'user',
 v1: 'pietro.verdile',
 v2: 1,
 v3: 'library',
 v4: 'systemTags',
 v5: 'eq;lib_60ccdfa5bc9e5400376a03ac'
}

This object never will match any document in MongoDB due the properties createdAt and updatedAt.

Deprecation warning

[MONGODB DRIVER] Warning: Current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor.

How to fix Error: The "url" argument must be of type string. Received undefined

const { MongoAdapter } = require('casbin-mongodb-adapter');

let uri = 'mongodb://192.168.99.100:27017,192.168.99.101:27017,192.168.99.102:27017/casbin';

const connect = (options) => {

 const adapter = await MongoAdapter.newAdapter({
      uri: uri ,
      option: {
        db: options.dbParameters(),
        server: options.serverParameters(),
        replset: options.replsetParameters(options.repl)
      }
    })

  return adapter;
}

RUN return error :

(node:11963) UnhandledPromiseRejectionWarning: Error: The "url" argument must be of type string. Received undefined at MongoAdapter.open (/Users/iadm/Project/microservice/authorization/node_modules/casbin-mongodb-adapter/build/main/lib/adapter.js:162:19) at processTicksAndRejections (internal/process/task_queues.js:97:5) at async Function.newAdapter (/Users/iadm/Project/microservice/authorization/node_modules/casbin-mongodb-adapter/build/main/lib/adapter.js:35:9) at async EventEmitter.<anonymous> (/Users/iadm/Project/microservice/authorization/src/config/db/mongo.js:15:21) (Usenode --trace-warnings ...to show where the warning was created)

How to fix Error: cannot to save policy, the adapter does not implement the BatchAdapter

Hello,

I am using following casbin and driver version
"casbin": "5.7.1"
"casbin-mongodb-adapter": "1.2.0"

I am trying to use batch method - addNamedPolicies('p', permissions);
I am getting following error while using this method

Error: cannot to save policy, the adapter does not implement the BatchAdapter

Can you please help me fix all the batch processing methods like addNamedPolicies(), RemoveNamedGroupingPolicies() issue in the adapter.

Why force users to install with yarn?

I am working on a project where I'd like to use this package. However, when trying to install with npm, the (intended) error message pops up: casbin-mongo-adapter must be installed with Yarn.

Is there any reason behind this rather than a a preference for Yarn? I work in an all-npm environment (including our CI servers, all other team members' development environments, ...), so changing to Yarn for just this one package is not an option.

If there is no other reason rather than a preference for Yarn, would you agree to removing the preinstall hook?

Update: I find this especially confusing as the README states to install using npm.

Mongodb Error during removeNamedGroupingPolicies method -

Hello,
I am using following version of casbin and adapter

"casbin": "5.7.1",
"casbin-mongodb-adapter": "1.2.2"

After adding batch processing in latest adapter version "1.2.2", I am able to use addNamedGroupingPolicies method.
But, while trying the removeNamedGroupingPolicies method I am getting following error

Reference Method - https://casbin.org/docs/en/management-api#removenamedgroupingpolicies

Example:- enforcer.removeNamedGroupingPolicies("g2", [[ "[email protected]", "Group1", "Floor1"]]);

error: MongoError: BSON field 'delete.deletes.q' is the wrong type 'array', expected type 'object'
error": {
"ok": 0,
"code": 14,
"codeName": "TypeMismatch",
"name": "MongoError"
}

Can you please help me resolve this issue.
Thank you.

savePolicy behavior

I am working on a project that deals with a larger amount of permissions. There is a REST service to manage permissions/roles. Each time a permission or role has been changed, I called await enforcer.savePolicy();.

Now I realized that savePolicy effectively drops the entire casbin mongo collection and re-creates it with the new policy data. When calling it in concurrent scenarios (e.g. I have two concurrent requests to add a permission), that results in the following situation:

  1. The first permission is created,
  2. savePolicy is called and drops the collection,
  3. the second permission is created,
  4. savePolicy is called and drops the collection,
  5. At the end, only the second permission is in the collection.

In other scenarios (I cannot quite reproduce when exactly), step 4 throws an error (ns not found) as it apparently tries to perform operations on the now-dropped collection.

I solved this in my application now by waiting for all write operations to finish, and only then call savePolicy.

Is this something that could be implemented in the adapter itself? Alternatively, would this behavior be something worth mentioning in the documentation?

Update: The problem only occured once we moved to a replica set rather than a single Mongo instance.

Casbin mongo adapter not connected error

package.json

{
  "dependencies": {
      "mongodb": "^4.3.1"
  }
}
Error: Error: Casbin mongo adapter not connected

This property this.mongoClient.isConnected is undefined and is used to validate connection previous query.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.