2018-05-09 08:05:17 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Providers;
|
|
|
|
|
2018-09-11 07:51:35 -05:00
|
|
|
use App\Guards\ApiTokenGuard;
|
2018-05-09 08:05:17 -05:00
|
|
|
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
|
2021-03-31 21:30:04 +02:00
|
|
|
use Illuminate\Support\Facades\Auth;
|
2018-05-09 08:05:17 -05:00
|
|
|
use Illuminate\Support\Facades\Gate;
|
|
|
|
|
|
|
|
class AuthServiceProvider extends ServiceProvider
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* The policy mappings for the application.
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $policies = [
|
2020-04-29 07:25:13 -05:00
|
|
|
\App\Models\User::class => \App\Policies\UserPolicy::class,
|
2022-05-31 08:08:40 -05:00
|
|
|
\App\Models\Dashboard::class => \App\Policies\DashboardPolicy::class,
|
2020-04-29 07:25:13 -05:00
|
|
|
\App\Models\Device::class => \App\Policies\DevicePolicy::class,
|
|
|
|
\App\Models\DeviceGroup::class => \App\Policies\DeviceGroupPolicy::class,
|
2020-06-08 08:27:03 -05:00
|
|
|
\App\Models\PollerCluster::class => \App\Policies\PollerClusterPolicy::class,
|
2020-05-06 09:12:33 -05:00
|
|
|
\App\Models\Port::class => \App\Policies\PortPolicy::class,
|
2021-02-02 06:40:11 +00:00
|
|
|
\App\Models\ServiceTemplate::class => \App\Policies\ServiceTemplatePolicy::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');
|
2020-09-21 14:54:51 +02:00
|
|
|
|
2018-09-11 07:51:35 -05:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|