Skip to content
Permalink
Browse files
Address review, export config string map as DOM element (eases editab…
…ility)
  • Loading branch information
nirvn committed May 13, 2021
1 parent a27c164 commit ad1c94c2274ca86f33bbdfb1dd9091267e898154
@@ -307,6 +307,8 @@ Export authentication configurations to an XML file
:param filename: The file path to save the XML content to
:param authcfgs: The list of configuration IDs to export
:param password: A password string to encrypt the XML content

.. versionadded:: 3.20
%End

bool importAuthenticationConfigsFromXml( const QString &filename, const QString &password = QString() );
@@ -315,6 +317,8 @@ Import authentication configurations from an XML file

:param filename: The file path from which the XML content will be read
:param password: A password string to decrypt the XML content

.. versionadded:: 3.20
%End

bool removeAllAuthenticationConfigs();
@@ -38,6 +38,8 @@ Hide the widget's title, e.g. when embedding
QStringList selectedAuthenticationConfigIds() const;
%Docstring
Returns the list of selected authentication configuration IDs

.. versionadded:: 3.20
%End

public slots:
@@ -15,6 +15,8 @@
***************************************************************************/

#include "qgsauthconfig.h"
#include "qgsauthcertutils.h"
#include "qgsxmlutils.h"

#include <QtCrypto>

@@ -23,8 +25,6 @@
#include <QCryptographicHash>
#include <QUrl>

#include "qgsauthcertutils.h"


//////////////////////////////////////////////
// QgsAuthMethodConfig
@@ -165,7 +165,16 @@ bool QgsAuthMethodConfig::writeXml( QDomElement &parentElement, QDomDocument &do
element.setAttribute( QStringLiteral( "name" ), mName );
element.setAttribute( QStringLiteral( "version" ), QString::number( mVersion ) );
element.setAttribute( QStringLiteral( "uri" ), mUri );
element.setAttribute( QStringLiteral( "config" ), configString() );

QDomElement configElements = document.createElement( QStringLiteral( "Config" ) );
QgsStringMap::const_iterator i = mConfigMap.constBegin();
while ( i != mConfigMap.constEnd() )
{
configElements.setAttribute( i.key(), i.value() );
++i;
}
element.appendChild( configElements );

parentElement.appendChild( element );
return true;
}
@@ -180,7 +189,14 @@ bool QgsAuthMethodConfig::readXml( const QDomElement &element )
mName = element.attribute( QStringLiteral( "name" ) );
mVersion = element.attribute( QStringLiteral( "version" ) ).toInt();
mUri = element.attribute( QStringLiteral( "uri" ) );
loadConfigString( element.attribute( QStringLiteral( "config" ) ) );

clearConfigMap();
QDomNamedNodeMap configAttributes = element.firstChildElement().attributes();
for ( int i = 0; i < configAttributes.length(); i++ )
{
QDomAttr configAttribute = configAttributes.item( i ).toAttr();
setConfig( configAttribute.name(), configAttribute.value() );
}

return true;
}
@@ -1428,8 +1428,6 @@ bool QgsAuthManager::importAuthenticationConfigsFromXml( const QString &filename
{
QgsAuthMethodConfig authMethodConfig;
authMethodConfig.readXml( configuration );
qDebug() << configuration.nodeName();
qDebug() << authMethodConfig.id();
storeAuthenticationConfig( authMethodConfig );

configuration = configuration.nextSiblingElement();
@@ -305,13 +305,15 @@ class CORE_EXPORT QgsAuthManager : public QObject
* \param filename The file path to save the XML content to
* \param authcfgs The list of configuration IDs to export
* \param password A password string to encrypt the XML content
* \since QGIS 3.20
*/
bool exportAuthenticationConfigsToXml( const QString &filename, const QStringList &authcfgs, const QString &password = QString() );

/**
* Import authentication configurations from an XML file
* \param filename The file path from which the XML content will be read
* \param password A password string to decrypt the XML content
* \since QGIS 3.20
*/
bool importAuthenticationConfigsFromXml( const QString &filename, const QString &password = QString() );

@@ -48,7 +48,10 @@ class GUI_EXPORT QgsAuthConfigEditor : public QWidget, private Ui::QgsAuthConfig
//! Hide the widget's title, e.g. when embedding
void toggleTitleVisibility( bool visible );

//! Returns the list of selected authentication configuration IDs
/**
* Returns the list of selected authentication configuration IDs
* \since QGIS 3.20
*/
QStringList selectedAuthenticationConfigIds() const;

public slots:
@@ -60,10 +60,16 @@ class GUI_EXPORT QgsAuthGuiUtils
//! Verify the authentication system is active, else notify user
static bool isDisabled( QgsMessageBar *msgbar );

//! Import authentication configurations from a XML file
/**
* Import authentication configurations from a XML file
* \since QGIS 3.20
*/
static void importAuthenticationConfigs( QgsMessageBar *msgbar );

//! Exports selected authentication configurations to a XML file
/**
* Exports selected authentication configurations to a XML file
* \since QGIS 3.20
*/
static void exportSelectedAuthenticationConfigs( QStringList authenticationConfigIds, QgsMessageBar *msgbar );

//! Sets the cached master password (and verifies it if its hash is in authentication database)

0 comments on commit ad1c94c

Please sign in to comment.