PHP-Casbin
Github.com/php-casbin/…

The key features of PHP-Casbin include

1. Support custom request format. The default request format is {subject, object, action}.

2. It has two core concepts: Access control model and policy;

3. Support multi-layer role inheritance in RBAC. Not only subjects can have roles, but also resources can have roles;

4. Super users, such as root and Administrator, can access any resources without authorization policies.

5. Supports multiple built-in operators, such as keyMatch, to facilitate the management of path-like resources. For example, /foo/bar can be mapped to /foo*

Php-casbin does not do:

1. Php-casbin is only responsible for access control. There should be other specialized components responsible for authentication and phP-Casbin for access control, which work together.

2. Manage the user list or role list. Php-casbin considers it more appropriate for the project itself to manage the list of users and roles. Php-casbin assumes that all users, roles, and resources present in all policies and requests are valid.

The installation

composer require casbin/casbin
Copy the code

The HelloWorld example

1. Initialize an enforcer with two parameters: model file path and policy file path;

$e = new Enforcer(__DIR__ . '/examples/modelandpolicy/basic_model.conf'.__DIR__ . "/examples/modelandpolicy/basic_policy.csv");
Copy the code

2. Add the following hooks where your code needs access control.

$sub = "alice"; // the user that wants to access a resource.
$obj = "data1"; // the resource that is going to be accessed.
$act = "read"; // the operation that the user performs on the resource.
if ($e->enforce($sub, $obj, $act) === true) {
    // permit alice to read data1x
} else {
    // deny the request, show an error
}
Copy the code

3. Use management apis to manage permissions, for example, to obtain all roles of a user.

$roles = $e->getRoles('alice');
Copy the code

Community development

Php-casbin is currently being pushed out to the community. It already supports integration with Laravel and other Web frameworks through plug-ins, and will be extended to more Web frameworks and communities in the future. Casbin already has Golang, Java, PHP, and Node.js versions. Developers with cross-language needs can use Casbin as a framework to manage permissions for projects in multiple languages.

  • Casbin (Go) : github.com/casbin/casb…
  • JCasbin (Java) : github.com/casbin/jcas…
  • PHP – Casbin (PHP) : github.com/php-casbin/…
  • Node – Casbin (Node. Js) : github.com/casbin/node…

agreement

Php-casbin is distributed under the Apache 2.0 open source license.

Contact the author

Please submit Issues: github.com/php-casbin/…

Or join QQ group: 546057381 (Casbin Access Control discussion group)