# Apache Casbin > Apache Casbin (Incubating) is an open-source authorization library that supports access control models like ACL, RBAC, ABAC, ReBAC, PBAC, BLP, Biba and more. A model file (PERM: policy, effect, request, matchers) and policy rules decide every request, and the same model works in Go, Java, Node.js, Python, .NET, PHP, Rust, C++ and other languages. ## Basics - [Overview](https://casbin.apache.org/docs/overview/): Apache Casbin is an open-source authorization library for Go, Java, Node.js, Python, .NET, PHP, Rust and C++ that supports ACL, RBAC, ABAC, ReBAC and more. - [Get Started](https://casbin.apache.org/docs/get-started/): Install Casbin for Go, Java, Node.js, PHP, Python, .NET, C++ or Rust, create an enforcer from a model and policy, and run your first authorization check. - [How It Works](https://casbin.apache.org/docs/how-it-works/): How Casbin works - the PERM metamodel (Policy, Effect, Request, Matchers) and CONF model files that let you switch between ACL, RBAC, ABAC and custom models. - [Tutorials](https://casbin.apache.org/docs/tutorials/): Casbin papers, videos and community tutorials for Go, Java, Node.js, Python, PHP, .NET and other languages, plus articles on modeling with PERM. ## Guides - [Golang RBAC Tutorial: Role-Based Access Control in Gin](https://casbin.apache.org/docs/go-rbac-tutorial/): Step-by-step Go RBAC tutorial - add role-based access control to a Gin REST API with Casbin, including the model, policy, middleware, and runtime role management. - [Node.js RBAC Tutorial: Role-Based Access Control in Express](https://casbin.apache.org/docs/nodejs-rbac-tutorial/): Step-by-step Node.js RBAC tutorial - add role-based access control to an Express REST API with Casbin, including the model, policy, middleware, and runtime role management. - [Python RBAC Tutorial: Role-Based Access Control in FastAPI](https://casbin.apache.org/docs/python-rbac-tutorial/): Step-by-step Python RBAC tutorial - add role-based access control to a FastAPI REST API with PyCasbin, including the model, policy, dependency, and runtime role management. - [Spring Boot RBAC Tutorial: Role-Based Access Control with jCasbin](https://casbin.apache.org/docs/java-rbac-tutorial/): Step-by-step Java RBAC tutorial - add role-based access control to a Spring Boot REST API with jCasbin, including the model, policy, interceptor, and runtime role management. - [NestJS RBAC Tutorial: Role-Based Access Control with Guards](https://casbin.apache.org/docs/nestjs-rbac-tutorial/): NestJS RBAC tutorial: role-based access control with role inheritance for a NestJS API, using node-casbin, a global guard and a permission decorator. - [RBAC in Rust with Axum](https://casbin.apache.org/docs/rust-rbac-tutorial/): Rust RBAC tutorial: role-based access control for an Axum REST API with casbin-rs, including the model, policy, middleware and runtime role changes. - [gRPC Authorization in Go](https://casbin.apache.org/docs/grpc-rbac-tutorial/): Role-based access control for a Go gRPC service with Casbin: unary and stream interceptors that check the caller's role against the full method name. - [ABAC in Go](https://casbin.apache.org/docs/go-abac-tutorial/): Go ABAC tutorial: attribute-based access control for a net/http API with Casbin, using owner, department and status to decide who can read, edit and publish. - [ABAC in Node.js with Express](https://casbin.apache.org/docs/nodejs-abac-tutorial/): Node.js ABAC tutorial: attribute-based access control for an Express API with node-casbin, using owner, department and status to decide who can edit. - [ABAC in Python with Flask](https://casbin.apache.org/docs/flask-abac-tutorial/): Python ABAC tutorial: attribute-based access control for a Flask API with PyCasbin, using owner, department and status to decide who can read and edit. - [Authorization for AI Agents and MCP Tools](https://casbin.apache.org/docs/ai-agent-authorization/): Control which tools an AI agent may call with Casbin: per-agent permissions, argument limits, deny rules, and no more access than its user. With an MCP example. ## Access Control Models - [RBAC vs ABAC vs ACL vs ReBAC: Choosing an Access Control Model](https://casbin.apache.org/docs/access-control-models/): ACL, RBAC, ABAC, ReBAC and PBAC compared on one example: what each decides on, strengths, weaknesses, when to choose it, and how to combine RBAC with ABAC. - [Supported Models](https://casbin.apache.org/docs/supported-models/): Access control models supported by Casbin - ACL, RBAC, RBAC with domains, ABAC, ReBAC, PBAC, BLP, Biba, LBAC, OrBAC, UCON, RESTful, IP match, deny-override and priority. - [Model Syntax](https://casbin.apache.org/docs/syntax-for-models/): Casbin model syntax reference - request, policy, role and effect definitions and matchers in CONF files, with operators and examples. - [Effector](https://casbin.apache.org/docs/effector/): The Casbin Effector interface combines the effects of all matching policy rules into one decision, for allow-override, deny-override, priority and custom effects. - [Functions](https://casbin.apache.org/docs/function/): Built-in Casbin matcher functions - keyMatch, keyMatch2-5, regexMatch, ipMatch, globMatch and key extraction - and how to register your own custom functions. - [RBAC Overview](https://casbin.apache.org/docs/rbac-overview/): Overview of role-based access control (RBAC) in Casbin - basic RBAC, resource roles, domains (multi-tenancy), pattern matching and conditional roles. - [What is RBAC? Role-Based Access Control in Casbin](https://casbin.apache.org/docs/rbac/): What role-based access control (RBAC) is and how to use it in Casbin: define roles with role_definition, assign users to roles, build role hierarchies and check roles in matchers. - [RBAC with Pattern](https://casbin.apache.org/docs/rbac-with-pattern/): Use wildcards and patterns in Casbin role assignments and domains with AddNamedMatchingFunc and AddNamedDomainMatchingFunc. - [RBAC with Domains](https://casbin.apache.org/docs/rbac-with-domains/): Multi-tenant RBAC with Casbin - give the same user different roles in different domains or tenants with a three-argument role definition. - [RBAC with Conditions](https://casbin.apache.org/docs/rbac-with-conditions/): Attach conditions to Casbin role assignments with the conditional role manager, for example roles that are valid only within a time window. - [RBAC vs. RBAC96](https://casbin.apache.org/docs/rbac-96/): How Casbin RBAC relates to the RBAC96 standard - users and roles, role hierarchies, sessions and constraints, and what Casbin adds with domains and flexible permissions. - [What is ReBAC? Relationship-Based Access Control with Examples](https://casbin.apache.org/docs/rebac/): What relationship-based access control (ReBAC) is, how it relates to Google Zanzibar, how it differs from RBAC and ABAC, and how to model user-resource relationships in Casbin. - [What is ABAC? Attribute-Based Access Control with Examples](https://casbin.apache.org/docs/abac/): What attribute-based access control (ABAC) is, how it differs from RBAC, and how to write ABAC rules in Casbin: compare user, resource and environment attributes in the matcher or store conditions as policy. - [What is PBAC? Policy-Based Access Control in Casbin](https://casbin.apache.org/docs/pbac/): What policy-based access control (PBAC) is, how it differs from ABAC and RBAC, and how to store rule expressions as policy in Casbin and evaluate them at runtime with eval(). - [MAC Overview](https://casbin.apache.org/docs/mac-overview/): Mandatory access control (MAC) in Casbin - label-based models such as Bell-LaPadula, Biba and LBAC that users cannot override. - [BLP](https://casbin.apache.org/docs/blp/): Implement the Bell-LaPadula (BLP) confidentiality model in Casbin - security levels for subjects and objects, with no read up and no write down rules. - [Biba Integrity Model: No Read Down, No Write Up](https://casbin.apache.org/docs/biba/): Implement the Biba integrity model in Casbin - integrity levels for subjects and objects, with no read down and no write up rules. - [What is LBAC? Lattice-Based Access Control in Casbin](https://casbin.apache.org/docs/lbac/): What lattice-based access control (LBAC) is, how it combines confidentiality and integrity levels, and how to enforce both in one Casbin model. - [OrBAC](https://casbin.apache.org/docs/orbac/): Implement organisation-based access control (OrBAC) in Casbin - roles, activities and views mapped to concrete users, actions and objects per organization. - [Priority Model](https://casbin.apache.org/docs/priority-model/): Resolve conflicting rules with the Casbin priority model - implicit priority by policy order, explicit priority fields, and role-hierarchy-based priority. - [What is Usage Control (UCON)? Continuous Authorization](https://casbin.apache.org/docs/ucon/): What usage control (UCON) is: authorizations, obligations and conditions checked continuously during use, with mutable attributes, and how to implement it with Casbin. - [Super Administrator in Casbin: Bypass Policy Checks](https://casbin.apache.org/docs/superadmin/): What a super administrator (root) is in Casbin, how to add one to the matcher, and how the same pattern works with RBAC, ABAC and RBAC with domains. ## Storage - [Model Storage](https://casbin.apache.org/docs/model-storage/): Load a Casbin model from a CONF file, from a string or from code. Models define your access control logic and are read-only at runtime. - [Policy Storage](https://casbin.apache.org/docs/policy-storage/): Store Casbin policy rules in a CSV file, a database or any other backend through adapters, and load or save them through the adapter API. - [Loading Policy Subsets](https://casbin.apache.org/docs/policy-subset-loading/): Load only a subset of Casbin policy rules with filtered adapters and LoadFilteredPolicy(), to save memory in large or multi-tenant deployments. ## Use Cases - [Data Permissions](https://casbin.apache.org/docs/data-permissions/): Data-level permissions with Casbin - query implicit roles and permissions through the RBAC hierarchy, and filter data sets with BatchEnforce(). - [Nested Organizations](https://casbin.apache.org/docs/nested-organizations/): Model nested organizations in Casbin - grant a role at a unit and inherit it through the whole subtree with domain paths and a descendant matching function. - [List Filtering](https://casbin.apache.org/docs/list-filtering/): Filter list and search results with Casbin - BatchEnforce, per-unit implicit permissions, a materialized permission table, and Postgres RLS, plus the query-planner gap. - [Menu Permissions](https://casbin.apache.org/docs/menu-permissions/): Menu-based access control with jCasbin and Spring Boot - map roles to menus and submenus and show each user only the menu items they may access. ## Plugins - [Plugin Overview](https://casbin.apache.org/docs/plugins-overview/): Overview of Casbin plugins - adapters, watchers, dispatchers, role managers and middleware that connect Casbin to databases, message buses and web frameworks. - [Enforcers](https://casbin.apache.org/docs/enforcers/): The Enforcer is the main structure in Casbin that acts as an interface for users to perform operations on policy rules and models. - [Adapters](https://casbin.apache.org/docs/adapters/): Casbin adapters load and save policy rules in MySQL, PostgreSQL, MongoDB, Redis, files and dozens of other stores. Find the adapter for your language and database. - [Watchers](https://casbin.apache.org/docs/watchers/): Casbin watchers keep policy in sync across multiple enforcer instances through etcd, Redis, Kafka, NATS and other message buses. - [Dispatchers](https://casbin.apache.org/docs/dispatchers/): Casbin dispatchers propagate incremental policy changes to every enforcer in a cluster using a consistency protocol such as Raft, without changing the Casbin API. - [Role Managers](https://casbin.apache.org/docs/role-managers/): Casbin role managers resolve the RBAC role hierarchy, either from policy in memory or from external sources such as LDAP, Okta, Auth0 and Azure AD. - [Middleware](https://casbin.apache.org/docs/middlewares/): Casbin authorization middleware for web frameworks and API gateways - Gin, Echo, Express, Koa, NestJS, Django, Flask, FastAPI, Spring Boot, Laravel and more. - [Kong Authorization](https://casbin.apache.org/docs/kong-authz/): kong-authz is a Kong API Gateway plugin that authorizes requests with lua-casbin. Install it, configure a model and policy, and protect your Kong routes. - [GraphQL Middleware](https://casbin.apache.org/docs/graphql-middlewares/): Add authorization to GraphQL APIs with Casbin - enforce access on types, fields and operations in resolvers, with middleware for popular GraphQL servers. - [Cloud Native](https://casbin.apache.org/docs/cloud-native/): Use Casbin for authorization in cloud-native stacks: projects that integrate Casbin with Envoy, Istio, Traefik, KubeSphere and other infrastructure. ## API - [API Overview](https://casbin.apache.org/docs/api-overview/): Overview of the main Casbin APIs - Enforce, BatchEnforce, EnforceEx, the Management API and the RBAC API - with examples using an RBAC model and a CSV policy. - [Management API](https://casbin.apache.org/docs/management-api/): Casbin Management API reference - get, add, remove, update and filter policy rules and role assignments at runtime, with examples for each language. - [RBAC API](https://casbin.apache.org/docs/rbac-api/): A more friendly API for RBAC. This API is a subset of Management API. The RBAC users could use this API to simplify the code - [RBAC with Domains API](https://casbin.apache.org/docs/rbac-with-domains-api/): A more user-friendly API for RBAC with domains. This API is a subset of the Management API. RBAC users can use this API to simplify their code. - [RBAC with Conditions API](https://casbin.apache.org/docs/rbac-with-conditions-api/): API reference for Casbin RBAC with conditions - register condition functions on user-role links and pass parameters to them. - [Role Manager API](https://casbin.apache.org/docs/rolemanager-api/): The RoleManager API provides an interface for defining operations to manage roles. The addition of a matching function to the RoleManager allows the use of wildcards in role names and domains. ## Advanced Usage - [Production Deployment](https://casbin.apache.org/docs/production-deployment/): Run Casbin in production - one enforcer per process, thread safety with SyncedEnforcer, decision caching, keeping replicas in sync with watchers, and writing policy inside database transactions. - [Multithreading](https://casbin.apache.org/docs/multi-threading/): Use Casbin safely in multi-threaded code with the synchronized enforcer (SyncedEnforcer) in Go, Java, C++ and other languages. - [Benchmarks](https://casbin.apache.org/docs/benchmark/): Casbin enforcement benchmarks - time and memory per Enforce() call for ACL, RBAC, ABAC, RESTful and other models, from a few rules up to 110,000 policy rules. - [Performance Optimization](https://casbin.apache.org/docs/performance/): Optimize Casbin at scale - handle high request volume with synchronized enforcers and sharding, and reduce memory with filtered policy loading. - [Kubernetes Admission Webhook](https://casbin.apache.org/docs/k8s-gatekeeper/): Casbin K8s-Gatekeeper is a Kubernetes admission webhook that allows or denies operations on any Kubernetes resource using declarative Casbin models and policies. - [Envoy (Service Mesh Authorization)](https://casbin.apache.org/docs/envoy/): Authorize service mesh traffic with Casbin through Envoy external authorization - envoy-authz enforces RBAC and ABAC policies for Envoy and Istio. ## Management - [Admin Portal](https://casbin.apache.org/docs/admin-portal/): Manage Casbin models and policies in a web UI. Casdoor and other admin portals provide model editors, policy editors and permission management on top of Casbin. - [Casbin Service](https://casbin.apache.org/docs/service/): Run Casbin as a remote authorization service over gRPC or HTTP with Casbin Server and other projects, instead of embedding the library. - [Command-line Tools](https://casbin.apache.org/docs/command-line-tools/): Casbin command-line tools for Go, Java, Node.js, Python, .NET and Rust - load a model and policy, run enforce checks and manage policy from your shell. - [Logging & Error Handling](https://casbin.apache.org/docs/log-error/): Enable and customize logging in Casbin for requests, model loading and policy changes, and handle errors returned by the enforcer. - [Frontend Integration](https://casbin.apache.org/docs/frontend/): Casbin.js is a Casbin addon that facilitates your access-control management in the frontend application ## Editors & Tools - [Online Editor](https://casbin.apache.org/docs/online-editor/): Write and test Casbin models and policies in the browser with the online editor - syntax highlighting, completion, AI assistance and instant enforce results. - [IDE Plugins](https://casbin.apache.org/docs/ide-plugins/): Casbin plugins for JetBrains IDEs and Visual Studio Code - syntax highlighting and editing support for model and policy files. ## Comparisons - [Casbin vs. Alternatives](https://casbin.apache.org/docs/comparison/): How Apache Casbin compares with OpenFGA, Open Policy Agent (OPA), CASL, and Cedar - library or service, policy language, access control models, language support, and when to choose each. - [Casbin vs. OpenFGA](https://casbin.apache.org/docs/casbin-vs-openfga/): Apache Casbin and OpenFGA compared - embedded library versus Zanzibar-style service, RBAC and ReBAC modeling, storage, performance characteristics, and when to choose each. - [Casbin vs. Open Policy Agent (OPA)](https://casbin.apache.org/docs/casbin-vs-opa/): Apache Casbin and Open Policy Agent compared - model and policy data versus Rego, embedded library versus policy agent, runtime policy management, language support, and when to choose each. - [Casbin vs. CASL](https://casbin.apache.org/docs/casbin-vs-casl/): Apache Casbin and CASL compared for JavaScript and TypeScript applications - rules as data versus abilities in code, frontend and backend use, multi-language services, and when to choose each. - [Casbin vs. Cedar](https://casbin.apache.org/docs/casbin-vs-cedar/): Apache Casbin and Cedar compared - configurable PERM model versus the Cedar policy language, validation and analysis, language support, policy storage, and when to choose each. ## About & More - [Adopters](https://casbin.apache.org/docs/adopters/): Companies and open-source projects that use Apache Casbin for authorization, either directly in their code or through a plugin or dependency. - [Contributing](https://casbin.apache.org/docs/contributing/): How to contribute to Apache Casbin - core libraries and language ports, adapters, middleware, the website and translations - and how to get started. - [Privacy Policy](https://casbin.apache.org/docs/privacy-policy/): Privacy policy for the Apache Casbin website and sign-in services: what information is collected, how it is used, stored and shared. - [Terms of Service](https://casbin.apache.org/docs/terms-of-service/): Terms of service for using the Apache Casbin website. ## More - [Download](https://casbin.apache.org/docs/download/): Download and verify Apache Casbin releases ## Optional - [Source code](https://github.com/apache/casbin): Go implementation and examples (Apache-2.0) - [Online editor](https://editor.casbin.org): Write and test a model and policy in the browser