Home > Backend Development > PHP Tutorial > ABAC permission control based on PHP-Casbin

ABAC permission control based on PHP-Casbin

藏色散人
Release: 2023-04-07 12:12:01
forward
4319 people have browsed it

PHP-Casbin is a powerful and efficient open source access control framework that supports permission management based on various access control models (RBAC ABAC ACL).

ABAC is attribute-based access control, which can use the attributes of the subject, object, or action to control access instead of the string itself.

Recommended: "PHP Tutorial"

The official example of ABAC is as follows:

[request_definition]
r = sub, obj, act
[policy_definition]
p = sub, obj, act
[policy_effect]
e = some(where (p.eft == allow))
[matchers]
m = r.sub == r.obj.owner
Copy after login

This is the definition of the r.obj class:

$data1 = new \stdClass();
$data1->name = 'data1';
$data1->owner = 'alice';
$data2 = new \stdClass();
$data2->name = 'data2';
$data2->owner = 'bob';
Copy after login

Then use the decider to make decisions:

$e->enforce('alice', $data1, 'read');  // true
$e->enforce('alice', $data2, 'read');  // false
$e->enforce('bob', $data1, 'read');  // false
$e->enforce('bob', $data2, 'read');  // true
Copy after login

The above is the detailed content of ABAC permission control based on PHP-Casbin. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template