QGIS API Documentation 3.99.0-Master (8e76e220402)
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 <QString>
33#include <QTableWidget>
34#include <QWidget>
35
36#include "moc_qgsautheditorwidgets.cpp"
37
38using namespace Qt::StringLiterals;
39
41 : QDialog( parent )
42
43{
44 if ( QgsApplication::authManager()->isDisabled() )
45 {
46 mAuthNotifyLayout = new QVBoxLayout;
47 this->setLayout( mAuthNotifyLayout );
48 mAuthNotify = new QLabel( QgsApplication::authManager()->disabledMessage(), this );
49 mAuthNotifyLayout->addWidget( mAuthNotify );
50 }
51 else
52 {
53 setupUi( this );
54 connect( buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject );
55 connect( buttonBox, &QDialogButtonBox::helpRequested, this, [] {
56 QgsHelp::openHelp( u"auth_system/auth_overview.html#authentication-methods"_s );
57 } );
58
59 setupTable();
60 populateTable();
61 }
62}
63
64void QgsAuthMethodPlugins::setupTable()
65{
66 tblAuthPlugins->setColumnCount( 3 );
67 tblAuthPlugins->verticalHeader()->hide();
68 tblAuthPlugins->horizontalHeader()->setVisible( true );
69 tblAuthPlugins->setHorizontalHeaderItem( 0, new QTableWidgetItem( tr( "Method" ) ) );
70 tblAuthPlugins->setHorizontalHeaderItem( 1, new QTableWidgetItem( tr( "Description" ) ) );
71 tblAuthPlugins->setHorizontalHeaderItem( 2, new QTableWidgetItem( tr( "Works with" ) ) );
72 tblAuthPlugins->horizontalHeader()->setStretchLastSection( true );
73 tblAuthPlugins->setAlternatingRowColors( true );
74 tblAuthPlugins->setColumnWidth( 0, 150 );
75 tblAuthPlugins->setColumnWidth( 1, 300 );
76 tblAuthPlugins->setRowCount( QgsApplication::authManager()->authMethodsKeys().size() );
77 tblAuthPlugins->verticalHeader()->setSectionResizeMode( QHeaderView::ResizeToContents );
78 tblAuthPlugins->setSortingEnabled( true );
79 tblAuthPlugins->setSelectionBehavior( QAbstractItemView::SelectRows );
80}
81
82void QgsAuthMethodPlugins::populateTable()
83{
84 const QStringList authMethodKeys = QgsApplication::authManager()->authMethodsKeys();
85
86 int i = 0;
87 const auto constAuthMethodKeys = authMethodKeys;
88 for ( const QString &authMethodKey : constAuthMethodKeys )
89 {
90 const QgsAuthMethodMetadata *meta = QgsApplication::authManager()->authMethodMetadata( authMethodKey );
91 const QgsAuthMethod *method = QgsApplication::authManager()->authMethod( authMethodKey );
92 if ( !meta || !method )
93 {
94 QgsDebugError( u"Load auth method instance FAILED for auth method key (%1)"_s.arg( authMethodKey ) );
95 continue;
96 }
97
98 QTableWidgetItem *twi = new QTableWidgetItem( meta->key() );
99 twi->setFlags( twi->flags() & ~Qt::ItemIsEditable );
100 tblAuthPlugins->setItem( i, 0, twi );
101
102 twi = new QTableWidgetItem( meta->description() );
103 twi->setFlags( twi->flags() & ~Qt::ItemIsEditable );
104 tblAuthPlugins->setItem( i, 1, twi );
105
106 twi = new QTableWidgetItem( method->supportedDataProviders().join( ", "_L1 ) );
107 twi->setFlags( twi->flags() & ~Qt::ItemIsEditable );
108 tblAuthPlugins->setItem( i, 2, twi );
109
110 i++;
111 }
112 tblAuthPlugins->sortItems( 0 );
113}
114
115
117 : QWidget( parent )
118
119{
120 setupUi( this );
121 connect( btnCertManager, &QPushButton::clicked, this, &QgsAuthEditorWidgets::btnCertManager_clicked );
122 connect( btnAuthPlugins, &QPushButton::clicked, this, &QgsAuthEditorWidgets::btnAuthPlugins_clicked );
123 if ( !QgsApplication::authManager()->isDisabled() )
124 {
125 wdgtConfigEditor->setRelayMessages( false );
126 wdgtConfigEditor->setShowUtilitiesButton( false );
127 setupUtilitiesMenu();
128 }
129 else
130 {
131 grpbxManagers->setEnabled( false );
132 }
133}
134
135void QgsAuthEditorWidgets::btnCertManager_clicked()
136{
137 QgsAuthCertManager *dlg = new QgsAuthCertManager( this );
138 dlg->setWindowModality( Qt::ApplicationModal );
139 dlg->resize( 750, 500 );
140 dlg->exec();
141 dlg->deleteLater();
142}
143
144void QgsAuthEditorWidgets::btnAuthPlugins_clicked()
145{
146 QgsAuthMethodPlugins *dlg = new QgsAuthMethodPlugins( this );
147 dlg->setWindowModality( Qt::WindowModal );
148 dlg->resize( 675, 500 );
149 dlg->exec();
150 dlg->deleteLater();
151}
152
153void QgsAuthEditorWidgets::setupUtilitiesMenu()
154{
155 connect( QgsApplication::authManager(), &QgsAuthManager::messageLog, this, &QgsAuthEditorWidgets::authMessageLog );
156
158
159 // set up utility actions menu
160 mActionImportAuthenticationConfigs = new QAction( tr( "Import Authentication Configurations from File…" ), this );
161 mActionExportSelectedAuthenticationConfigs = new QAction( tr( "Export Selected Authentication Configurations to File…" ), this );
162 mActionSetMasterPassword = new QAction( tr( "Input Master Password…" ), this );
163 mActionClearCachedMasterPassword = new QAction( tr( "Clear Cached Master Password" ), this );
164 mActionResetMasterPassword = new QAction( tr( "Reset Master Password…" ), this );
165 mActionClearCachedAuthConfigs = new QAction( tr( "Clear Cached Authentication Configurations" ), this );
166 mActionRemoveAuthConfigs = new QAction( tr( "Remove all Authentication Configurations…" ), this );
167 mActionEraseAuthDatabase = new QAction( tr( "Erase Authentication Database…" ), this );
168
169 mActionClearAccessCacheNow = new QAction( tr( "Clear Network Authentication Access Cache" ), this );
170 mActionAutoClearAccessCache = new QAction( tr( "Automatically Clear Network Authentication Access Cache on SSL Errors" ), this );
171 mActionAutoClearAccessCache->setCheckable( true );
172 mActionAutoClearAccessCache->setChecked( QgsSettings().value( u"clear_auth_cache_on_errors"_s, true, QgsSettings::Section::Auth ).toBool() );
173
174 mActionPasswordHelperDelete = new QAction( tr( "Clear the Master Password from the %1…" ).arg( QgsAuthManager::passwordHelperDisplayName( true ) ), this );
175 mActionPasswordHelperEnable = new QAction( tr( "Integrate Master Password with the %1" ).arg( QgsAuthManager::passwordHelperDisplayName( true ) ), this );
176 mActionPasswordHelperLoggingEnable = new QAction( tr( "Enable Password Helper Debug Log" ), this );
177
178 mActionPasswordHelperEnable->setCheckable( true );
179 mActionPasswordHelperEnable->setChecked( QgsApplication::authManager()->passwordHelperEnabled() );
180
181 mActionPasswordHelperLoggingEnable->setCheckable( true );
182 mActionPasswordHelperLoggingEnable->setChecked( QgsApplication::authManager()->passwordHelperLoggingEnabled() );
183
184 if ( !isReadOnly )
185 {
186 connect( mActionImportAuthenticationConfigs, &QAction::triggered, this, &QgsAuthEditorWidgets::importAuthenticationConfigs );
187 connect( mActionResetMasterPassword, &QAction::triggered, this, &QgsAuthEditorWidgets::resetMasterPassword );
188 connect( mActionRemoveAuthConfigs, &QAction::triggered, this, &QgsAuthEditorWidgets::removeAuthenticationConfigs );
189 connect( mActionEraseAuthDatabase, &QAction::triggered, this, &QgsAuthEditorWidgets::eraseAuthenticationDatabase );
190 }
191 else
192 {
193 mActionImportAuthenticationConfigs->setEnabled( false );
194 mActionResetMasterPassword->setEnabled( false );
195 mActionRemoveAuthConfigs->setEnabled( false );
196 mActionEraseAuthDatabase->setEnabled( false );
197 }
198
199 connect( mActionExportSelectedAuthenticationConfigs, &QAction::triggered, this, &QgsAuthEditorWidgets::exportSelectedAuthenticationConfigs );
200 connect( mActionSetMasterPassword, &QAction::triggered, this, &QgsAuthEditorWidgets::setMasterPassword );
201 connect( mActionClearCachedMasterPassword, &QAction::triggered, this, &QgsAuthEditorWidgets::clearCachedMasterPassword );
202 connect( mActionClearCachedAuthConfigs, &QAction::triggered, this, &QgsAuthEditorWidgets::clearCachedAuthenticationConfigs );
203
204 connect( mActionPasswordHelperDelete, &QAction::triggered, this, &QgsAuthEditorWidgets::passwordHelperDelete );
205 connect( mActionPasswordHelperEnable, &QAction::triggered, this, &QgsAuthEditorWidgets::passwordHelperEnableTriggered );
206 connect( mActionPasswordHelperLoggingEnable, &QAction::triggered, this, &QgsAuthEditorWidgets::passwordHelperLoggingEnableTriggered );
207
208 connect( mActionClearAccessCacheNow, &QAction::triggered, this, [this] {
209 QgsNetworkAccessManager::instance()->clearAccessCache();
210 messageBar()->clearWidgets();
211 messageBar()->pushSuccess( tr( "Auth cache cleared" ), tr( "Network authentication cache has been cleared" ) );
212 } );
213 connect( mActionAutoClearAccessCache, &QAction::triggered, this, []( bool checked ) {
214 QgsSettings().setValue( u"clear_auth_cache_on_errors"_s, checked, QgsSettings::Section::Auth );
215 } );
216
217 mAuthUtilitiesMenu = new QMenu( this );
218 mAuthUtilitiesMenu->addAction( mActionSetMasterPassword );
219 mAuthUtilitiesMenu->addAction( mActionClearCachedMasterPassword );
220 mAuthUtilitiesMenu->addAction( mActionResetMasterPassword );
221 mAuthUtilitiesMenu->addSeparator();
222 mAuthUtilitiesMenu->addAction( mActionClearAccessCacheNow );
223 mAuthUtilitiesMenu->addAction( mActionAutoClearAccessCache );
224 mAuthUtilitiesMenu->addSeparator();
225 mAuthUtilitiesMenu->addAction( mActionPasswordHelperEnable );
226 mAuthUtilitiesMenu->addAction( mActionPasswordHelperDelete );
227 mAuthUtilitiesMenu->addAction( mActionPasswordHelperLoggingEnable );
228 mAuthUtilitiesMenu->addSeparator();
229 mAuthUtilitiesMenu->addAction( mActionClearCachedAuthConfigs );
230 mAuthUtilitiesMenu->addAction( mActionRemoveAuthConfigs );
231 mAuthUtilitiesMenu->addSeparator();
232 mAuthUtilitiesMenu->addAction( mActionImportAuthenticationConfigs );
233 mAuthUtilitiesMenu->addAction( mActionExportSelectedAuthenticationConfigs );
234 mAuthUtilitiesMenu->addSeparator();
235 mAuthUtilitiesMenu->addAction( mActionEraseAuthDatabase );
236
237 btnAuthUtilities->setMenu( mAuthUtilitiesMenu );
238}
239
240void QgsAuthEditorWidgets::importAuthenticationConfigs()
241{
243}
244
245void QgsAuthEditorWidgets::exportSelectedAuthenticationConfigs()
246{
247 if ( !wdgtConfigEditor )
248 return;
249
250 QgsAuthGuiUtils::exportSelectedAuthenticationConfigs( wdgtConfigEditor->selectedAuthenticationConfigIds(), messageBar() );
251}
252
253void QgsAuthEditorWidgets::setMasterPassword()
254{
256}
257
258void QgsAuthEditorWidgets::clearCachedMasterPassword()
259{
261}
262
263void QgsAuthEditorWidgets::resetMasterPassword()
264{
265 QgsAuthGuiUtils::resetMasterPassword( messageBar(), this );
266}
267
268void QgsAuthEditorWidgets::clearCachedAuthenticationConfigs()
269{
271}
272
273void QgsAuthEditorWidgets::removeAuthenticationConfigs()
274{
276}
277
278void QgsAuthEditorWidgets::eraseAuthenticationDatabase()
279{
281}
282
283void QgsAuthEditorWidgets::authMessageLog( const QString &message, const QString &authtag, Qgis::MessageLevel level )
284{
285 messageBar()->clearWidgets();
286 messageBar()->pushMessage( authtag, message, level );
287}
288
289void QgsAuthEditorWidgets::passwordHelperDelete()
290{
291 QgsAuthGuiUtils::passwordHelperDelete( messageBar(), this );
292}
293
294void QgsAuthEditorWidgets::passwordHelperEnableTriggered()
295{
296 // Only fire on real changes
297 QgsAuthGuiUtils::passwordHelperEnable( mActionPasswordHelperEnable->isChecked(), messageBar() );
298}
299
300void QgsAuthEditorWidgets::passwordHelperLoggingEnableTriggered()
301{
302 QgsAuthGuiUtils::passwordHelperLoggingEnable( mActionPasswordHelperLoggingEnable->isChecked(), messageBar() );
303}
304
305QgsMessageBar *QgsAuthEditorWidgets::messageBar()
306{
307 return mMsgBar;
308}
MessageLevel
Level for messages This will be used both for message log and message bar in application.
Definition qgis.h:159
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:41
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:59