-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Add wildcard permissions #1381
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add wildcard permissions #1381
Conversation
ba9284d
to
6063707
Compare
@stefanriehl This looks great. Question: all the wildcard lookup logic is agnostic of the user's current guard. Is that intentional? |
Good point. You're right. Will change. |
@drbyte To be honest, I am not yet completely satisfied with the implementation. Why? Well, let me show an example: public function it_can_verify_permission_instances_not_assigned_to_user()
{
$userPermission = Permission::create(['name' => 'posts.*']);
$permission = Permission::create(['name' => 'posts.create']);
$user->givePermissionTo([$userPermission]);
// all these asserts should be true, but are currently false
$this->assertTrue($user->hasPermissionTo('posts.create'));
// because permission exists in db and wildcard permission won't be called
$this->assertTrue($user->hasPermissionTo($permission));
$this->assertTrue($user->hasPermissionTo($permission->id));
// because we can only handle strings right now
} That doesn't seem logical to me! So, I would like to change the implementation:
I already did the implementation with more tests, but I would like to get your thoughts before updating. |
Makes sense. I haven't seen your proposed new approach, but perhaps it makes sense to just be binary about it: either the wildcard switch is on and that's the only matching that's used, or it's off and it defaults to the prior matching logic. |
That's what I did. I will push tomorrow. Thanks! |
@stefanriehl I do like this improvement. Feels more intuitive that the switch is all-or-nothing, not hybrid. Thoughts about performance? caching needs? |
Well, I did some performance tests. Wildcard permissions vs. DB permissions:
Wildcard permission check is ~ 2.2x slower than DB permission. With the restriction that probably the permission to be checked is not the last one in the permission list. In a real scenario the wildcard query surely would be faster. Interesting: the more permissions a user has, the lower the factor. @drbyte What do you think? Is it necessary to consider caching for wildcard permissions? In my opinion caching would only make sense, if we'll cache the positive/negative checked permissions for a user. But this implementation is more complex I think. |
I agree: it's probably suitable to revisit caching requirements for this feature after feedback from use-in-the-wild, where specific use-cases can be cited, so we fix actual problems instead of over-engineering something that just takes more effort to support and maintain. |
I'm satisfied that the public signature of these changes is minimal. Are you satisfied with the completeness of this? Ready for merge? |
@drbyte Yes I'm fine. I'll just correct the spelling mistake. |
Thanks! |
Allows using wildcard permissions based on the default wildcard permission implementation of Apache Shiro.
Enable wildcard permissions in the config file:
When enabled, wildcard permissions offers you a flexible representation for a variety of permission schemes.
Some examples:
See full documentation at
// docs/basic-usage/wildcard-permissions.md