php-casbin / laravel-authz

An authorization library that supports access control models like ACL, RBAC, ABAC in Laravel.
Apache License 2.0
272 stars 46 forks source link

how to use rbac with domains model? #56

Closed oknixus closed 1 year ago

oknixus commented 1 year ago

In the configuration file lauthz.php, I change the basic.model.config_file_path to __DIR__ . DIRECTORY_SEPARATOR . 'lauthz-rbac-with-domains-model.conf', and then copy the file example/rbac_with_domains_model.conf to config directory, and rename the file name to authz-rbac-with-domains-model.conf.

But the next step is ?

I got the error grouping policy elements do not meet role definition when I use the Enforcer::addRoleForUserInDomain('alice', 'admin', 'article');.

So how to use rbac with domains model ?

hsluoyz commented 1 year ago

@leeqvip

leeqvip commented 1 year ago

I did what you said, and everything is as expected, and there is an extra policy in the database.

1   g   alice   admin   article             2023-03-19 15:35:56 2023-03-19 15:35:56

Did not encounter the problem you mentioned. Can you insist that the content of your conf file is correct and effective (restart the service)?

leeqvip commented 1 year ago

@oknixus Is there any historical data left over from other models in your database? An error will occur if there is data loaded that does not conform to the current model.

oknixus commented 1 year ago

Yes, u r right. I think my problem was caused by my old rules. The old rules was lauthz-rbac-model.conf.