20#include <QInputDialog> 
   34  return QColor( 0, 170, 0 );
 
 
   39  return QColor( 255, 128, 0 );
 
 
   44  return QColor( 200, 0, 0 );
 
 
   49  return QColor( 255, 255, 125 );
 
 
   72    msgbar->
pushMessage( QObject::tr( 
"Authentication System" ),
 
   73                         QObject::tr( 
"DISABLED. Resources authenticating via the system can not be accessed" ),
 
 
   82  const QString password = QInputDialog::getText( msgbar, QObject::tr( 
"Export Authentication Configurations" ),
 
   83                           QObject::tr( 
"Enter a password encrypt the configuration file:" ), QLineEdit::Password );
 
   84  if ( password.isEmpty() )
 
   86    if ( QMessageBox::warning( msgbar,
 
   87                               QObject::tr( 
"Export Authentication Configurations" ),
 
   88                               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?" ),
 
   89                               QMessageBox::Ok | QMessageBox::Cancel,
 
   90                               QMessageBox::Cancel ) == QMessageBox::Cancel )
 
   96  const QString filename = QFileDialog::getSaveFileName( msgbar, QObject::tr( 
"Export Authentication Configurations" ), QDir::homePath(),
 
   97                           QObject::tr( 
"XML files (*.xml *.XML)" ) );
 
   98  if ( filename.isEmpty() )
 
  106                         QObject::tr( 
"Export of authentication configurations failed." ),
 
 
  114  const QString filename = QFileDialog::getOpenFileName( msgbar, QObject::tr( 
"Export Authentication Configurations" ), QDir::homePath(),
 
  115                           QObject::tr( 
"XML files (*.xml *.XML)" ) );
 
  116  if ( filename.isEmpty() )
 
  120  QFile file( filename );
 
  121  if ( !file.open( QFile::ReadOnly ) )
 
  126  QDomDocument document( QStringLiteral( 
"qgis_authentication" ) );
 
  127  if ( !document.setContent( &file ) )
 
  134  const QDomElement root = document.documentElement();
 
  135  if ( root.tagName() != QLatin1String( 
"qgis_authentication" ) )
 
  141  if ( root.hasAttribute( QStringLiteral( 
"salt" ) ) )
 
  143    password = QInputDialog::getText( msgbar, QObject::tr( 
"Import Authentication Configurations" ),
 
  144                                      QObject::tr( 
"Enter the password to decrypt the configurations file:" ), QLineEdit::Password );
 
  152                         QObject::tr( 
"Import of authentication configurations failed." ),
 
 
  166                         QObject::tr( 
"Master password already set." ),
 
 
  178  QString msg( QObject::tr( 
"Master password not cleared because it is not set." ) );
 
  184    msg = QObject::tr( 
"Master password cleared (NOTE: network connections may be cached)." );
 
  187      msg = QObject::tr( 
"Master password FAILED to be cleared." );
 
 
  201  QString msg( QObject::tr( 
"Master password reset" ) );
 
  207    msg = QObject::tr( 
"Master password reset: NO current password hash in database" );
 
  216  bool keepbackup = 
false;
 
  221    QgsDebugMsgLevel( QStringLiteral( 
"Master password reset: input canceled by user" ), 2 );
 
  228    msg = QObject::tr( 
"Master password FAILED to be reset" );
 
  232  if ( !backuppath.isEmpty() )
 
  234    msg += QObject::tr( 
" (database backup: %1)" ).arg( backuppath );
 
 
  247  const QString msg = QObject::tr( 
"Cached authentication configurations for session cleared" );
 
 
  257  if ( QMessageBox::warning( parent,
 
  258                             QObject::tr( 
"Remove Configurations" ),
 
  259                             QObject::tr( 
"Are you sure you want to remove ALL authentication configurations?\n\n" 
  260                                          "Operation can NOT be undone!" ),
 
  261                             QMessageBox::Ok | QMessageBox::Cancel,
 
  262                             QMessageBox::Cancel ) == QMessageBox::Cancel )
 
  267  QString msg( QObject::tr( 
"Authentication configurations removed." ) );
 
  272    msg = QObject::tr( 
"Authentication configurations FAILED to be removed." );
 
 
  285  const QMessageBox::StandardButton btn = QMessageBox::warning(
 
  287      QObject::tr( 
"Erase Database" ),
 
  288      QObject::tr( 
"Are you sure you want to ERASE the entire authentication database?\n\n" 
  289                   "Operation can NOT be undone!\n\n" 
  290                   "(Current database will be backed up and new one created.)" ),
 
  291      QMessageBox::Ok | QMessageBox::Cancel,
 
  292      QMessageBox::Cancel );
 
  296  if ( btn == QMessageBox::Cancel )
 
  301  QString msg( QObject::tr( 
"Active authentication database erased." ) );
 
  307    msg = QObject::tr( 
"Authentication database FAILED to be erased." );
 
  312    if ( !backuppath.isEmpty() )
 
  314      msg += QObject::tr( 
" (backup: %1)" ).arg( backuppath );
 
  320  msgbar->
pushMessage( QObject::tr( 
"RESTART QGIS" ), msg, level );
 
 
  328    widget->setToolTip( QObject::tr( 
"File not found" ) );
 
  332    widget->setStyleSheet( QString() );
 
  333    widget->setToolTip( QString() );
 
 
  340  const QString recentdir = settings.
value( QStringLiteral( 
"UI/lastAuthOpenFileDir" ), QDir::homePath() ).toString();
 
  341  QString f = QFileDialog::getOpenFileName( parent, title, recentdir, extfilter );
 
  344    settings.
setValue( QStringLiteral( 
"UI/lastAuthOpenFileDir" ), QFileInfo( f ).absoluteDir().path() );
 
 
  351  if ( QMessageBox::warning( parent,
 
  352                             QObject::tr( 
"Delete Password" ),
 
  353                             QObject::tr( 
"Do you really want to delete the master password from your %1?" )
 
  355                             QMessageBox::Ok | QMessageBox::Cancel,
 
  356                             QMessageBox::Cancel ) == QMessageBox::Cancel )
 
  369    msg = QObject::tr( 
"Master password was successfully deleted from your %1" )
 
  375  msgbar->
pushMessage( QObject::tr( 
"Password helper delete" ), msg, level );
 
 
  384    msg = QObject::tr( 
"Master password is not set and cannot be stored in your %1." )
 
  395    msg = QObject::tr( 
"Master password has been successfully stored in your %1." )
 
  401  msgbar->
pushMessage( QObject::tr( 
"Password helper write" ), msg, level );
 
 
  407  const QString msg = enabled ? QObject::tr( 
"Your %1 will be <b>used from now</b> on to store and retrieve the master password." )
 
  409                      QObject::tr( 
"Your %1 will <b>not be used anymore</b> to store and retrieve the master password." )
 
 
MessageLevel
Level for messages This will be used both for message log and message bar in application.
@ Warning
Warning message.
@ Critical
Critical/error message.
@ Info
Information message.
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.
static 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.
bool clearWidgets()
Removes all items from the bar.
This class is a composition of two QSettings instances:
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
void setValue(const QString &key, const QVariant &value, QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.
#define QgsDebugMsgLevel(str, level)