Skip to main content

Overview

Casbin is a powerful and efficient open-source access control library that supports various access control models for enforcing authorization across the board.

Enforcing a set of rules is as simple as listing subjects, objects and the desired allowed action (or any other format per your needs) in a policy file. This is synonymous across all flows Casbin is used in. The developer/administrator has complete control over the layout, execution and conditions for authorization which is set via the model file. Casbin provides an Enforcer for validating an incoming request based on the policy and model files given to the Enforcer.

What is Casbin?​

Casbin is an authorization library which can be used in flows where we want a certain object or entity to be accessed by a specific user or subject. The type of access (or action) can be read, write, delete or any other action as set by the developer. This method of using Casbin is most widely applied and is referred to as the "standard" or classic { subject, object, action } flow.

Casbin is capable of handling many complex authorization scenarios other than the standard flow. There can be addition of roles (RBAC), attributes (ABAC) etc.

What Casbin does:​

  • Enforces the policy in the classic { subject, object, action } or customized form as you defined, supporting both allow and deny authorizations.

  • Handles the storage of the access control model and its policy.

  • Manages the role-user mappings and role-role mappings (also known as role hierarchy in RBAC).

  • Supports built-in superusers like root or administrator. A superuser can do anything without explicit permission.

  • Allocates multiple built-in operators to support the rule matching. For example, keyMatch can map a resource key /foo/bar to the pattern /foo*.

What Casbin does NOT do:​

  • Authentication (verify username and password when a user logs in)
  • Manage the list of users or roles.

It is more convenient for the project to manage it's list of users, roles or passwords. Users usually have their passwords and Casbin is not designed as a password container. However, Casbin stores the user-role mapping for the RBAC scenario.

Languages supported by Casbin:​

Casbin provides support for various programming languages, ready to be integrated within any project and workflow:

golangjavanodejsphp
CasbinjCasbinnode-CasbinPHP-Casbin
production-readyproduction-readyproduction-readyproduction-ready
pythondotnetc++rust
PyCasbinCasbin.NETCasbin-CPPCasbin-RS
production-readyproduction-readyproduction-readyproduction-ready

Feature set for different languages​

We are constantly working to make Casbin have the same features for all languages. However, presently, the following features exist in the respective languages.

FeatureGoJavaNode.jsPHPPythonC#DelphiRustC++LuaDartElixir
Enforcementβœ…βœ…βœ…βœ…βœ…βœ…βœ…βœ…βœ…βœ…βœ…βœ…
RBACβœ…βœ…βœ…βœ…βœ…βœ…βœ…βœ…βœ…βœ…βœ…βœ…
ABACβœ…βœ…βœ…βœ…βœ…βœ…βœ…βœ…βœ…βœ…βœ…βœ…
Scaling ABAC (eval())βœ…βœ…βœ…βœ…βœ…βœ…βŒβœ…βœ…βœ…βœ…βœ…
Adapterβœ…βœ…βœ…βœ…βœ…βœ…βœ…βœ…βœ…βœ…βœ…βŒ
Management APIβœ…βœ…βœ…βœ…βœ…βœ…βœ…βœ…βœ…βœ…βœ…βœ…
RBAC APIβœ…βœ…βœ…βœ…βœ…βœ…βœ…βœ…βœ…βœ…βœ…βœ…
Batch APIβœ…βœ…βœ…βœ…βœ…βœ…βŒβœ…βœ…βœ…βŒβŒ
Filtered Adapterβœ…βœ…βœ…βœ…βœ…βœ…βŒβœ…βœ…βœ…βŒβŒ
Watcherβœ…βœ…βœ…βœ…βœ…βœ…βœ…βœ…βœ…βœ…βŒβŒ
Role Managerβœ…βœ…βœ…βœ…βœ…βœ…βŒβœ…βœ…βœ…βœ…βŒ
Multi-Threadingβœ…βœ…βœ…βŒβœ…βŒβŒβœ…βŒβŒβŒβŒ
'in' of matcherβœ…βœ…βœ…βœ…βœ…βŒβœ…βŒβŒβŒβœ…βœ…

βœ… for Watcher or Role Manager only means having the interface in the core library. It is not indicative of whether there is a watcher or role manager implementation available.