19 #include <QFileDialog> 
   20 #include <QInputDialog> 
   22 #include <QMessageBox> 
   24 #include "qgssettings.h" 
   34   return QColor( 0, 170, 0 );
 
   39   return QColor( 255, 128, 0 );
 
   44   return QColor( 200, 0, 0 );
 
   49   return QColor( 255, 255, 125 );
 
   71     msgbar->
pushMessage( QObject::tr( 
"Authentication System" ),
 
   72                          QObject::tr( 
"DISABLED. Resources authenticating via the system can not be accessed" ),
 
   73                          Qgis::MessageLevel::Critical );
 
   81   QString password = QInputDialog::getText( msgbar, QObject::tr( 
"Export Authentication Configurations" ),
 
   82                      QObject::tr( 
"Enter a password encrypt the configuration file:" ), QLineEdit::Password );
 
   83   if ( password.isEmpty() )
 
   85     if ( QMessageBox::warning( msgbar,
 
   86                                QObject::tr( 
"Export Authentication Configurations" ),
 
   87                                QObject::tr( 
"Exporting authentication configurations with a blank password will result in a plain text file which may contain sensitive information. Are you sure you want to do this?" ),
 
   88                                QMessageBox::Ok | QMessageBox::Cancel,
 
   89                                QMessageBox::Cancel ) == QMessageBox::Cancel )
 
   95   QString filename = QFileDialog::getSaveFileName( msgbar, QObject::tr( 
"Export Authentication Configurations" ), QDir::homePath(),
 
   96                      QObject::tr( 
"XML files (*.xml *.XML)" ) );
 
   97   if ( filename.isEmpty() )
 
  104                          QObject::tr( 
"Export of authentication configurations failed." ),
 
  105                          Qgis::MessageLevel::Critical );
 
  112   QString filename = QFileDialog::getOpenFileName( msgbar, QObject::tr( 
"Export Authentication Configurations" ), QDir::homePath(),
 
  113                      QObject::tr( 
"XML files (*.xml *.XML)" ) );
 
  114   if ( filename.isEmpty() )
 
  118   QFile file( filename );
 
  119   if ( !file.open( QFile::ReadOnly ) )
 
  124   QDomDocument document( QStringLiteral( 
"qgis_authentication" ) );
 
  125   if ( !document.setContent( &file ) )
 
  132   QDomElement root = document.documentElement();
 
  133   if ( root.tagName() != QLatin1String( 
"qgis_authentication" ) )
 
  139   if ( root.hasAttribute( QStringLiteral( 
"salt" ) ) )
 
  141     password = QInputDialog::getText( msgbar, QObject::tr( 
"Import Authentication Configurations" ),
 
  142                                       QObject::tr( 
"Enter the password to decrypt the configurations file:" ), QLineEdit::Password );
 
  149                          QObject::tr( 
"Import of authentication configurations failed." ),
 
  150                          Qgis::MessageLevel::Critical );
 
  162                          QObject::tr( 
"Master password already set." ),
 
  163                          Qgis::MessageLevel::Info );
 
  174   QString msg( QObject::tr( 
"Master password not cleared because it is not set." ) );
 
  180     msg = QObject::tr( 
"Master password cleared (NOTE: network connections may be cached)." );
 
  183       msg = QObject::tr( 
"Master password FAILED to be cleared." );
 
  184       level = Qgis::MessageLevel::Warning;
 
  196   QString msg( QObject::tr( 
"Master password reset" ) );
 
  202     msg = QObject::tr( 
"Master password reset: NO current password hash in database" );
 
  210   bool keepbackup = 
