mirror of
https://github.com/yuezk/GlobalProtect-openconnect.git
synced 2025-04-02 18:31:50 -04:00
Improve the authentication workflow (#18)
This commit is contained in:
parent
3a790cdc63
commit
cf34f9f70f
@ -243,6 +243,7 @@ void GPClient::portalLogin()
|
|||||||
connect(portalAuth, &PortalAuthenticator::success, this, &GPClient::onPortalSuccess);
|
connect(portalAuth, &PortalAuthenticator::success, this, &GPClient::onPortalSuccess);
|
||||||
// Prelogin failed on the portal interface, try to treat the portal as a gateway interface
|
// Prelogin failed on the portal interface, try to treat the portal as a gateway interface
|
||||||
connect(portalAuth, &PortalAuthenticator::preloginFailed, this, &GPClient::onPortalPreloginFail);
|
connect(portalAuth, &PortalAuthenticator::preloginFailed, this, &GPClient::onPortalPreloginFail);
|
||||||
|
connect(portalAuth, &PortalAuthenticator::portalConfigFailed, this, &GPClient::onPortalConfigFail);
|
||||||
// Portal login failed
|
// Portal login failed
|
||||||
connect(portalAuth, &PortalAuthenticator::fail, this, &GPClient::onPortalFail);
|
connect(portalAuth, &PortalAuthenticator::fail, this, &GPClient::onPortalFail);
|
||||||
|
|
||||||
@ -251,21 +252,49 @@ void GPClient::portalLogin()
|
|||||||
portalAuth->authenticate();
|
portalAuth->authenticate();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GPClient::onPortalSuccess(const PortalConfigResponse portalConfig, const GPGateway gateway, QList<GPGateway> allGateways)
|
void GPClient::onPortalSuccess(const PortalConfigResponse portalConfig, const QString region)
|
||||||
{
|
{
|
||||||
PLOGI << "Portal authentication succeeded.";
|
PLOGI << "Portal authentication succeeded.";
|
||||||
|
|
||||||
this->portalConfig = portalConfig;
|
// No gateway found in protal configuration
|
||||||
|
if (portalConfig.allGateways().size() == 0) {
|
||||||
|
PLOGI << "No gateway found in portal configuration, treat the portal address as a gateway.";
|
||||||
|
tryGatewayLogin();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
setAllGateways(allGateways);
|
GPGateway gateway = filterPreferredGateway(portalConfig.allGateways(), region);
|
||||||
|
setAllGateways(portalConfig.allGateways());
|
||||||
setCurrentGateway(gateway);
|
setCurrentGateway(gateway);
|
||||||
|
this->portalConfig = portalConfig;
|
||||||
|
|
||||||
gatewayLogin();
|
gatewayLogin();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GPClient::onPortalPreloginFail()
|
void GPClient::onPortalPreloginFail(const QString msg)
|
||||||
{
|
{
|
||||||
PLOGI << "Portal prelogin failed, try to preform login on the the gateway interface...";
|
PLOGI << "Portal prelogin failed: " << msg;
|
||||||
|
tryGatewayLogin();
|
||||||
|
}
|
||||||
|
|
||||||
|
void GPClient::onPortalConfigFail(const QString msg)
|
||||||
|
{
|
||||||
|
PLOGI << "Failed to get the portal configuration, " << msg << " Treat the portal address as gateway.";
|
||||||
|
tryGatewayLogin();
|
||||||
|
}
|
||||||
|
|
||||||
|
void GPClient::onPortalFail(const QString &msg)
|
||||||
|
{
|
||||||
|
if (!msg.isEmpty()) {
|
||||||
|
openMessageBox("Portal authentication failed.", msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
updateConnectionStatus(VpnStatus::disconnected);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GPClient::tryGatewayLogin()
|
||||||
|
{
|
||||||
|
PLOGI << "Try to preform login on the the gateway interface...";
|
||||||
|
|
||||||
// Treat the portal input as the gateway address
|
// Treat the portal input as the gateway address
|
||||||
GPGateway g;
|
GPGateway g;
|
||||||
@ -281,15 +310,6 @@ void GPClient::onPortalPreloginFail()
|
|||||||
gatewayLogin();
|
gatewayLogin();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GPClient::onPortalFail(const QString &msg)
|
|
||||||
{
|
|
||||||
if (!msg.isEmpty()) {
|
|
||||||
openMessageBox("Portal authentication failed.", msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
updateConnectionStatus(VpnStatus::disconnected);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Login to the gateway
|
// Login to the gateway
|
||||||
void GPClient::gatewayLogin()
|
void GPClient::gatewayLogin()
|
||||||
{
|
{
|
||||||
|
@ -30,8 +30,9 @@ private slots:
|
|||||||
void onSystemTrayActivated(QSystemTrayIcon::ActivationReason reason);
|
void onSystemTrayActivated(QSystemTrayIcon::ActivationReason reason);
|
||||||
void onGatewayChanged(QAction *action);
|
void onGatewayChanged(QAction *action);
|
||||||
|
|
||||||
void onPortalSuccess(const PortalConfigResponse portalConfig, const GPGateway gateway, QList<GPGateway> allGateways);
|
void onPortalSuccess(const PortalConfigResponse portalConfig, const QString region);
|
||||||
void onPortalPreloginFail();
|
void onPortalPreloginFail(const QString msg);
|
||||||
|
void onPortalConfigFail(const QString msg);
|
||||||
void onPortalFail(const QString &msg);
|
void onPortalFail(const QString &msg);
|
||||||
|
|
||||||
void onGatewaySuccess(const QString &authCookie);
|
void onGatewaySuccess(const QString &authCookie);
|
||||||
@ -72,6 +73,7 @@ private:
|
|||||||
|
|
||||||
void doConnect();
|
void doConnect();
|
||||||
void portalLogin();
|
void portalLogin();
|
||||||
|
void tryGatewayLogin();
|
||||||
void gatewayLogin();
|
void gatewayLogin();
|
||||||
|
|
||||||
QString portal() const;
|
QString portal() const;
|
||||||
|
@ -57,7 +57,7 @@ void PortalAuthenticator::onPreloginFinished()
|
|||||||
tryAutoLogin();
|
tryAutoLogin();
|
||||||
} else {
|
} else {
|
||||||
PLOGE << QString("Unknown prelogin response for %1 got %2").arg(preloginUrl).arg(QString::fromUtf8(preloginResponse.rawResponse()));
|
PLOGE << QString("Unknown prelogin response for %1 got %2").arg(preloginUrl).arg(QString::fromUtf8(preloginResponse.rawResponse()));
|
||||||
emitFail("Unknown response for portal prelogin interface.");
|
emit preloginFailed("Unknown response for portal prelogin interface.");
|
||||||
}
|
}
|
||||||
|
|
||||||
delete reply;
|
delete reply;
|
||||||
@ -175,7 +175,7 @@ void PortalAuthenticator::onFetchConfigFinished()
|
|||||||
isAutoLogin = false;
|
isAutoLogin = false;
|
||||||
normalAuth();
|
normalAuth();
|
||||||
} else {
|
} else {
|
||||||
emitFail("Failed to fetch the portal config.");
|
emit portalConfigFailed("Failed to fetch the portal config.");
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -197,7 +197,7 @@ void PortalAuthenticator::onFetchConfigFinished()
|
|||||||
normalLoginWindow->close();
|
normalLoginWindow->close();
|
||||||
}
|
}
|
||||||
|
|
||||||
emit success(response, filterPreferredGateway(response.allGateways(), preloginResponse.region()), response.allGateways());
|
emit success(response, preloginResponse.region());
|
||||||
}
|
}
|
||||||
|
|
||||||
void PortalAuthenticator::emitFail(const QString& msg)
|
void PortalAuthenticator::emitFail(const QString& msg)
|
||||||
|
@ -18,9 +18,10 @@ public:
|
|||||||
void authenticate();
|
void authenticate();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void success(const PortalConfigResponse, const GPGateway, QList<GPGateway> allGateways);
|
void success(const PortalConfigResponse response, const QString region);
|
||||||
void fail(const QString& msg);
|
void fail(const QString& msg);
|
||||||
void preloginFailed(const QString& msg);
|
void preloginFailed(const QString& msg);
|
||||||
|
void portalConfigFailed(const QString msg);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onPreloginFinished();
|
void onPreloginFinished();
|
||||||
|
@ -132,7 +132,7 @@ QString PortalConfigResponse::prelogonUserAuthCookie() const
|
|||||||
return _prelogonAuthCookie;
|
return _prelogonAuthCookie;
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<GPGateway> PortalConfigResponse::allGateways()
|
QList<GPGateway> PortalConfigResponse::allGateways() const
|
||||||
{
|
{
|
||||||
return _gateways;
|
return _gateways;
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ public:
|
|||||||
QString password() const;
|
QString password() const;
|
||||||
QString userAuthCookie() const;
|
QString userAuthCookie() const;
|
||||||
QString prelogonUserAuthCookie() const;
|
QString prelogonUserAuthCookie() const;
|
||||||
QList<GPGateway> allGateways();
|
QList<GPGateway> allGateways() const;
|
||||||
void setAllGateways(QList<GPGateway> gateways);
|
void setAllGateways(QList<GPGateway> gateways);
|
||||||
|
|
||||||
void setUsername(const QString username);
|
void setUsername(const QString username);
|
||||||
|
Loading…
Reference in New Issue
Block a user