-
Notifications
You must be signed in to change notification settings - Fork 0
Working with roles and permissions
The whole auth and security implementation is done with the help of Laravel's authorization package. The persistence layer is written by ourselves. On top of this Vain provides another ServiceProvider (AuthServiceProvider
) inside the user module which registers all stored roles and permissions for you, to make working with auth and security as convenient as possible.
If your module should provide its own permissions in the application permissions pool it has to register a new config file with only an array of the permission keys. Also, be sure to document it well. Here is an example taken out of the user´s permission.php
config file:
<?php
return [
/*
|--------------------------------------------------------------------------
| User Permissions
|--------------------------------------------------------------------------
|
| These permissions handle the access to the user resources. These are
| generally considered static, so if you change them you can not expect
| the app to work properly.
|
*/
'user.users.show',
'user.users.edit',
'user.users.destroy',
...
The registration of the config file can normally be done within a ServiceProvider. This code was taken from the ConfigServiceProvider
of the user module. The config file itself has to be merged into the permission
namespace like so:
public function register()
{
$this->mergeConfigFrom(
__DIR__.'/../Config/permission.php', 'permission'
);
...
NOTE: For more information about naming conventions, see the naming conventions article in this wiki.
Grab a user object in any possibility which suits your current context best. You can follow the sentinel docu step by step as written here to check permissions and check roles.
Any problems? Try our Troubleshooting page!