Files
librenms-librenms/app/Providers/AuthServiceProvider.php
T

63 lines
1.7 KiB
PHP
Raw Normal View History

2018-05-09 08:05:17 -05:00
<?php
namespace App\Providers;
2019-06-19 16:01:53 -05:00
use App\Models\DeviceGroup;
2019-04-22 19:01:39 -05:00
use App\Models\User;
2019-06-19 16:01:53 -05:00
use App\Policies\DeviceGroupPolicy;
2019-04-22 19:01:39 -05:00
use App\Policies\UserPolicy;
2018-09-11 07:51:35 -05:00
use App\Guards\ApiTokenGuard;
2018-05-09 08:05:17 -05:00
use Auth;
use Illuminate\Support\Facades\Gate;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
class AuthServiceProvider extends ServiceProvider
{
/**
* The policy mappings for the application.
*
* @var array
*/
protected $policies = [
2019-06-19 16:01:53 -05:00
User::class => UserPolicy::class,
DeviceGroup::class => DeviceGroupPolicy::class,
2018-05-09 08:05:17 -05:00
];
/**
* Register any authentication / authorization services.
*
* @return void
*/
public function boot()
{
$this->registerPolicies();
Auth::provider('legacy', function ($app, array $config) {
return new LegacyUserProvider();
});
2018-09-11 07:51:35 -05:00
Auth::provider('token_provider', function ($app, array $config) {
return new TokenUserProvider();
});
Auth::extend('token_driver', function ($app, $name, array $config) {
$userProvider = $app->make(TokenUserProvider::class);
$request = $app->make('request');
return new ApiTokenGuard($userProvider, $request);
});
Gate::define('global-admin', function ($user) {
return $user->hasGlobalAdmin();
});
Gate::define('admin', function ($user) {
return $user->isAdmin();
});
Gate::define('global-read', function ($user) {
return $user->hasGlobalRead();
});
Gate::define('device', function ($user, $device) {
return $user->canAccessDevice($device);
});
2018-05-09 08:05:17 -05:00
}
}