mirror of
https://github.com/yuezk/GlobalProtect-openconnect.git
synced 2025-05-20 07:26:58 -04:00
Code refactor, support multiple gateways and non-SAML authentication (#9)
* Code refactor * Update README.md
This commit is contained in:
97
GPClient/preloginresponse.cpp
Normal file
97
GPClient/preloginresponse.cpp
Normal file
@@ -0,0 +1,97 @@
|
||||
#include "preloginresponse.h"
|
||||
|
||||
#include <QXmlStreamReader>
|
||||
#include <QMap>
|
||||
|
||||
QString PreloginResponse::xmlAuthMessage = "authentication-message";
|
||||
QString PreloginResponse::xmlLabelUsername = "username-label";
|
||||
QString PreloginResponse::xmlLabelPassword = "password-label";
|
||||
QString PreloginResponse::xmlSamlMethod = "saml-auth-method";
|
||||
QString PreloginResponse::xmlSamlRequest = "saml-request";
|
||||
QString PreloginResponse::xmlRegion = "region";
|
||||
|
||||
PreloginResponse::PreloginResponse()
|
||||
{
|
||||
add(xmlAuthMessage, "");
|
||||
add(xmlLabelUsername, "");
|
||||
add(xmlLabelPassword, "");
|
||||
add(xmlSamlMethod, "");
|
||||
add(xmlSamlRequest, "");
|
||||
add(xmlRegion, "");
|
||||
}
|
||||
|
||||
PreloginResponse PreloginResponse::parse(const QByteArray& xml)
|
||||
{
|
||||
QXmlStreamReader xmlReader(xml);
|
||||
PreloginResponse response;
|
||||
response.setRawResponse(xml);
|
||||
|
||||
while (!xmlReader.atEnd()) {
|
||||
xmlReader.readNextStartElement();
|
||||
QString name = xmlReader.name().toString();
|
||||
if (response.has(name)) {
|
||||
response.add(name, xmlReader.readElementText());
|
||||
}
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
const QByteArray& PreloginResponse::rawResponse() const
|
||||
{
|
||||
return _rawResponse;
|
||||
}
|
||||
|
||||
QString PreloginResponse::authMessage() const
|
||||
{
|
||||
return resultMap.value(xmlAuthMessage);
|
||||
}
|
||||
|
||||
QString PreloginResponse::labelUsername() const
|
||||
{
|
||||
return resultMap.value(xmlLabelUsername);
|
||||
}
|
||||
|
||||
QString PreloginResponse::labelPassword() const
|
||||
{
|
||||
return resultMap.value(xmlLabelPassword);
|
||||
}
|
||||
|
||||
QString PreloginResponse::samlMethod() const
|
||||
{
|
||||
return resultMap.value(xmlSamlMethod);
|
||||
}
|
||||
|
||||
QString PreloginResponse::samlRequest() const
|
||||
{
|
||||
return QByteArray::fromBase64(resultMap.value(xmlSamlRequest).toUtf8());
|
||||
}
|
||||
|
||||
QString PreloginResponse::region() const
|
||||
{
|
||||
return resultMap.value(xmlRegion);
|
||||
}
|
||||
|
||||
bool PreloginResponse::hasSamlAuthFields() const
|
||||
{
|
||||
return !samlMethod().isEmpty() && !samlRequest().isEmpty();
|
||||
}
|
||||
|
||||
bool PreloginResponse::hasNormalAuthFields() const
|
||||
{
|
||||
return !labelUsername().isEmpty() && !labelPassword().isEmpty();
|
||||
}
|
||||
|
||||
void PreloginResponse::setRawResponse(const QByteArray &response)
|
||||
{
|
||||
_rawResponse = response;
|
||||
}
|
||||
|
||||
bool PreloginResponse::has(const QString &name) const
|
||||
{
|
||||
return resultMap.contains(name);
|
||||
}
|
||||
|
||||
void PreloginResponse::add(const QString &name, const QString &value)
|
||||
{
|
||||
resultMap.insert(name, value);
|
||||
}
|
Reference in New Issue
Block a user