false;
 
  215     QgsDebugMsg( QStringLiteral( 
"Master password reset: input canceled by user" ) );
 
  222     msg = QObject::tr( 
"Master password FAILED to be reset" );
 
  223     level = Qgis::MessageLevel::Warning;
 
  226   if ( !backuppath.isEmpty() )
 
  228     msg += QObject::tr( 
" (database backup: %1)" ).arg( backuppath );
 
  240   QString msg = QObject::tr( 
"Cached authentication configurations for session cleared" );
 
  249   if ( QMessageBox::warning( parent,
 
  250                              QObject::tr( 
"Remove Configurations" ),
 
  251                              QObject::tr( 
"Are you sure you want to remove ALL authentication configurations?\n\n" 
  252                                           "Operation can NOT be undone!" ),
 
  253                              QMessageBox::Ok | QMessageBox::Cancel,
 
  254                              QMessageBox::Cancel ) == QMessageBox::Cancel )
 
  259   QString msg( QObject::tr( 
"Authentication configurations removed." ) );
 
  264     msg = QObject::tr( 
"Authentication configurations FAILED to be removed." );
 
  265     level = Qgis::MessageLevel::Warning;
 
  276   QMessageBox::StandardButton btn = QMessageBox::warning(
 
  278                                       QObject::tr( 
"Erase Database" ),
 
  279                                       QObject::tr( 
"Are you sure you want to ERASE the entire authentication database?\n\n" 
  280                                           "Operation can NOT be undone!\n\n" 
  281                                           "(Current database will be backed up and new one created.)" ),
 
  282                                       QMessageBox::Ok | QMessageBox::Cancel,
 
  283                                       QMessageBox::Cancel );
 
  287   if ( btn == QMessageBox::Cancel )
 
  292   QString msg( QObject::tr( 
"Active authentication database erased." ) );
 
  298     msg = QObject::tr( 
"Authentication database FAILED to be erased." );
 
  299     level = Qgis::MessageLevel::Warning;
 
  303     if ( !backuppath.isEmpty() )
 
  305       msg += QObject::tr( 
" (backup: %1)" ).arg( backuppath );
 
  307     level = Qgis::MessageLevel::Critical;
 
  310   msgbar->
pushMessage( QObject::tr( 
"RESTART QGIS" ), msg, level );
 
  318     widget->setToolTip( QObject::tr( 
"File not found" ) );
 
  322     widget->setStyleSheet( QString() );
 
  323     widget->setToolTip( QString() );
 
  329   QgsSettings settings;
 
  330   QString recentdir = settings.value( QStringLiteral( 
"UI/lastAuthOpenFileDir" ), QDir::homePath() ).toString();
 
  331   QString f = QFileDialog::getOpenFileName( parent, title, recentdir, extfilter );
 
  334     settings.setValue( QStringLiteral( 
"UI/lastAuthOpenFileDir" ), QFileInfo( f ).absoluteDir().path() );
 
  341   if ( QMessageBox::warning( parent,
 
  342                              QObject::tr( 
"Delete Password" ),
 
  343                              QObject::tr( 
"Do you really want to delete the master password from your %1?" )
 
  345                              QMessageBox::Ok | QMessageBox::Cancel,
 
  346                              QMessageBox::Cancel ) == QMessageBox::Cancel )
 
  355     level = Qgis::MessageLevel::Warning;
 
  359     msg = QObject::tr( 
"Master password was successfully deleted from your %1" )
 
  362     level = Qgis::MessageLevel::Info;
 
  364   msgbar->
pushMessage( QObject::tr( 
"Password helper delete" ), msg, level );
 
  373     msg = QObject::tr( 
"Master password is not set and cannot be stored in your %1." )
 
  375     level = Qgis::MessageLevel::Warning;
 
  380     level = Qgis::MessageLevel::Warning;
 
  384     msg = QObject::tr( 
"Master password has been successfully stored in your %1." )
 
  387     level = Qgis::MessageLevel::Info;
 
  389   msgbar->
pushMessage( QObject::tr( 
"Password helper write" ), msg, level );
 
  395   QString msg = enabled ? QObject::tr( 
"Your %1 will be <b>used from now</b> on to store and retrieve the master password." )
 
  397                 QObject::tr( 
"Your %1 will <b>not be used anymore</b> to store and retrieve the master password." )
 
  399   msgbar->
pushMessage( QObject::tr( 
"Password helper write" ), msg, Qgis::MessageLevel::Info );
 
