public function canAccess($permissionKeys, $fullAccessKey, $errorMsg, $defaultUrl, $redirect = false)
    {
        if ($this->getUser()->isGuest) {
            return $this->getUser()->loginRequired();
        }

        if ($this->getPermissionManager()->canAccess($fullAccessKey)) {
            return true;
        }

        if (!is_array($permissionKeys)) {
            $permissionKeys = [$permissionKeys];
        }

        foreach ($permissionKeys as $permissionKey) {
            if ($this->getPermissionManager()->canAccess($permissionKey)) {
                return true;
            }
        }

        if ($redirect) {
            $this->flashError($errorMsg);

            $request = $this->getRequest();
            $referrerUrl = $request->referrer;

            $redirectUrl = ($referrerUrl == $request->url || is_null($referrerUrl)) ?
                $defaultUrl : $referrerUrl;

            $this->redirect($redirectUrl)->send();
            Yii::$app->end(); //this enforces the redirect
        }
        return false;
    }