All Projects → casbin → Mongodb Adapter

casbin / Mongodb Adapter

Licence: apache-2.0
MongoDB adapter for Casbin

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to Mongodb Adapter

sequelize-adapter
Sequelize adapter for Casbin
Stars: ✭ 51 (-73.71%)
Mutual labels:  adapter, authorization, access-control, casbin
Gorm Adapter
Gorm adapter for Casbin
Stars: ✭ 373 (+92.27%)
Mutual labels:  adapter, authorization, access-control, casbin
Xorm Adapter
Xorm adapter for Casbin
Stars: ✭ 329 (+69.59%)
Mutual labels:  adapter, authorization, access-control, casbin
Redis Adapter
Redis adapter for Casbin
Stars: ✭ 167 (-13.92%)
Mutual labels:  adapter, authorization, access-control, casbin
Protobuf Adapter
Google Protocol Buffers adapter for Casbin
Stars: ✭ 185 (-4.64%)
Mutual labels:  adapter, authorization, access-control, casbin
Node Casbin
An authorization library that supports access control models like ACL, RBAC, ABAC in Node.js and Browser
Stars: ✭ 1,757 (+805.67%)
Mutual labels:  authorization, access-control, casbin
Casbin.net
An authorization library that supports access control models like ACL, RBAC, ABAC in .NET (C#)
Stars: ✭ 535 (+175.77%)
Mutual labels:  authorization, access-control, casbin
Laravel Authz
An authorization library that supports access control models like ACL, RBAC, ABAC in Laravel.
Stars: ✭ 136 (-29.9%)
Mutual labels:  authorization, access-control, casbin
Casbin Editor
Web-based model & policy editor for Casbin
Stars: ✭ 45 (-76.8%)
Mutual labels:  authorization, access-control, casbin
Pycasbin
An authorization library that supports access control models like ACL, RBAC, ABAC in Python
Stars: ✭ 625 (+222.16%)
Mutual labels:  authorization, access-control, casbin
Negroni Authz
negroni-authz is an authorization middleware for Negroni
Stars: ✭ 152 (-21.65%)
Mutual labels:  authorization, access-control, casbin
Casbin Rs
An authorization library that supports access control models like ACL, RBAC, ABAC in Rust.
Stars: ✭ 375 (+93.3%)
Mutual labels:  authorization, access-control, casbin
Jcasbin
An authorization library that supports access control models like ACL, RBAC, ABAC in Java
Stars: ✭ 1,335 (+588.14%)
Mutual labels:  authorization, access-control, casbin
Etcd Watcher
Etcd watcher for Casbin
Stars: ✭ 157 (-19.07%)
Mutual labels:  authorization, access-control, casbin
Casbin Cpp
An authorization library that supports access control models like ACL, RBAC, ABAC in C/C++
Stars: ✭ 113 (-41.75%)
Mutual labels:  authorization, access-control, casbin
Openstack Policy Editor
A Casbin Policy Editor for OpenStack
Stars: ✭ 28 (-85.57%)
Mutual labels:  authorization, access-control, casbin
Casbin4D
An authorization library that supports access control models like ACL, RBAC, ABAC in Delphi
Stars: ✭ 25 (-87.11%)
Mutual labels:  authorization, access-control, casbin
jdbc-adapter
JDBC adapter for Casbin
Stars: ✭ 26 (-86.6%)
Mutual labels:  adapter, authorization, access-control
Casbin
An authorization library that supports access control models like ACL, RBAC, ABAC in Golang
Stars: ✭ 10,872 (+5504.12%)
Mutual labels:  authorization, access-control, casbin
Think Authz
An authorization library that supports access control models like ACL, RBAC, ABAC in ThinkPHP 6.0 .
Stars: ✭ 155 (-20.1%)
Mutual labels:  authorization, access-control, casbin

MongoDB Adapter Build Status Coverage Status Godoc

MongoDB Adapter is the Mongo DB adapter for Casbin. With this library, Casbin can load policy from MongoDB or save policy to it.

Installation

go get -u github.com/casbin/mongodb-adapter/v3

Simple Example

package main

import (
	"github.com/casbin/casbin/v2"
	"github.com/casbin/mongodb-adapter/v3"
)

func main() {
	// Initialize a MongoDB adapter and use it in a Casbin enforcer:
	// The adapter will use the database named "casbin".
	// If it doesn't exist, the adapter will create it automatically.
	a,err := mongodbadapter.NewAdapter("127.0.0.1:27017") // Your MongoDB URL. 
	if err != nil {
		panic(err)
	}
	// Or you can use an existing DB "abc" like this:
	// The adapter will use the table named "casbin_rule".
	// If it doesn't exist, the adapter will create it automatically.
	// a := mongodbadapter.NewAdapter("127.0.0.1:27017/abc")

	e, err := casbin.NewEnforcer("examples/rbac_model.conf", a)
	if err != nil {
		panic(err)
	}

	// Load the policy from DB.
	e.LoadPolicy()
	
	// Check the permission.
	e.Enforce("alice", "data1", "read")
	
	// Modify the policy.
	// e.AddPolicy(...)
	// e.RemovePolicy(...)
	
	// Save the policy back to DB.
	e.SavePolicy()
}

Filtered Policies

import "github.com/globalsign/mgo/bson"

// This adapter also implements the FilteredAdapter interface. This allows for
// efficent, scalable enforcement of very large policies:
filter := &bson.M{"v0": "alice"}
e.LoadFilteredPolicy(filter)

// The loaded policy is now a subset of the policy in storage, containing only
// the policy lines that match the provided filter. This filter should be a
// valid MongoDB selector using BSON. A filtered policy cannot be saved.

Getting Help

License

This project is under Apache 2.0 License. See the LICENSE file for the full license text.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].