All Projects → casbin → Xorm Adapter

casbin / Xorm Adapter

Licence: apache-2.0
Xorm adapter for Casbin

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to Xorm Adapter

Gorm Adapter
Gorm adapter for Casbin
Stars: ✭ 373 (+13.37%)
Mutual labels:  orm, adapter, authorization, access-control, casbin
sequelize-adapter
Sequelize adapter for Casbin
Stars: ✭ 51 (-84.5%)
Mutual labels:  adapter, orm, authorization, access-control, casbin
Protobuf Adapter
Google Protocol Buffers adapter for Casbin
Stars: ✭ 185 (-43.77%)
Mutual labels:  adapter, authorization, access-control, casbin
Redis Adapter
Redis adapter for Casbin
Stars: ✭ 167 (-49.24%)
Mutual labels:  adapter, authorization, access-control, casbin
Mongodb Adapter
MongoDB adapter for Casbin
Stars: ✭ 194 (-41.03%)
Mutual labels:  adapter, authorization, access-control, casbin
sqlx-adapter
Asynchronous casbin adapter for mysql, postgres, sqlite based on sqlx-rs
Stars: ✭ 27 (-91.79%)
Mutual labels:  adapter, access-control, casbin
Beego Authz
Beego's RBAC & ABAC Authorization middleware based on Casbin
Stars: ✭ 208 (-36.78%)
Mutual labels:  authorization, access-control, casbin
casbin-ex
An authorization library that supports access control models like ACL, RBAC, ABAC in Elixir
Stars: ✭ 37 (-88.75%)
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 (-52.89%)
Mutual labels:  authorization, access-control, casbin
Chi Authz
chi-authz is an authorization middleware for Chi
Stars: ✭ 248 (-24.62%)
Mutual labels:  authorization, access-control, casbin
Casbin4D
An authorization library that supports access control models like ACL, RBAC, ABAC in Delphi
Stars: ✭ 25 (-92.4%)
Mutual labels:  authorization, access-control, casbin
Casbin Authz Plugin
Docker Authorization Plugin based on Casbin
Stars: ✭ 204 (-37.99%)
Mutual labels:  authorization, access-control, casbin
Casbin Server
Casbin as a Service (CaaS)
Stars: ✭ 171 (-48.02%)
Mutual labels:  authorization, access-control, casbin
Caddy Authz
Caddy-authz is a middleware for Caddy that blocks or allows requests based on access control policies.
Stars: ✭ 221 (-32.83%)
Mutual labels:  authorization, access-control, casbin
Etcd Watcher
Etcd watcher for Casbin
Stars: ✭ 157 (-52.28%)
Mutual labels:  authorization, access-control, casbin
jdbc-adapter
JDBC adapter for Casbin
Stars: ✭ 26 (-92.1%)
Mutual labels:  adapter, authorization, access-control
lua-casbin
An authorization library that supports access control models like ACL, RBAC, ABAC in Lua (OpenResty)
Stars: ✭ 43 (-86.93%)
Mutual labels:  authorization, access-control, casbin
Laravel Authz
An authorization library that supports access control models like ACL, RBAC, ABAC in Laravel.
Stars: ✭ 136 (-58.66%)
Mutual labels:  authorization, access-control, casbin
Negroni Authz
negroni-authz is an authorization middleware for Negroni
Stars: ✭ 152 (-53.8%)
Mutual labels:  authorization, access-control, casbin
dart-casbin
An authorization library that supports access control models like ACL, RBAC, ABAC in Dart/Flutter
Stars: ✭ 30 (-90.88%)
Mutual labels:  authorization, access-control, casbin

Xorm Adapter Build Status Coverage Status Go Report Card Godoc

Xorm Adapter is the Xorm adapter for Casbin. With this library, Casbin can load policy from Xorm supported database or save policy to it.

Based on Xorm Drivers Support, The current supported databases are:

Installation

go get github.com/casbin/xorm-adapter

Simple MySQL Example

package main

import (
	"github.com/casbin/casbin/v2"
	_ "github.com/go-sql-driver/mysql"

	"github.com/casbin/xorm-adapter/v2"
)

func main() {
	// Initialize a Xorm adapter and use it in a Casbin enforcer:
	// The adapter will use the MySQL database named "casbin".
	// If it doesn't exist, the adapter will create it automatically.
	a, _ := xormadapter.NewAdapter("mysql", "mysql_username:[email protected](127.0.0.1:3306)/") // Your driver and data source. 

	// 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 := xormadapter.NewAdapter("mysql", "mysql_username:[email protected](127.0.0.1:3306)/abc", true)

	e, _ := casbin.NewEnforcer("examples/rbac_model.conf", a)
	
	// 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()
}

Simple Postgres Example

package main

import (
	"github.com/casbin/casbin/v2"
	_ "github.com/lib/pq"

	"github.com/casbin/xorm-adapter"
)

func main() {
	// Initialize a Xorm adapter and use it in a Casbin enforcer:
	// The adapter will use the Postgres database named "casbin".
	// If it doesn't exist, the adapter will create it automatically.
	a, _ := xormadapter.NewAdapter("postgres", "user=postgres_username password=postgres_password host=127.0.0.1 port=5432 sslmode=disable") // Your driver and data source.

	// 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 := xormadapter.NewAdapter("postgres", "dbname=abc user=postgres_username password=postgres_password host=127.0.0.1 port=5432 sslmode=disable", true)

	e, _ := casbin.NewEnforcer("../examples/rbac_model.conf", a)

	// 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()
}

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].