Handle an incoming request.

@param \Illuminate\Http\Request $request
@param Closure                  $next
@param string|null              $permission
@return mixed
976063
public function handle($request, Closure $next, $permission = null)
    {
        if (    $permission
            &&  ! $this->core->auth()->admin()
            &&  ! $this->core->auth()->can($permission)
        ) {

            if ($this->core->bootChecker()->isCmsApiRequest()) {
                return $this->core->api()->error('Permission denied', 403);
            }

            if ($request->ajax() || $request->wantsJson()) {
                return response('Permission denied.', 403);
            }

            /** @var CoreInterface $core */
            $core = app(Component::CORE);

            return redirect()->route( $core->prefixRoute(NamedRoute::HOME) );
        }

        return $next($request);
    }
1076884
public function handle($request, Closure $next, $value)
    {
        if (\Gate::denies($value)) {
            app()->abort(403, 'Missing permission \''.$value.'\'');
        }

        return $next($request);
    }
981663
public function handle($request, Closure $next)
    {
        $resource = $request->route()->getActionName();
        $permission = Permission::where('resource', '=', $resource)->first();

        // If the specific route requires permissions
        if ($permission) {
            // Get user permissions
            try {
                $user_permissions = Auth::user()->role->permissions->keyBy('resource');
            } catch (\Exception $e) {
                return abort(401, trans('acl::general.messages.user_permissions_not_found'));
            }

            // And the user has permissions
            if (! $user_permissions->has($resource)) {
                return abort(401, trans('acl::general.messages.no_permissions'));
            }
        }

        return $next($request);
    }
305200
public function handle(Request $request, Closure $next)
    {
        $header = $request->header(self::AUTH_HEADER);
        $apiKey = ApiKey::getByKey($header);

        if ($apiKey instanceof ApiKey) {
            $this->logAccessEvent($request, $apiKey);
            return $next($request);
        }

        return response([
            'errors' => [[
                'message' => 'Unauthorized'
            ]]
        ], 401);
    }
13049
public function handle(Request $request, Closure $next)
    {
        $response = $this->router->routePage($request->route()->parameter('location'));

        if ($response) {
            return $response;
        }

        return $next($request);
    }
1035872
public function handle(Request $request, Closure $next)
    {
        // 1. Check global permission
        $rule = $this->settings->get('permission');

        $response = $this->guard->isPermissionGranted(
            app($rule)->validate()
        );

        if (!$response) {
            auth('admin')->logout();

            return response()
                ->redirectGuest($this->loginUrl)
                ->with('redirect', $request->url());
        }

        if ($this->isResponseObject($response)) {
            return $response;
        }

        if ($this->redirectReceived($response)) {
            return $response->with('redirect', $request->url());
        }

        return $next($request);
    }
989455
public function handle(Request $request, Closure $next)
    {
        $isAuthenticated = $this->authenticate($request);
        $isAuthorized    = $isAuthenticated === true ? $this->authorize($request) : $isAuthenticated;

        return $isAuthorized === true ? $next($request) : $this->getUnauthorizedResponse();
    }
1009960
public function handle($request, Closure $next, string $permission = '')
    {
        if (!$this->getTokenPermissions($request->header('Hc-Token'))->hasTokenPermission($permission))
            return HCLog::error('APP-003', trans ("HCApps::apps_tokens.access_denied"));

        return $next($request);
    }
294154
public function handle($request, Closure $next, ?string $action = null)
    {
        if (! $this->authorize($action)) {
            return $this->responseOnUnauthorized($request);
        }

        return $next($request);
    }
71658
public function handle($request, Closure $next, $permissions, $team = null, $options = '')
    {
        if (!$this->authorization('permissions', $permissions, $team, $options)) {
            return $this->unauthorized();
        }

        return $next($request);
    }
666273
public function handle($request, Closure $next, $permission)
    {
        if (! auth()->user() || ! auth()->user()->can($permission)) {
            if ($request->ajax()) {
                return response()->json([
                    'error' => [
                        'status_code' => 401,
                        'code'        => 'INSUFFICIENT_PERMISSIONS',
                        'description' => 'You are not authorized to access this resource.',
                    ],
                ], 401);
            }

            return abort(401, 'You are not authorized to access this resource.');
        }

        return $next($request);
    }
552989
public function handle($request, Closure $next)
    {

        $request = $this->requestConverter->toCmsRequest($request);

        $request->provideCmsPath(function($request){
            $this->attachCmsPath($request);
        });

        $this->injectRequest($request);

        $this->app['events']->fire($this->requestEventName,[$request, $this]);

        return $next($request);

    }
1359535
public function handle($request, Closure $next)
    {
        if (Config::get('cms.api-token') == $request->get('token')) {
            return $next($request);
        }

        return response('Unauthorized.', 401);
    }
759715
public function handle($request, Closure $next, $requestPermissionCollection)
    {
        $requestPermissions = explode('|', $requestPermissionCollection);

        foreach ($request->user()->roles as $role) {
            foreach ($role->permissions as $permission) {
                $userPermissionCollection[] = $permission;
            }
        }

        foreach ($requestPermissions as $accessPermission) {
            if (in_array($accessPermission, $userPermissionCollection)) {
                return $next($request);
            }
        }

        return response()->view('errors.401', [], 401);
    }
183790
public function handle($request, Closure $next, $permission)
    {
        if (! $user = $request->user()) {
            abort(403, "Access denied!");
        }

        if (! $user->can($permission)) {
            abort(403, "Access denied!");
        }

        return $next($request);
    }
1054986
public function handle($request, Closure $next)
    {
        $this->credentials->getThrottleProvider()->enable();

        return $next($request);
    }
764238
public function handle($request, Closure $next, $permissions)
    {
        $abilities = is_array($permissions) ? $permissions : explode(',', $permissions);

        if (! auth()->check() || ! auth()->user()->canAtLeast($abilities)) {
            abort(403, 'You are not allowed to view this content!');
        }

        return $next($request);
    }