QGIS API Documentation 3.99.0-Master (752b475928d)
Loading...
Searching...
No Matches
qgsautheditorwidgets.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsautheditorwidgets.cpp
3 ---------------------
4 begin : April 26, 2015
5 copyright : (C) 2015 by Boundless Spatial, Inc. USA
6 author : Larry Shaffer
7 email : lshaffer at boundlessgeo dot com
8 ***************************************************************************
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 ***************************************************************************/
16
17#include "ui_qgsauthmethodplugins.h"
19
20#include "qgsapplication.h"
23#include "qgsauthguiutils.h"
24#include "qgsauthmanager.h"
26#include "qgshelp.h"
28#include "qgssettings.h"
29
30#include <QAction>
31#include <QMenu>
32#include <QTableWidget>
33#include <QWidget>
34
35#include "moc_qgsautheditorwidgets.cpp"
36
38 : QDialog( parent )
39
40{
41 if ( QgsApplication::authManager()->isDisabled() )
42 {
43 mAuthNotifyLayout = new QVBoxLayout;
44 this->setLayout( mAuthNotifyLayout );
45 mAuthNotify = new QLabel( QgsApplication::authManager()->disabledMessage(), this );
46 mAuthNotifyLayout->addWidget( mAuthNotify );
47 }
48 else
49 {
50 setupUi( this );
51 connect( buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject );
52 connect( buttonBox, &QDialogButtonBox::helpRequested, this, [] {
53 QgsHelp::openHelp( QStringLiteral( "auth_system/auth_overview.html#authentication-methods" ) );
54 } );
55
56 setupTable();
57 populateTable();
58 }
59}
60
61void QgsAuthMethodPlugins::setupTable()
62{
63 tblAuthPlugins->setColumnCount( 3 );
64 tblAuthPlugins->verticalHeader()->hide();
65 tblAuthPlugins->horizontalHeader()->setVisible( true );
66 tblAuthPlugins->setHorizontalHeaderItem( 0, new QTableWidgetItem( tr( "Method" ) ) );
67 tblAuthPlugins->setHorizontalHeaderItem( 1, new QTableWidgetItem( tr( "Description" ) ) );
68 tblAuthPlugins->setHorizontalHeaderItem( 2, new QTableWidgetItem( tr( "Works with" ) ) );
69 tblAuthPlugins->horizontalHeader()->setStretchLastSection( true );
70 tblAuthPlugins->setAlternatingRowColors( true );
71 tblAuthPlugins->setColumnWidth( 0, 150 );
72 tblAuthPlugins->setColumnWidth( 1, 300 );
73 tblAuthPlugins->setRowCount( QgsApplication::authManager()->authMethodsKeys().size() );
74 tblAuthPlugins->verticalHeader()->setSectionResizeMode( QHeaderView::ResizeToContents );
75 tblAuthPlugins->setSortingEnabled( true );
76 tblAuthPlugins->setSelectionBehavior( QAbstractItemView::SelectRows );
77}
78
79void QgsAuthMethodPlugins::populateTable()
80{
81 const QStringList authMethodKeys = QgsApplication::authManager()->authMethodsKeys();
82
83 int i = 0;
84 const auto constAuthMethodKeys = authMethodKeys;
85 for ( const QString &authMethodKey : constAuthMethodKeys )
86 {
87 const QgsAuthMethodMetadata *meta = QgsApplication::authManager()->authMethodMetadata( authMethodKey );
88 const QgsAuthMethod *method = QgsApplication::authManager()->authMethod( authMethodKey );
89 if ( !meta || !method )
90 {
91 QgsDebugError( QStringLiteral( "Load auth method instance FAILED for auth method key (%1)" ).arg( authMethodKey ) );
92 continue;
93 }
94
95 QTableWidgetItem *twi = new QTableWidgetItem( meta->key() );
96 twi->setFlags( twi->flags() & ~Qt::ItemIsEditable );
97 tblAuthPlugins->setItem( i, 0, twi );
98
99 twi = new QTableWidgetItem( meta->description() );
100 twi->setFlags( twi->flags() & ~Qt::ItemIsEditable );
101 tblAuthPlugins->setItem( i, 1, twi );
102
103 twi = new QTableWidgetItem( method->supportedDataProviders().join( QLatin1String( ", " ) ) );
104 twi->setFlags( twi->flags() & ~Qt::ItemIsEditable );
105 tblAuthPlugins->setItem( i, 2, twi );
106
107 i++;
108 }
109 tblAuthPlugins->sortItems( 0 );
110}
111
112
114 : QWidget( parent )
115
116{
117 setupUi( this );
118 connect( btnCertManager, &QPushButton::clicked, this, &QgsAuthEditorWidgets::btnCertManager_clicked );
119 connect( btnAuthPlugins, &QPushButton::clicked, this, &QgsAuthEditorWidgets::btnAuthPlugins_clicked );
120 if ( !QgsApplication::authManager()->isDisabled() )
121 {
122 wdgtConfigEditor->setRelayMessages( false );
123 wdgtConfigEditor->setShowUtilitiesButton( false );
124 setupUtilitiesMenu();
125 }
126 else
127 {
128 grpbxManagers->setEnabled( false );
129 }
130}
131
132void QgsAuthEditorWidgets::btnCertManager_clicked()
133{
134 QgsAuthCertManager *dlg = new QgsAuthCertManager( this );
135 dlg->setWindowModality( Qt::ApplicationModal );
136 dlg->resize( 750, 500 );
137 dlg->exec();
138 dlg->deleteLater();
139}
140
141void QgsAuthEditorWidgets::btnAuthPlugins_clicked()
142{
143 QgsAuthMethodPlugins *dlg = new QgsAuthMethodPlugins( this );
144 dlg->setWindowModality( Qt::WindowModal );
145 dlg->resize( 675, 500 );
146 dlg->exec();
147 dlg->deleteLater();
148}
149
150void QgsAuthEditorWidgets::setupUtilitiesMenu()
151{
152 connect( QgsApplication::authManager(), &QgsAuthManager::messageLog, this, &QgsAuthEditorWidgets::authMessageLog );
153
155
156 // set up utility actions menu
157 mActionImportAuthenticationConfigs = new QAction( tr( "Import Authentication Configurations from File…" ), this );
158 mActionExportSelectedAuthenticationConfigs = new QAction( tr( "Export Selected Authentication Configurations to File…" ), this );
159 mActionSetMasterPassword = new QAction( tr( "Input Master Password…" ), this );
160 mActionClearCachedMasterPassword = new QAction( tr( "Clear Cached Master Password" ), this );
161 mActionResetMasterPassword = new QAction( tr( "Reset Master Password…" ), this );
162 mActionClearCachedAuthConfigs = new QAction( tr( "Clear Cached Authentication Configurations" ), this );
163 mActionRemoveAuthConfigs = new QAction( tr( "Remove all Authentication Configurations…" ), this );
164 mActionEraseAuthDatabase = new QAction( tr( "Erase Authentication Database…" ), this );
165
166 mActionClearAccessCacheNow = new QAction( tr( "Clear Network Authentication Access Cache" ), this );
167 mActionAutoClearAccessCache = new QAction( tr( "Automatically Clear Network Authentication Access Cache on SSL Errors" ), this );
168 mActionAutoClearAccessCache->setCheckable( true );
169 mActionAutoClearAccessCache->setChecked( QgsSettings().value( QStringLiteral( "clear_auth_cache_on_errors" ), true, QgsSettings::Section::Auth ).toBool() );
170
171 mActionPasswordHelperDelete = new QAction( tr( "Clear the Master Password from the %1…" ).arg( QgsAuthManager::passwordHelperDisplayName( true ) ), this );
172 mActionPasswordHelperEnable = new QAction( tr( "Integrate Master Password with the %1" ).arg( QgsAuthManager::passwordHelperDisplayName( true ) ), this );
173 mActionPasswordHelperLoggingEnable = new QAction( tr( "Enable Password Helper Debug Log" ), this );
174
175 mActionPasswordHelperEnable->setCheckable( true );
176 mActionPasswordHelperEnable->setChecked( QgsApplication::authManager()->passwordHelperEnabled() );
177
178 mActionPasswordHelperLoggingEnable->setCheckable( true );
179 mActionPasswordHelperLoggingEnable->setChecked( QgsApplication::authManager()->passwordHelperLoggingEnabled() );
180
181 if ( !isReadOnly )
182 {
183 connect( mActionImportAuthenticationConfigs, &QAction::triggered, this, &QgsAuthEditorWidgets::importAuthenticationConfigs );
184 connect( mActionResetMasterPassword, &QAction::triggered, this, &QgsAuthEditorWidgets::resetMasterPassword );
185 connect( mActionRemoveAuthConfigs, &QAction::triggered, this, &QgsAuthEditorWidgets::removeAuthenticationConfigs );
186 connect( mActionEraseAuthDatabase, &QAction::triggered, this, &QgsAuthEditorWidgets::eraseAuthenticationDatabase );
187 }
188 else
189 {
190 mActionImportAuthenticationConfigs->setEnabled( false );
191 mActionResetMasterPassword->setEnabled( false );
192 mActionRemoveAuthConfigs->setEnabled( false );
193 mActionEraseAuthDatabase->setEnabled( false );
194 }
195
196 connect( mActionExportSelectedAuthenticationConfigs, &QAction::triggered, this, &QgsAuthEditorWidgets::exportSelectedAuthenticationConfigs );
197 connect( mActionSetMasterPassword, &QAction::triggered, this, &QgsAuthEditorWidgets::setMasterPassword );
198 connect( mActionClearCachedMasterPassword, &QAction::triggered, this, &QgsAuthEditorWidgets::clearCachedMasterPassword );
199 connect( mActionClearCachedAuthConfigs, &QAction::triggered, this, &QgsAuthEditorWidgets::clearCachedAuthenticationConfigs );
200
201 connect( mActionPasswordHelperDelete, &QAction::triggered, this, &QgsAuthEditorWidgets::passwordHelperDelete );
202 connect( mActionPasswordHelperEnable, &QAction::triggered, this, &QgsAuthEditorWidgets::passwordHelperEnableTriggered );
203 connect( mActionPasswordHelperLoggingEnable, &QAction::triggered, this, &QgsAuthEditorWidgets::passwordHelperLoggingEnableTriggered );
204
205 connect( mActionClearAccessCacheNow, &QAction::triggered, this, [this] {
206 QgsNetworkAccessManager::instance()->clearAccessCache();
207 messageBar()->clearWidgets();
208 messageBar()->pushSuccess( tr( "Auth cache cleared" ), tr( "Network authentication cache has been cleared" ) );
209 } );
210 connect( mActionAutoClearAccessCache, &QAction::triggered, this, []( bool checked ) {
211 QgsSettings().setValue( QStringLiteral( "clear_auth_cache_on_errors" ), checked, QgsSettings::Section::Auth );
212 } );
213
214 mAuthUtilitiesMenu = new QMenu( this );
215 mAuthUtilitiesMenu->addAction( mActionSetMasterPassword );
216 mAuthUtilitiesMenu->addAction( mActionClearCachedMasterPassword );
217 mAuthUtilitiesMenu->addAction( mActionResetMasterPassword );
218 mAuthUtilitiesMenu->addSeparator();
219 mAuthUtilitiesMenu->addAction( mActionClearAccessCacheNow );
220 mAuthUtilitiesMenu->addAction( mActionAutoClearAccessCache );
221 mAuthUtilitiesMenu->addSeparator();
222 mAuthUtilitiesMenu->addAction( mActionPasswordHelperEnable );
223 mAuthUtilitiesMenu->addAction( mActionPasswordHelperDelete );
224 mAuthUtilitiesMenu->addAction( mActionPasswordHelperLoggingEnable );
225 mAuthUtilitiesMenu->addSeparator();
226 mAuthUtilitiesMenu->addAction( mActionClearCachedAuthConfigs );
227 mAuthUtilitiesMenu->addAction( mActionRemoveAuthConfigs );
228 mAuthUtilitiesMenu->addSeparator();
229 mAuthUtilitiesMenu->addAction( mActionImportAuthenticationConfigs );
230 mAuthUtilitiesMenu->addAction( mActionExportSelectedAuthenticationConfigs );
231 mAuthUtilitiesMenu->addSeparator();
232 mAuthUtilitiesMenu->addAction( mActionEraseAuthDatabase );
233
234 btnAuthUtilities->setMenu( mAuthUtilitiesMenu );
235}
236
237void QgsAuthEditorWidgets::importAuthenticationConfigs()
238{
240}
241
242void QgsAuthEditorWidgets::exportSelectedAuthenticationConfigs()
243{
244 if ( !wdgtConfigEditor )
245 return;
246
247 QgsAuthGuiUtils::exportSelectedAuthenticationConfigs( wdgtConfigEditor->selectedAuthenticationConfigIds(), messageBar() );
248}
249
250void QgsAuthEditorWidgets::setMasterPassword()
251{
253}
254
255void QgsAuthEditorWidgets::clearCachedMasterPassword()
256{
258}
259
260void QgsAuthEditorWidgets::resetMasterPassword()
261{
262 QgsAuthGuiUtils::resetMasterPassword( messageBar(), this );
263}
264
265void QgsAuthEditorWidgets::clearCachedAuthenticationConfigs()
266{
268}
269
270void QgsAuthEditorWidgets::removeAuthenticationConfigs()
271{
273}
274
275void QgsAuthEditorWidgets::eraseAuthenticationDatabase()
276{
278}
279
280void QgsAuthEditorWidgets::authMessageLog( const QString &message, const QString &authtag, Qgis::MessageLevel level )
281{
282 messageBar()->clearWidgets();
283 messageBar()->pushMessage( authtag, message, level );
284}
285
286void QgsAuthEditorWidgets::passwordHelperDelete()
287{
288 QgsAuthGuiUtils::passwordHelperDelete( messageBar(), this );
289}
290
291void QgsAuthEditorWidgets::passwordHelperEnableTriggered()
292{
293 // Only fire on real changes
294 QgsAuthGuiUtils::passwordHelperEnable( mActionPasswordHelperEnable->isChecked(), messageBar() );
295}
296
297void QgsAuthEditorWidgets::passwordHelperLoggingEnableTriggered()
298{
299 QgsAuthGuiUtils::passwordHelperLoggingEnable( mActionPasswordHelperLoggingEnable->isChecked(), messageBar() );
300}
301
302QgsMessageBar *QgsAuthEditorWidgets::messageBar()
303{
304 return mMsgBar;
305}
MessageLevel
Level for messages This will be used both for message log and message bar in application.
Definition qgis.h:156
static QgsAuthManager * authManager()
Returns the application's authentication manager instance.
Dialog wrapper for widget to manage available certificate editors.
virtual bool isReadOnly() const
Returns true if the storage is read-only, false otherwise.
QgsAuthEditorWidgets(QWidget *parent=nullptr)
Construct a widget to contain various authentication editors.
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 void resetMasterPassword(QgsMessageBar *msgbar, QWidget *parent=nullptr)
Reset the cached master password, updating its hash in authentication database and resetting all exis...
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 void clearCachedAuthenticationConfigs(QgsMessageBar *msgbar)
Clear all cached authentication configs for session.
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 void setMasterPassword(QgsMessageBar *msgbar)
Sets the cached master password (and verifies it if its hash is in authentication database).
static void passwordHelperDelete(QgsMessageBar *msgbar, QWidget *parent=nullptr)
Remove master password from wallet.
QgsAuthConfigurationStorageDb * defaultDbStorage() const
Transitional proxy to the first ready storage of database type.
void messageLog(const QString &message, const QString &tag=QgsAuthManager::AUTH_MAN_TAG, Qgis::MessageLevel level=Qgis::MessageLevel::Info) const
Custom logging signal to relay to console output and QgsMessageLog.
QgsAuthMethod * authMethod(const QString &authMethodKey)
Gets authentication method from the config/provider cache via its key.
QStringList authMethodsKeys(const QString &dataprovider=QString())
Gets keys of supported authentication methods.
const QgsAuthMethodMetadata * authMethodMetadata(const QString &authMethodKey)
Gets authentication method metadata via its key.
static QString passwordHelperDisplayName(bool titleCase=false)
Returns a translated display name of the password helper (platform dependent).
QString description() const
Returns descriptive text for the method.
QString key() const
Returns the unique key associated with the method.
QgsAuthMethodPlugins(QWidget *parent=nullptr)
Construct a dialog for viewing available authentication method plugins.
QStringList supportedDataProviders() const
The data providers that the method supports, allowing for filtering out authcfgs that are not applica...
static void openHelp(const QString &key)
Opens help topic for the given help key using default system web browser.
Definition qgshelp.cpp:38
A bar for displaying non-blocking messages to the user.
static QgsNetworkAccessManager * instance(Qt::ConnectionType connectionType=Qt::BlockingQueuedConnection)
Returns a pointer to the active QgsNetworkAccessManager for the current thread.
#define QgsDebugError(str)
Definition qgslogger.h:57