Skip to content

Commit

Permalink
Don't ask for a password when importing a plain text configurations file
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvn committed May 12, 2021
1 parent 3d70259 commit a27c164
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 13 deletions.
10 changes: 5 additions & 5 deletions src/core/auth/qgsauthmanager.cpp
Expand Up @@ -1386,19 +1386,19 @@ bool QgsAuthManager::exportAuthenticationConfigsToXml( const QString &filename,

bool QgsAuthManager::importAuthenticationConfigsFromXml( const QString &filename, const QString &password )
{
QFile f( filename );
if ( !f.open( QFile::ReadOnly ) )
QFile file( filename );
if ( !file.open( QFile::ReadOnly ) )
{
return false;
}

QDomDocument document( QStringLiteral( "qgis_authentication" ) );
if ( !document.setContent( &f ) )
if ( !document.setContent( &file ) )
{
f.close();
file.close();
return false;
}
f.close();
file.close();

QDomElement root = document.documentElement();
if ( root.tagName() != QLatin1String( "qgis_authentication" ) )
Expand Down
41 changes: 33 additions & 8 deletions src/gui/auth/qgsauthguiutils.cpp
Expand Up @@ -92,12 +92,12 @@ void QgsAuthGuiUtils::exportSelectedAuthenticationConfigs( QStringList authentic
}
}

QString fileName = QFileDialog::getSaveFileName( msgbar, QObject::tr( "Export Authentication Configurations" ), QDir::homePath(),
QString filename = QFileDialog::getSaveFileName( msgbar, QObject::tr( "Export Authentication Configurations" ), QDir::homePath(),
QObject::tr( "XML files (*.xml *.XML)" ) );
if ( fileName.isEmpty() )
if ( filename.isEmpty() )
return;

bool ok = QgsApplication::authManager()->exportAuthenticationConfigsToXml( fileName, authenticationConfigIds, password );
bool ok = QgsApplication::authManager()->exportAuthenticationConfigsToXml( filename, authenticationConfigIds, password );
if ( !ok )
{
msgbar->pushMessage( QgsApplication::authManager()->authManTag(),
Expand All @@ -109,15 +109,40 @@ void QgsAuthGuiUtils::exportSelectedAuthenticationConfigs( QStringList authentic
void QgsAuthGuiUtils::importAuthenticationConfigs( QgsMessageBar *msgbar )
{

QString fileName = QFileDialog::getOpenFileName( msgbar, QObject::tr( "Export Authentication Configurations" ), QDir::homePath(),
QString filename = QFileDialog::getOpenFileName( msgbar, QObject::tr( "Export Authentication Configurations" ), QDir::homePath(),
QObject::tr( "XML files (*.xml *.XML)" ) );
if ( fileName.isEmpty() )
if ( filename.isEmpty() )
return;

QString password = QInputDialog::getText( msgbar, QObject::tr( "Import Authentication Configurations" ),
QObject::tr( "Enter the password to decrypt the configurations file:" ), QLineEdit::Password );

bool ok = QgsApplication::authManager()->importAuthenticationConfigsFromXml( fileName, password );
QFile file( filename );
if ( !file.open( QFile::ReadOnly ) )
{
return;
}

QDomDocument document( QStringLiteral( "qgis_authentication" ) );
if ( !document.setContent( &file ) )
{
file.close();
return;
}
file.close();

QDomElement root = document.documentElement();
if ( root.tagName() != QLatin1String( "qgis_authentication" ) )
{
return;
}

QString password;
if ( root.hasAttribute( QStringLiteral( "salt" ) ) )
{
password = QInputDialog::getText( msgbar, QObject::tr( "Import Authentication Configurations" ),
QObject::tr( "Enter the password to decrypt the configurations file:" ), QLineEdit::Password );
}

bool ok = QgsApplication::authManager()->importAuthenticationConfigsFromXml( filename, password );
if ( !ok )
{
msgbar->pushMessage( QgsApplication::authManager()->authManTag(),
Expand Down

0 comments on commit a27c164

Please sign in to comment.