19 #include <QFileDialog> 21 #include <QMessageBox> 33 return QColor( 0, 170, 0 );
38 return QColor( 255, 128, 0 );
43 return QColor( 200, 0, 0 );
48 return QColor( 255, 255, 125 );
70 msgbar->
pushMessage( QObject::tr(
"Authentication System" ),
71 QObject::tr(
"DISABLED. Resources authenticating via the system can not be accessed" ),
86 QObject::tr(
"Master password already set." ),
98 QString msg( QObject::tr(
"Master password not cleared because it is not set." ) );
104 msg = QObject::tr(
"Master password cleared (NOTE: network connections may be cached)." );
107 msg = QObject::tr(
"Master password FAILED to be cleared." );
120 QString msg( QObject::tr(
"Master password reset" ) );
126 msg = QObject::tr(
"Master password reset: NO current password hash in database" );
134 bool keepbackup =
false;
139 QgsDebugMsg(
"Master password reset: input canceled by user" );
146 msg = QObject::tr(
"Master password FAILED to be reset" );
150 if ( !backuppath.isEmpty() )
152 msg += QObject::tr(
" (database backup: %1)" ).arg( backuppath );
165 QString msg = QObject::tr(
"Cached authentication configurations for session cleared" );
174 if ( QMessageBox::warning( parent,
175 QObject::tr(
"Remove Configurations" ),
176 QObject::tr(
"Are you sure you want to remove ALL authentication configurations?\n\n" 177 "Operation can NOT be undone!" ),
178 QMessageBox::Ok | QMessageBox::Cancel,
179 QMessageBox::Cancel ) == QMessageBox::Cancel )
184 QString msg( QObject::tr(
"Authentication configurations removed." ) );
189 msg = QObject::tr(
"Authentication configurations FAILED to be removed." );
201 QMessageBox::StandardButton btn = QMessageBox::warning(
203 QObject::tr(
"Erase Database" ),
204 QObject::tr(
"Are you sure you want to ERASE the entire authentication database?\n\n" 205 "Operation can NOT be undone!\n\n" 206 "(Current database will be backed up and new one created.)" ),
207 QMessageBox::Ok | QMessageBox::Cancel,
208 QMessageBox::Cancel );
212 if ( btn == QMessageBox::Cancel )
217 QString msg( QObject::tr(
"Active authentication database erased." ) );
223 msg = QObject::tr(
"Authentication database FAILED to be erased." );
228 if ( !backuppath.isEmpty() )
230 msg += QObject::tr(
" (backup: %1)" ).arg( backuppath );
236 msgbar->
pushMessage( QObject::tr(
"RESTART QGIS" ), msg, level, timeout );
244 widget->setToolTip( QObject::tr(
"File not found" ) );
248 widget->setStyleSheet( QLatin1String(
"" ) );
249 widget->setToolTip( QLatin1String(
"" ) );
256 QString recentdir = settings.
value( QStringLiteral(
"UI/lastAuthOpenFileDir" ), QDir::homePath() ).toString();
257 QString
f = QFileDialog::getOpenFileName( parent, title, recentdir, extfilter );
260 settings.
setValue( QStringLiteral(
"UI/lastAuthOpenFileDir" ), QFileInfo( f ).absoluteDir().path() );
267 if ( QMessageBox::warning( parent,
268 QObject::tr(
"Delete Password" ),
269 QObject::tr(
"Do you really want to delete the master password from your %1?" )
271 QMessageBox::Ok | QMessageBox::Cancel,
272 QMessageBox::Cancel ) == QMessageBox::Cancel )
285 msg = QObject::tr(
"Master password was successfully deleted from your %1" )
290 msgbar->
pushMessage( QObject::tr(
"Password helper delete" ), msg, level, timeout );
299 msg = QObject::tr(
"Master password is not set and cannot be stored in your %1." )
310 msg = QObject::tr(
"Master password has been successfully stored in your %1." )
315 msgbar->
pushMessage( QObject::tr(
"Password helper write" ), msg, level, timeout );
321 QString msg = enabled ? QObject::tr(
"Your %1 will be <b>used from now</b> on to store and retrieve the master password." )
323 QObject::tr(
"Your %1 will <b>not be used anymore</b> to store and retrieve the master password." )
static bool isDisabled(QgsMessageBar *msgbar, int timeout=0)
Verify the authentication system is active, else notify user.
static void resetMasterPassword(QgsMessageBar *msgbar, int timeout=0, QWidget *parent=nullptr)
Reset the cached master password, updating its hash in authentication database and resetting all exis...
static void eraseAuthenticationDatabase(QgsMessageBar *msgbar, int timeout=0, QWidget *parent=nullptr)
Completely clear out the authentication database (configs and master password)
static void fileFound(bool found, QWidget *widget)
Color a widget via a stylesheet if a file path is found or not.
void setScheduledAuthDatabaseErase(bool scheduleErase)
Schedule an optional erase of authentication database, starting when mutex is lockable.
This class is a composition of two QSettings instances:
static void clearCachedMasterPassword(QgsMessageBar *msgbar, int timeout=0)
Clear the currently cached master password (not its hash in database)
static void removeAuthenticationConfigs(QgsMessageBar *msgbar, int timeout=0, QWidget *parent=nullptr)
Remove all authentication configs.
A bar for displaying non-blocking messages to the user.
static void setMasterPassword(QgsMessageBar *msgbar, int timeout=0)
Sets the cached master password (and verifies it if its hash is in authentication database) ...
static QColor yellowColor()
Yellow color representing caution regarding action.
MessageLevel
Level for messages This will be used both for message log and message bar in application.
static QColor orangeColor()
Orange color representing loaded component, but not stored in database.
static const QString AUTH_PASSWORD_HELPER_DISPLAY_NAME
The display name of the password helper (platform dependent)
static void passwordHelperLoggingEnable(bool enabled, QgsMessageBar *msgbar, int timeout=0)
Set password helper logging enabled (enable/disable)
static void clearCachedAuthenticationConfigs(QgsMessageBar *msgbar, int timeout=0)
Clear all cached authentication configs for session.
void setValue(const QString &key, const QVariant &value, const QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.
static QColor redColor()
Red color representing invalid, untrusted, etc. certificate.
static QColor greenColor()
Green color representing valid, trusted, etc. certificate.
static QString greenTextStyleSheet(const QString &selector="*")
Green text stylesheet representing valid, trusted, etc. certificate.
void setPasswordHelperEnabled(const bool enabled)
Password helper enabled setter.
static QString getOpenFileName(QWidget *parent, const QString &title, const QString &extfilter)
Open file dialog for auth associated widgets.
void setPasswordHelperLoggingEnabled(const bool enabled)
Password helper logging enabled setter.
bool requestMasterPasswordReset(QString *newpass, QString *oldpass, bool *keepbackup)
void pushMessage(const QString &text, Qgis::MessageLevel level=Qgis::Info, int duration=5)
convenience method for pushing a message to the bar
static void passwordHelperEnable(bool enabled, QgsMessageBar *msgbar, int timeout=0)
Set password helper enabled (enable/disable)
static QgsAuthManager * authManager()
Returns the application's authentication manager instance.
static void passwordHelperSync(QgsMessageBar *msgbar, int timeout=0)
Store master password into the wallet.
static QString redTextStyleSheet(const QString &selector="*")
Red text stylesheet representing invalid, untrusted, etc. certificate.
void clearMasterPassword()
Clear supplied master password.
bool setMasterPassword(bool verify=false)
Main call to initially set or continually check master password is set.
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), const Section section=NoSection) const
Returns the value for setting key.
const QString passwordHelperErrorMessage()
Error message getter.
Dialog to verify current master password and initiate reset of authentication database with a new pas...
static QString orangeTextStyleSheet(const QString &selector="*")
Orange text stylesheet representing loaded component, but not stored in database. ...
void clearAllCachedConfigs()
Clear all authentication configs from authentication method caches.
static void passwordHelperDelete(QgsMessageBar *msgbar, int timeout=0, QWidget *parent=nullptr)
Remove master password from wallet.