Comments (4)
from php-casbin.
@ewaldkleefstra
Use pattern matching in RBAC: https://casbin.org/docs/en/rbac#use-pattern-matching-in-rbac
from php-casbin.
This is a complete example :
use Casbin\Enforcer;
use Casbin\Util\BuiltinOperations;
use \Casbin\Model\Model;
$model = Model::newModelFromString(<<<EOT
[request_definition]
r = sub, dom, obj, act
[policy_definition]
p = sub, dom, obj, act
[role_definition]
g = _, _, _
[policy_effect]
e = some(where (p.eft == allow))
[matchers]
m = g(r.sub, p.sub, r.dom) && keyMatch2(r.dom, p.dom) && keyMatch2(r.obj, p.obj) && keyMatch2(r.act, p.act)
EOT);
$enforcer = new Enforcer($model);
$rm = new Casbin\Rbac\DefaultRoleManager\RoleManager(10);
$rm->addDomainMatchingFunc("keyMatch2", function (...$args) {
return BuiltinOperations::keyMatch2Func(...$args);
});
$enforcer->setRoleManager($rm);
$enforcer->addPolicy("role", "*", "*", "action");
$enforcer->addGroupingPolicy("username", "role", "*");
$enforcer->enforce("username", "domain", "object", "action"); // true
from php-casbin.
That did the trick! Thanks a lot.
from php-casbin.
Related Issues (20)
- support Priority Explicitly or subjectPriority HOT 1
- Database Adapter class not updated with new updateFilteredPolicies HOT 3
- The result after packaging is not as expected HOT 3
- Issue in ManagementEnforcer : getAllSubject/Object... has field indexes hard coded HOT 3
- array_combine(): Both parameters should have an equal number of elements HOT 13
- DeleteUser() removes roles but leaves permissions HOT 4
- [Feature] Add cache for g function HOT 3
- Could change addPermissionsForUser function declaration HOT 3
- May be should cast $name1 and $name2 to string before call hasLink function in generateGFunction. HOT 1
- Cannot use multiple policy rule HOT 2
- I got wrong match result from RBAC model HOT 11
- globMatch raises error HOT 1
- PHP Depreciated for php v8.2.0 : $this->enabled HOT 1
- composer is fetching v0.1.1 HOT 9
- Regression after RoleManager rewrite HOT 1
- RBAC with domain and domain pattern returns invalid results HOT 3
- ErrorException when some user belong no role in subjectPriority mode HOT 1
- Multiple request, policy, effect, matcher type support HOT 2
- Implement keyGet() and keyGet2() built-in method HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from php-casbin.