diff --git a/GPClient/gatewayauthenticator.cpp b/GPClient/gatewayauthenticator.cpp index eb55b6f..16b51e8 100644 --- a/GPClient/gatewayauthenticator.cpp +++ b/GPClient/gatewayauthenticator.cpp @@ -111,10 +111,9 @@ void GatewayAuthenticator::normalAuth(QString labelUsername, QString labelPasswo // Do login connect(normalLoginWindow, &NormalLoginWindow::performLogin, this, &GatewayAuthenticator::onPerformNormalLogin); connect(normalLoginWindow, &NormalLoginWindow::rejected, this, &GatewayAuthenticator::onLoginWindowRejected); + connect(normalLoginWindow, &NormalLoginWindow::finished, this, &GatewayAuthenticator::onLoginWindowFinished); - normalLoginWindow->exec(); - delete normalLoginWindow; - normalLoginWindow = nullptr; + normalLoginWindow->show(); } void GatewayAuthenticator::onPerformNormalLogin(const QString &username, const QString &password) @@ -131,6 +130,12 @@ void GatewayAuthenticator::onLoginWindowRejected() emit fail(); } +void GatewayAuthenticator::onLoginWindowFinished() +{ + delete normalLoginWindow; + normalLoginWindow = nullptr; +} + void GatewayAuthenticator::samlAuth(QString samlMethod, QString samlRequest, QString preloginUrl) { PLOGI << "Trying to perform SAML login with saml-method " << samlMethod; @@ -144,8 +149,6 @@ void GatewayAuthenticator::samlAuth(QString samlMethod, QString samlRequest, QSt connect(loginWindow, &SAMLLoginWindow::success, this, &GatewayAuthenticator::onSAMLLoginFinished); connect(loginWindow, &SAMLLoginWindow::rejected, this, &GatewayAuthenticator::onLoginWindowRejected); -// loginWindow->exec(); -// delete loginWindow; } void GatewayAuthenticator::onSAMLLoginFinished(const QMap &samlResult) diff --git a/GPClient/gatewayauthenticator.h b/GPClient/gatewayauthenticator.h index 89b6499..5407803 100644 --- a/GPClient/gatewayauthenticator.h +++ b/GPClient/gatewayauthenticator.h @@ -23,8 +23,9 @@ private slots: void onLoginFinished(); void onPreloginFinished(); void onPerformNormalLogin(const QString &username, const QString &password); - void onSAMLLoginFinished(const QMap &samlResult); void onLoginWindowRejected(); + void onLoginWindowFinished(); + void onSAMLLoginFinished(const QMap &samlResult); private: QString gateway; diff --git a/GPClient/gpgateway.cpp b/GPClient/gpgateway.cpp index d3e539b..f150fca 100644 --- a/GPClient/gpgateway.cpp +++ b/GPClient/gpgateway.cpp @@ -29,7 +29,7 @@ void GPGateway::setPriorityRules(const QMap &priorityRules) _priorityRules = priorityRules; } -int GPGateway::priorityOf(QString ruleName) +int GPGateway::priorityOf(QString ruleName) const { if (_priorityRules.contains(ruleName)) { return _priorityRules.value(ruleName); diff --git a/GPClient/gpgateway.h b/GPClient/gpgateway.h index 129fe41..af0564b 100644 --- a/GPClient/gpgateway.h +++ b/GPClient/gpgateway.h @@ -15,7 +15,7 @@ public: void setName(const QString &name); void setAddress(const QString &address); void setPriorityRules(const QMap &priorityRules); - int priorityOf(QString ruleName); + int priorityOf(QString ruleName) const; private: QString _name; diff --git a/GPClient/gphelper.cpp b/GPClient/gphelper.cpp index ca2b8b3..f9b74d2 100644 --- a/GPClient/gphelper.cpp +++ b/GPClient/gphelper.cpp @@ -33,14 +33,15 @@ SAMLLoginWindow* gpclient::helper::samlLogin(QString samlMethod, QString samlReq PLOGE << "Unknown saml-auth-method expected POST or REDIRECT, got " << samlMethod; return nullptr; } + return loginWindow; } -GPGateway &gpclient::helper::filterPreferredGateway(QList &gateways, QString ruleName) +GPGateway gpclient::helper::filterPreferredGateway(QList *gateways, const QString ruleName) { - GPGateway& gateway = gateways.first(); + GPGateway gateway = gateways->first(); - for (GPGateway& g : gateways) { + for (GPGateway g : *gateways) { if (g.priorityOf(ruleName) > gateway.priorityOf(ruleName)) { gateway = g; } diff --git a/GPClient/gphelper.h b/GPClient/gphelper.h index 5dce246..dfc8b2e 100644 --- a/GPClient/gphelper.h +++ b/GPClient/gphelper.h @@ -22,7 +22,7 @@ namespace gpclient { SAMLLoginWindow *samlLogin(QString samlMethod, QString samlRequest, QString preloginUrl); - GPGateway& filterPreferredGateway(QList &gateways, QString ruleName); + GPGateway filterPreferredGateway(QList *gateways, const QString ruleName); QUrlQuery parseGatewayResponse(const QByteArray& xml); diff --git a/GPClient/loginparams.cpp b/GPClient/loginparams.cpp index 0a0ea61..45b72aa 100644 --- a/GPClient/loginparams.cpp +++ b/GPClient/loginparams.cpp @@ -4,6 +4,22 @@ LoginParams::LoginParams() { + params.addQueryItem("prot", QUrl::toPercentEncoding("https:")); + params.addQueryItem("server", ""); + params.addQueryItem("inputSrc", ""); + params.addQueryItem("jnlpReady", "jnlpReady"); + params.addQueryItem("user", ""); + params.addQueryItem("passwd", ""); + params.addQueryItem("computer", QUrl::toPercentEncoding(QSysInfo::machineHostName())); + params.addQueryItem("ok", "Login"); + params.addQueryItem("direct", "yes"); + params.addQueryItem("clientVer", "4100"); + params.addQueryItem("os-version", QUrl::toPercentEncoding(QSysInfo::prettyProductName())); + params.addQueryItem("clientos", "Linux"); + params.addQueryItem("portal-userauthcookie", ""); + params.addQueryItem("portal-prelogonuserauthcookie", ""); + params.addQueryItem("prelogin-cookie", ""); + params.addQueryItem("ipv6-support", "yes"); } LoginParams::~LoginParams() diff --git a/GPClient/loginparams.h b/GPClient/loginparams.h index c14bc6d..c5583f6 100644 --- a/GPClient/loginparams.h +++ b/GPClient/loginparams.h @@ -19,24 +19,7 @@ public: QByteArray toUtf8() const; private: - QUrlQuery params { - {"prot", QUrl::toPercentEncoding("https:")}, - {"server", ""}, - {"inputSrc", ""}, - {"jnlpReady", "jnlpReady"}, - {"user", ""}, - {"passwd", ""}, - {"computer", QUrl::toPercentEncoding(QSysInfo::machineHostName())}, - {"ok", "Login"}, - {"direct", "yes"}, - {"clientVer", "4100"}, - {"os-version", QUrl::toPercentEncoding(QSysInfo::prettyProductName())}, - {"clientos", "Linux"}, - {"portal-userauthcookie", ""}, - {"portal-prelogonuserauthcookie", ""}, - {"prelogin-cookie", ""}, - {"ipv6-support", "yes"} - }; + QUrlQuery params; void updateQueryItem(const QString &key, const QString &value); }; diff --git a/GPClient/normalloginwindow.cpp b/GPClient/normalloginwindow.cpp index 44dde14..a712bee 100644 --- a/GPClient/normalloginwindow.cpp +++ b/GPClient/normalloginwindow.cpp @@ -8,7 +8,9 @@ NormalLoginWindow::NormalLoginWindow(QWidget *parent) : ui(new Ui::NormalLoginWindow) { ui->setupUi(this); + setWindowTitle("GlobalProtect Login"); setFixedSize(width(), height()); + setModal(true); } NormalLoginWindow::~NormalLoginWindow() diff --git a/GPClient/portalauthenticator.cpp b/GPClient/portalauthenticator.cpp index 786490e..452cb33 100644 --- a/GPClient/portalauthenticator.cpp +++ b/GPClient/portalauthenticator.cpp @@ -24,7 +24,6 @@ PortalAuthenticator::~PortalAuthenticator() delete normalLoginWindow; } - void PortalAuthenticator::authenticate() { PLOGI << "Preform portal prelogin at " << preloginUrl; @@ -88,10 +87,9 @@ void PortalAuthenticator::normalAuth() // Do login connect(normalLoginWindow, &NormalLoginWindow::performLogin, this, &PortalAuthenticator::onPerformNormalLogin); connect(normalLoginWindow, &NormalLoginWindow::rejected, this, &PortalAuthenticator::onLoginWindowRejected); + connect(normalLoginWindow, &NormalLoginWindow::finished, this, &PortalAuthenticator::onLoginWindowFinished); - normalLoginWindow->exec(); - delete normalLoginWindow; - normalLoginWindow = nullptr; + normalLoginWindow->show(); } void PortalAuthenticator::onPerformNormalLogin(const QString &username, const QString &password) @@ -105,6 +103,12 @@ void PortalAuthenticator::onLoginWindowRejected() emitFail(); } +void PortalAuthenticator::onLoginWindowFinished() +{ + delete normalLoginWindow; + normalLoginWindow = nullptr; +} + void PortalAuthenticator::samlAuth() { PLOGI << "Trying to perform SAML login with saml-method " << preloginResponse.samlMethod(); diff --git a/GPClient/portalauthenticator.h b/GPClient/portalauthenticator.h index aaf8b39..4f3b12f 100644 --- a/GPClient/portalauthenticator.h +++ b/GPClient/portalauthenticator.h @@ -26,6 +26,7 @@ private slots: void onPreloginFinished(); void onPerformNormalLogin(const QString &username, const QString &password); void onLoginWindowRejected(); + void onLoginWindowFinished(); void onSAMLLoginSuccess(const QMap &samlResult); void onFetchConfigFinished(); diff --git a/GPClient/portalconfigresponse.cpp b/GPClient/portalconfigresponse.cpp index 6b57f1c..1bf4a2d 100644 --- a/GPClient/portalconfigresponse.cpp +++ b/GPClient/portalconfigresponse.cpp @@ -8,9 +8,15 @@ QString PortalConfigResponse::xmlPrelogonUserAuthCookie = "portal-prelogonuserau QString PortalConfigResponse::xmlGateways = "gateways"; PortalConfigResponse::PortalConfigResponse() + : _gateways(new QList) { } +PortalConfigResponse::~PortalConfigResponse() +{ + delete _gateways; +} + PortalConfigResponse PortalConfigResponse::parse(const QByteArray& xml) { QXmlStreamReader xmlReader(xml); @@ -27,7 +33,7 @@ PortalConfigResponse PortalConfigResponse::parse(const QByteArray& xml) } else if (name == xmlPrelogonUserAuthCookie) { response.setPrelogonUserAuthCookie(xmlReader.readElementText()); } else if (name == xmlGateways) { - response.setGateways(parseGateways(xmlReader)); + parseGateways(xmlReader, response.allGateways()); } } @@ -49,10 +55,8 @@ QString PortalConfigResponse::password() const return _password; } -QList PortalConfigResponse::parseGateways(QXmlStreamReader &xmlReader) +void PortalConfigResponse::parseGateways(QXmlStreamReader &xmlReader, QList *gateways) { - QList gateways; - while (xmlReader.name() != xmlGateways || !xmlReader.isEndElement()) { xmlReader.readNext(); // Parse the gateways -> external -> list -> entry @@ -62,10 +66,9 @@ QList PortalConfigResponse::parseGateways(QXmlStreamReader &xmlReader gateway.setAddress(address); gateway.setPriorityRules(parsePriorityRules(xmlReader)); gateway.setName(parseGatewayName(xmlReader)); - gateways.append(gateway); + gateways->append(gateway); } } - return gateways; } QMap PortalConfigResponse::parsePriorityRules(QXmlStreamReader &xmlReader) @@ -109,7 +112,7 @@ QString PortalConfigResponse::prelogonUserAuthCookie() const return _prelogonAuthCookie; } -QList& PortalConfigResponse::allGateways() +QList* PortalConfigResponse::allGateways() { return _gateways; } @@ -138,8 +141,3 @@ void PortalConfigResponse::setPrelogonUserAuthCookie(const QString &cookie) { _prelogonAuthCookie = cookie; } - -void PortalConfigResponse::setGateways(const QList &gateways) -{ - _gateways = gateways; -} diff --git a/GPClient/portalconfigresponse.h b/GPClient/portalconfigresponse.h index aa5b73b..ac5dd6c 100644 --- a/GPClient/portalconfigresponse.h +++ b/GPClient/portalconfigresponse.h @@ -11,6 +11,7 @@ class PortalConfigResponse { public: PortalConfigResponse(); + ~PortalConfigResponse(); static PortalConfigResponse parse(const QByteArray& xml); @@ -19,7 +20,7 @@ public: QString password() const; QString userAuthCookie() const; QString prelogonUserAuthCookie() const; - QList& allGateways(); + QList* allGateways(); void setUsername(const QString& username); void setPassword(const QString& password); @@ -35,14 +36,13 @@ private: QString _userAuthCookie; QString _prelogonAuthCookie; - QList _gateways; + QList *_gateways; void setRawResponse(const QByteArray& response); void setUserAuthCookie(const QString& cookie); void setPrelogonUserAuthCookie(const QString& cookie); - void setGateways(const QList& gateways); - static QList parseGateways(QXmlStreamReader &xmlReader); + static void parseGateways(QXmlStreamReader &xmlReader, QList *gateways); static QMap parsePriorityRules(QXmlStreamReader &xmlReader); static QString parseGatewayName(QXmlStreamReader &xmlReader); }; diff --git a/GPClient/samlloginwindow.cpp b/GPClient/samlloginwindow.cpp index 7a16c9d..97f9c98 100644 --- a/GPClient/samlloginwindow.cpp +++ b/GPClient/samlloginwindow.cpp @@ -8,6 +8,7 @@ SAMLLoginWindow::SAMLLoginWindow(QWidget *parent) : QDialog(parent) { setWindowTitle("GlobalProtect SAML Login"); + setModal(true); resize(700, 550); QVBoxLayout *verticalLayout = new QVBoxLayout(this); @@ -70,6 +71,6 @@ void SAMLLoginWindow::onLoadFinished() emit success(samlResult); accept(); } else { - open(); + this->show(); } }