19 #include <QFileDialog> 
   20 #include <QInputDialog> 
   22 #include <QMessageBox> 
   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   const 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   const 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   const 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   const 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   const 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   const 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() );
 
  330   const 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   const 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 );