MessageLevel
Level for messages This will be used both for message log and message bar in application.
static QgsAuthManager * authManager()
Returns the application's authentication manager instance.
static void importAuthenticationConfigs(QgsMessageBar *msgbar)
Import authentication configurations from a XML file.
static void exportSelectedAuthenticationConfigs(QStringList authenticationConfigIds, QgsMessageBar *msgbar)
Exports selected authentication configurations to a XML file.
static QString greenTextStyleSheet(const QString &selector="*")
Green text stylesheet representing valid, trusted, etc. certificate.
static void resetMasterPassword(QgsMessageBar *msgbar, QWidget *parent=nullptr)
Reset the cached master password, updating its hash in authentication database and resetting all exis...
static QColor greenColor()
Green color representing valid, trusted, etc. certificate.
static QColor orangeColor()
Orange color representing loaded component, but not stored in database.
static QString redTextStyleSheet(const QString &selector="*")
Red text stylesheet representing invalid, untrusted, etc. certificate.
static void clearCachedMasterPassword(QgsMessageBar *msgbar)
Clear the currently cached master password (not its hash in database)
static void passwordHelperEnable(bool enabled, QgsMessageBar *msgbar)
Sets password helper enabled (enable/disable)
static QString orangeTextStyleSheet(const QString &selector="*")
Orange text stylesheet representing loaded component, but not stored in database.
static void clearCachedAuthenticationConfigs(QgsMessageBar *msgbar)
Clear all cached authentication configs for session.
static bool isDisabled(QgsMessageBar *msgbar)
Verify the authentication system is active, else notify user.
static void passwordHelperLoggingEnable(bool enabled, QgsMessageBar *msgbar, int timeout=0)
Sets password helper logging enabled (enable/disable)
static void eraseAuthenticationDatabase(QgsMessageBar *msgbar, QWidget *parent=nullptr)
Completely clear out the authentication database (configs and master password)
static void removeAuthenticationConfigs(QgsMessageBar *msgbar, QWidget *parent=nullptr)
Remove all authentication configs.
static QColor yellowColor()
Yellow color representing caution regarding action.
static void fileFound(bool found, QWidget *widget)
Color a widget via a stylesheet if a file path is found or not.
static void setMasterPassword(QgsMessageBar *msgbar)
Sets the cached master password (and verifies it if its hash is in authentication database)
static QString getOpenFileName(QWidget *parent, const QString &title, const QString &extfilter)
Open file dialog for auth associated widgets.
static void passwordHelperDelete(QgsMessageBar *msgbar, QWidget *parent=nullptr)
Remove master password from wallet.
static void passwordHelperSync(QgsMessageBar *msgbar)
Store master password into the wallet.
static QColor redColor()
Red color representing invalid, untrusted, etc. certificate.
void clearAllCachedConfigs()
Clear all authentication configs from authentication method caches.
bool exportAuthenticationConfigsToXml(const QString &filename, const QStringList &authcfgs, const QString &password=QString())
Export authentication configurations to an XML file.
void setPasswordHelperEnabled(bool enabled)
Password helper enabled setter.
void setScheduledAuthDatabaseErase(bool scheduleErase)
Schedule an optional erase of authentication database, starting when mutex is lockable.
bool importAuthenticationConfigsFromXml(const QString &filename, const QString &password=QString(), bool overwrite=false)
Import authentication configurations from an XML file.
void clearMasterPassword()
Clear supplied master password.
const QString passwordHelperErrorMessage()
Error message getter.
void setPasswordHelperLoggingEnabled(bool enabled)
Password helper logging enabled setter.
bool setMasterPassword(bool verify=false)
Main call to initially set or continually check master password is set.
static const QString AUTH_PASSWORD_HELPER_DISPLAY_NAME
The display name of the password helper (platform dependent)
Dialog to verify current master password and initiate reset of authentication database with a new pas...
bool requestMasterPasswordReset(QString *newpass, QString *oldpass, bool *keepbackup)
A bar for displaying non-blocking messages to the user.
void pushMessage(const QString &text, Qgis::MessageLevel level=Qgis::MessageLevel::Info, int duration=-1)
A convenience method for pushing a message with the specified text to the bar.