mirror of
https://github.com/yuezk/GlobalProtect-openconnect.git
synced 2025-04-02 18:31:50 -04:00
Improve code
This commit is contained in:
parent
7f5bf0ce52
commit
e22bb8e1b7
@ -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<QString, QString> &samlResult)
|
||||
|
@ -23,8 +23,9 @@ private slots:
|
||||
void onLoginFinished();
|
||||
void onPreloginFinished();
|
||||
void onPerformNormalLogin(const QString &username, const QString &password);
|
||||
void onSAMLLoginFinished(const QMap<QString, QString> &samlResult);
|
||||
void onLoginWindowRejected();
|
||||
void onLoginWindowFinished();
|
||||
void onSAMLLoginFinished(const QMap<QString, QString> &samlResult);
|
||||
|
||||
private:
|
||||
QString gateway;
|
||||
|
@ -29,7 +29,7 @@ void GPGateway::setPriorityRules(const QMap<QString, int> &priorityRules)
|
||||
_priorityRules = priorityRules;
|
||||
}
|
||||
|
||||
int GPGateway::priorityOf(QString ruleName)
|
||||
int GPGateway::priorityOf(QString ruleName) const
|
||||
{
|
||||
if (_priorityRules.contains(ruleName)) {
|
||||
return _priorityRules.value(ruleName);
|
||||
|
@ -15,7 +15,7 @@ public:
|
||||
void setName(const QString &name);
|
||||
void setAddress(const QString &address);
|
||||
void setPriorityRules(const QMap<QString, int> &priorityRules);
|
||||
int priorityOf(QString ruleName);
|
||||
int priorityOf(QString ruleName) const;
|
||||
|
||||
private:
|
||||
QString _name;
|
||||
|
@ -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<GPGateway> &gateways, QString ruleName)
|
||||
GPGateway gpclient::helper::filterPreferredGateway(QList<GPGateway> *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;
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ namespace gpclient {
|
||||
|
||||
SAMLLoginWindow *samlLogin(QString samlMethod, QString samlRequest, QString preloginUrl);
|
||||
|
||||
GPGateway& filterPreferredGateway(QList<GPGateway> &gateways, QString ruleName);
|
||||
GPGateway filterPreferredGateway(QList<GPGateway> *gateways, const QString ruleName);
|
||||
|
||||
QUrlQuery parseGatewayResponse(const QByteArray& xml);
|
||||
|
||||
|
@ -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()
|
||||
|
@ -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);
|
||||
};
|
||||
|
@ -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()
|
||||
|
@ -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();
|
||||
|
@ -26,6 +26,7 @@ private slots:
|
||||
void onPreloginFinished();
|
||||
void onPerformNormalLogin(const QString &username, const QString &password);
|
||||
void onLoginWindowRejected();
|
||||
void onLoginWindowFinished();
|
||||
void onSAMLLoginSuccess(const QMap<QString, QString> &samlResult);
|
||||
void onFetchConfigFinished();
|
||||
|
||||
|
@ -8,9 +8,15 @@ QString PortalConfigResponse::xmlPrelogonUserAuthCookie = "portal-prelogonuserau
|
||||
QString PortalConfigResponse::xmlGateways = "gateways";
|
||||
|
||||
PortalConfigResponse::PortalConfigResponse()
|
||||
: _gateways(new QList<GPGateway>)
|
||||
{
|
||||
}
|
||||
|
||||
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<GPGateway> PortalConfigResponse::parseGateways(QXmlStreamReader &xmlReader)
|
||||
void PortalConfigResponse::parseGateways(QXmlStreamReader &xmlReader, QList<GPGateway> *gateways)
|
||||
{
|
||||
QList<GPGateway> gateways;
|
||||
|
||||
while (xmlReader.name() != xmlGateways || !xmlReader.isEndElement()) {
|
||||
xmlReader.readNext();
|
||||
// Parse the gateways -> external -> list -> entry
|
||||
@ -62,10 +66,9 @@ QList<GPGateway> PortalConfigResponse::parseGateways(QXmlStreamReader &xmlReader
|
||||
gateway.setAddress(address);
|
||||
gateway.setPriorityRules(parsePriorityRules(xmlReader));
|
||||
gateway.setName(parseGatewayName(xmlReader));
|
||||
gateways.append(gateway);
|
||||
gateways->append(gateway);
|
||||
}
|
||||
}
|
||||
return gateways;
|
||||
}
|
||||
|
||||
QMap<QString, int> PortalConfigResponse::parsePriorityRules(QXmlStreamReader &xmlReader)
|
||||
@ -109,7 +112,7 @@ QString PortalConfigResponse::prelogonUserAuthCookie() const
|
||||
return _prelogonAuthCookie;
|
||||
}
|
||||
|
||||
QList<GPGateway>& PortalConfigResponse::allGateways()
|
||||
QList<GPGateway>* PortalConfigResponse::allGateways()
|
||||
{
|
||||
return _gateways;
|
||||
}
|
||||
@ -138,8 +141,3 @@ void PortalConfigResponse::setPrelogonUserAuthCookie(const QString &cookie)
|
||||
{
|
||||
_prelogonAuthCookie = cookie;
|
||||
}
|
||||
|
||||
void PortalConfigResponse::setGateways(const QList<GPGateway> &gateways)
|
||||
{
|
||||
_gateways = gateways;
|
||||
}
|
||||
|
@ -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<GPGateway>& allGateways();
|
||||
QList<GPGateway>* allGateways();
|
||||
|
||||
void setUsername(const QString& username);
|
||||
void setPassword(const QString& password);
|
||||
@ -35,14 +36,13 @@ private:
|
||||
QString _userAuthCookie;
|
||||
QString _prelogonAuthCookie;
|
||||
|
||||
QList<GPGateway> _gateways;
|
||||
QList<GPGateway> *_gateways;
|
||||
|
||||
void setRawResponse(const QByteArray& response);
|
||||
void setUserAuthCookie(const QString& cookie);
|
||||
void setPrelogonUserAuthCookie(const QString& cookie);
|
||||
void setGateways(const QList<GPGateway>& gateways);
|
||||
|
||||
static QList<GPGateway> parseGateways(QXmlStreamReader &xmlReader);
|
||||
static void parseGateways(QXmlStreamReader &xmlReader, QList<GPGateway> *gateways);
|
||||
static QMap<QString, int> parsePriorityRules(QXmlStreamReader &xmlReader);
|
||||
static QString parseGatewayName(QXmlStreamReader &xmlReader);
|
||||
};
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user