Skip to content
Permalink
Browse files
[authentication manager] Allow configurations to be overwritten when …
…importing
  • Loading branch information
nirvn committed May 15, 2021
1 parent 8abb178 commit 8513b8051f3abcf6202674f0e7d8f83e586a5fcd
@@ -262,11 +262,12 @@ Returns the regular expression for authcfg=.{7} key/value token for authenticati
Gets list of authentication ids from database
%End

bool storeAuthenticationConfig( QgsAuthMethodConfig &mconfig /In,Out/ );
bool storeAuthenticationConfig( QgsAuthMethodConfig &mconfig /In,Out/, bool overwrite = false );
%Docstring
Store an authentication config in the database

:param mconfig: Associated authentication config id
:param overwrite: If set to ``True``, pre-existing authentication configurations will be overwritten

:return: Whether operation succeeded
%End
@@ -311,12 +312,13 @@ Export authentication configurations to an XML file
.. versionadded:: 3.20
%End

bool importAuthenticationConfigsFromXml( const QString &filename, const QString &password = QString() );
bool importAuthenticationConfigsFromXml( const QString &filename, const QString &password = QString(), bool overwrite = false );
%Docstring
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
:param overwrite: If set to ``True``, pre-existing authentication configurations will be overwritten

.. versionadded:: 3.20
%End
@@ -1076,7 +1076,7 @@ QgsAuthMethod::Expansions QgsAuthManager::supportedAuthMethodExpansions( const Q
return QgsAuthMethod::Expansions();
}

bool QgsAuthManager::storeAuthenticationConfig( QgsAuthMethodConfig &mconfig )
bool QgsAuthManager::storeAuthenticationConfig( QgsAuthMethodConfig &mconfig, bool overwrite )
{
QMutexLocker locker( mMutex.get() );
if ( !setMasterPassword( true ) )
@@ -1099,10 +1099,16 @@ bool QgsAuthManager::storeAuthenticationConfig( QgsAuthMethodConfig &mconfig )
}
else if ( configIds().contains( uid ) )
{
const char *err = QT_TR_NOOP( "Store config: FAILED because pre-defined config ID is not unique" );
QgsDebugMsg( err );
emit messageOut( tr( err ), authManTag(), WARNING );
return false;
if ( !overwrite )
{
const char *err = QT_TR_NOOP( "Store config: FAILED because pre-defined config ID %1 is not unique" );
QgsDebugMsg( err );
emit messageOut( tr( err ), authManTag(), WARNING );
return false;
}
locker.unlock();
removeAuthenticationConfig( uid );
locker.relock();
}

QString configstring = mconfig.configString();
@@ -1142,15 +1148,14 @@ bool QgsAuthManager::storeAuthenticationConfig( QgsAuthMethodConfig &mconfig )
if ( !authDbCommit() )
return false;

// passed-in config should now be like as if it was just loaded from db
// passed-in config should now be like as if it was just loaded from db
if ( !passedinID )
mconfig.setId( uid );

updateConfigAuthMethods();

QgsDebugMsgLevel( QStringLiteral( "Store config SUCCESS for authcfg: %1" ).arg( uid ), 2 );
return true;

}

bool QgsAuthManager::updateAuthenticationConfig( const QgsAuthMethodConfig &config )
@@ -1384,7 +1389,7 @@ bool QgsAuthManager::exportAuthenticationConfigsToXml( const QString &filename,
return true;
}

bool QgsAuthManager::importAuthenticationConfigsFromXml( const QString &filename, const QString &password )
bool QgsAuthManager::importAuthenticationConfigsFromXml( const QString &filename, const QString &password, bool overwrite )
{
QFile file( filename );
if ( !file.open( QFile::ReadOnly ) )
@@ -1428,7 +1433,7 @@ bool QgsAuthManager::importAuthenticationConfigsFromXml( const QString &filename
{
QgsAuthMethodConfig authMethodConfig;
authMethodConfig.readXml( configuration );
storeAuthenticationConfig( authMethodConfig );
storeAuthenticationConfig( authMethodConfig, overwrite );

configuration = configuration.nextSiblingElement();
}
@@ -273,9 +273,10 @@ class CORE_EXPORT QgsAuthManager : public QObject
/**
* Store an authentication config in the database
* \param mconfig Associated authentication config id
* \param overwrite If set to TRUE, pre-existing authentication configurations will be overwritten
* \returns Whether operation succeeded
*/
bool storeAuthenticationConfig( QgsAuthMethodConfig &mconfig SIP_INOUT );
bool storeAuthenticationConfig( QgsAuthMethodConfig &mconfig SIP_INOUT, bool overwrite = false );

/**
* Update an authentication config in the database
@@ -313,9 +314,10 @@ class CORE_EXPORT QgsAuthManager : public QObject
* 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
* \param overwrite If set to TRUE, pre-existing authentication configurations will be overwritten
* \since QGIS 3.20
*/
bool importAuthenticationConfigsFromXml( const QString &filename, const QString &password = QString() );
bool importAuthenticationConfigsFromXml( const QString &filename, const QString &password = QString(), bool overwrite = false );

/**
* Clear all authentication configs from table in database and from provider caches

0 comments on commit 8513b80

Please sign in to comment.