QGIS API Documentation 3.39.0-Master (d85f3c2a281)
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
19#include "ui_qgsauthmethodplugins.h"
20
21#include <QAction>
22#include <QMenu>
23#include <QWidget>
24#include <QTableWidget>
25
26#include "qgssettings.h"
28#include "qgsauthguiutils.h"
29#include "qgsauthmanager.h"
30#include "qgsapplication.h"
33
34
36 : QDialog( parent )
37
38{
39 if ( QgsApplication::authManager()->isDisabled() )
40 {
41 mAuthNotifyLayout = new QVBoxLayout;
42 this->setLayout( mAuthNotifyLayout );
43 mAuthNotify = new QLabel( QgsApplication::authManager()->disabledMessage(), this );
44 mAuthNotifyLayout->addWidget( mAuthNotify );
45 }
46 else
47 {
48 setupUi( this );
49 connect( buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject );
50
51 setupTable();
52 populateTable();
53 }
54}
55
56void QgsAuthMethodPlugins::setupTable()
57{
58 tblAuthPlugins->setColumnCount( 3 );
59 tblAuthPlugins->verticalHeader()->hide();
60 tblAuthPlugins->horizontalHeader()->setVisible( true );
61 tblAuthPlugins->setHorizontalHeaderItem( 0, new QTableWidgetItem( tr( "Method" ) ) );
62 tblAuthPlugins->setHorizontalHeaderItem( 1, new QTableWidgetItem( tr( "Description" ) ) );
63 tblAuthPlugins->setHorizontalHeaderItem( 2, new QTableWidgetItem( tr( "Works with" ) ) );
64 tblAuthPlugins->horizontalHeader()->setStretchLastSection( true );
65 tblAuthPlugins->setAlternatingRowColors( true );
66 tblAuthPlugins->setColumnWidth( 0, 150 );
67 tblAuthPlugins->setColumnWidth( 1, 300 );
68 tblAuthPlugins->setRowCount( QgsApplication::authManager()->authMethodsKeys().size() );
69 tblAuthPlugins->verticalHeader()->setSectionResizeMode( QHeaderView::ResizeToContents );
70 tblAuthPlugins->setSortingEnabled( true );
71 tblAuthPlugins->setSelectionBehavior( QAbstractItemView::SelectRows );
72}
73
74void QgsAuthMethodPlugins::populateTable()
75{
76 const QStringList authMethodKeys = QgsApplication::authManager()->authMethodsKeys();
77
78 int i = 0;
79 const auto constAuthMethodKeys = authMethodKeys;
80 for ( const QString &authMethodKey : constAuthMethodKeys )
81 {
83 const QgsAuthMethod *method = QgsApplication::authManager()->authMethod( authMethodKey );
84 if ( !meta || !method )
85 {
86 QgsDebugError( QStringLiteral( "Load auth method instance FAILED for auth method key (%1)" ).arg( authMethodKey ) );
87 continue;
88 }
89
90 QTableWidgetItem *twi = new QTableWidgetItem( meta->key() );
91 twi->setFlags( twi->flags() & ~Qt::ItemIsEditable );
92 tblAuthPlugins->setItem( i, 0, twi );
93
94 twi = new QTableWidgetItem( meta->description() );
95 twi->setFlags( twi->flags() & ~Qt::ItemIsEditable );
96 tblAuthPlugins->setItem( i, 1, twi );
97
98 twi = new QTableWidgetItem( method->supportedDataProviders().join( QLatin1String( ", " ) ) );
99 twi->setFlags( twi->flags() & ~Qt::ItemIsEditable );
100 tblAuthPlugins->setItem( i, 2, twi );
101
102 i++;
103 }
104 tblAuthPlugins->sortItems( 0 );
105}
106
107
108
110 : QWidget( parent )
111
112{
113 setupUi( this );
114 connect( btnCertManager, &QPushButton::clicked, this, &QgsAuthEditorWidgets::btnCertManager_clicked );
115 connect( btnAuthPlugins, &QPushButton::clicked, this, &QgsAuthEditorWidgets::btnAuthPlugins_clicked );
116 if ( !QgsApplication::authManager()->isDisabled() )
117 {
118 wdgtConfigEditor->setRelayMessages( false );
119 wdgtConfigEditor->setShowUtilitiesButton( false );
120 setupUtilitiesMenu();
121 }
122 else
123 {
124 grpbxManagers->setEnabled( false );
125 }
126}
127
128void QgsAuthEditorWidgets::btnCertManager_clicked()
129{
130 QgsAuthCertManager *dlg = new QgsAuthCertManager( this );
131 dlg->setWindowModality( Qt::ApplicationModal );
132 dlg->resize( 750, 500 );
133 dlg->exec();
134 dlg->deleteLater();
135}
136
137void QgsAuthEditorWidgets::btnAuthPlugins_clicked()
138{
140 dlg->setWindowModality( Qt::WindowModal );
141 dlg->resize( 675, 500 );
142 dlg->exec();
143 dlg->deleteLater();
144}
145
146void QgsAuthEditorWidgets::setupUtilitiesMenu()
147{
149 this, &QgsAuthEditorWidgets::authMessageLog );
150
152
153 // set up utility actions menu
154 mActionImportAuthenticationConfigs = new QAction( tr( "Import Authentication Configurations from File…" ), this );
155 mActionExportSelectedAuthenticationConfigs = new QAction( tr( "Export Selected Authentication Configurations to File…" ), this );
156 mActionSetMasterPassword = new QAction( tr( "Input Master Password…" ), this );
157 mActionClearCachedMasterPassword = new QAction( tr( "Clear Cached Master Password" ), this );
158 mActionResetMasterPassword = new QAction( tr( "Reset Master Password…" ), this );
159 mActionClearCachedAuthConfigs = new QAction( tr( "Clear Cached Authentication Configurations" ), this );
160 mActionRemoveAuthConfigs = new QAction( tr( "Remove all Authentication Configurations…" ), this );
161 mActionEraseAuthDatabase = new QAction( tr( "Erase Authentication Database…" ), this );
162
163 mActionClearAccessCacheNow = new QAction( tr( "Clear Network Authentication Access Cache" ), this );
164 mActionAutoClearAccessCache = new QAction( tr( "Automatically Clear Network Authentication Access Cache on SSL Errors" ), this );
165 mActionAutoClearAccessCache->setCheckable( true );
166 mActionAutoClearAccessCache->setChecked( QgsSettings().value( QStringLiteral( "clear_auth_cache_on_errors" ), true, QgsSettings::Section::Auth ).toBool( ) );
167
168 mActionPasswordHelperSync = new QAction( tr( "Store/update the Master Password in your %1" )
170 mActionPasswordHelperDelete = new QAction( tr( "Clear the Master Password from your %1…" )
172 mActionPasswordHelperEnable = new QAction( tr( "Integrate Master Password with your %1" )
174 mActionPasswordHelperLoggingEnable = new QAction( tr( "Enable Password Helper Debug Log" ), this );
175
176 mActionPasswordHelperEnable->setCheckable( true );
177 mActionPasswordHelperEnable->setChecked( QgsApplication::authManager()->passwordHelperEnabled() );
178
179 mActionPasswordHelperLoggingEnable->setCheckable( true );
180 mActionPasswordHelperLoggingEnable->setChecked( QgsApplication::authManager()->passwordHelperLoggingEnabled() );
181
182 if ( ! isReadOnly )
183 {
184 connect( mActionImportAuthenticationConfigs, &QAction::triggered, this, &QgsAuthEditorWidgets::importAuthenticationConfigs );
185 connect( mActionResetMasterPassword, &QAction::triggered, this, &QgsAuthEditorWidgets::resetMasterPassword );
186 connect( mActionRemoveAuthConfigs, &QAction::triggered, this, &QgsAuthEditorWidgets::removeAuthenticationConfigs );
187 connect( mActionEraseAuthDatabase, &QAction::triggered, this, &QgsAuthEditorWidgets::eraseAuthenticationDatabase );
188 }
189 else
190 {
191 mActionImportAuthenticationConfigs->setEnabled( false );
192 mActionResetMasterPassword->setEnabled( false );
193 mActionRemoveAuthConfigs->setEnabled( false );
194 mActionEraseAuthDatabase->setEnabled( false );
195 }
196
197 connect( mActionExportSelectedAuthenticationConfigs, &QAction::triggered, this, &QgsAuthEditorWidgets::exportSelectedAuthenticationConfigs );
198 connect( mActionSetMasterPassword, &QAction::triggered, this, &QgsAuthEditorWidgets::setMasterPassword );
199 connect( mActionClearCachedMasterPassword, &QAction::triggered, this, &QgsAuthEditorWidgets::clearCachedMasterPassword );
200 connect( mActionClearCachedAuthConfigs, &QAction::triggered, this, &QgsAuthEditorWidgets::clearCachedAuthenticationConfigs );
201
202 connect( mActionPasswordHelperSync, &QAction::triggered, this, &QgsAuthEditorWidgets::passwordHelperSync );
203 connect( mActionPasswordHelperDelete, &QAction::triggered, this, &QgsAuthEditorWidgets::passwordHelperDelete );
204 connect( mActionPasswordHelperEnable, &QAction::triggered, this, &QgsAuthEditorWidgets::passwordHelperEnableTriggered );
205 connect( mActionPasswordHelperLoggingEnable, &QAction::triggered, this, &QgsAuthEditorWidgets::passwordHelperLoggingEnableTriggered );
206
207 connect( mActionClearAccessCacheNow, &QAction::triggered, this, [ = ]
208 {
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 {
215 QgsSettings().setValue( QStringLiteral( "clear_auth_cache_on_errors" ), checked, QgsSettings::Section::Auth );
216 } );
217
218 mAuthUtilitiesMenu = new QMenu( this );
219 mAuthUtilitiesMenu->addAction( mActionSetMasterPassword );
220 mAuthUtilitiesMenu->addAction( mActionClearCachedMasterPassword );
221 mAuthUtilitiesMenu->addAction( mActionResetMasterPassword );
222 mAuthUtilitiesMenu->addSeparator();
223 mAuthUtilitiesMenu->addAction( mActionClearAccessCacheNow );
224 mAuthUtilitiesMenu->addAction( mActionAutoClearAccessCache );
225 mAuthUtilitiesMenu->addSeparator();
226 mAuthUtilitiesMenu->addAction( mActionPasswordHelperEnable );
227 mAuthUtilitiesMenu->addAction( mActionPasswordHelperSync );
228 mAuthUtilitiesMenu->addAction( mActionPasswordHelperDelete );
229 mAuthUtilitiesMenu->addAction( mActionPasswordHelperLoggingEnable );
230 mAuthUtilitiesMenu->addSeparator();
231 mAuthUtilitiesMenu->addAction( mActionClearCachedAuthConfigs );
232 mAuthUtilitiesMenu->addAction( mActionRemoveAuthConfigs );
233 mAuthUtilitiesMenu->addSeparator();
234 mAuthUtilitiesMenu->addAction( mActionImportAuthenticationConfigs );
235 mAuthUtilitiesMenu->addAction( mActionExportSelectedAuthenticationConfigs );
236 mAuthUtilitiesMenu->addSeparator();
237 mAuthUtilitiesMenu->addAction( mActionEraseAuthDatabase );
238
239 btnAuthUtilities->setMenu( mAuthUtilitiesMenu );
240}
241
242void QgsAuthEditorWidgets::importAuthenticationConfigs()
243{
245}
246
247void QgsAuthEditorWidgets::exportSelectedAuthenticationConfigs()
248{
249 if ( !wdgtConfigEditor )
250 return;
251
252 QgsAuthGuiUtils::exportSelectedAuthenticationConfigs( wdgtConfigEditor->selectedAuthenticationConfigIds(), messageBar() );
253}
254
255void QgsAuthEditorWidgets::setMasterPassword()
256{
258}
259
260void QgsAuthEditorWidgets::clearCachedMasterPassword()
261{
263}
264
265void QgsAuthEditorWidgets::resetMasterPassword()
266{
267 QgsAuthGuiUtils::resetMasterPassword( messageBar(), this );
268}
269
270void QgsAuthEditorWidgets::clearCachedAuthenticationConfigs()
271{
273}
274
275void QgsAuthEditorWidgets::removeAuthenticationConfigs()
276{
278}
279
280void QgsAuthEditorWidgets::eraseAuthenticationDatabase()
281{
283}
284
285void QgsAuthEditorWidgets::authMessageLog( const QString &message, const QString &authtag, Qgis::MessageLevel level )
286{
287 messageBar()->clearWidgets();
288 messageBar()->pushMessage( authtag, message, level );
289}
290
291void QgsAuthEditorWidgets::passwordHelperDelete()
292{
293 QgsAuthGuiUtils::passwordHelperDelete( messageBar(), this );
294}
295
296void QgsAuthEditorWidgets::passwordHelperSync()
297{
299}
300
301void QgsAuthEditorWidgets::passwordHelperEnableTriggered()
302{
303 // Only fire on real changes
304 QgsAuthGuiUtils::passwordHelperEnable( mActionPasswordHelperEnable->isChecked(), messageBar() );
305}
306
307void QgsAuthEditorWidgets::passwordHelperLoggingEnableTriggered()
308{
309 QgsAuthGuiUtils::passwordHelperLoggingEnable( mActionPasswordHelperLoggingEnable->isChecked(), messageBar() );
310}
311
312QgsMessageBar *QgsAuthEditorWidgets::messageBar()
313{
314 return mMsgBar;
315}
316
MessageLevel
Level for messages This will be used both for message log and message bar in application.
Definition qgis.h:154
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.
static void passwordHelperSync(QgsMessageBar *msgbar)
Store master password into the 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.
static const QString AUTH_PASSWORD_HELPER_DISPLAY_NAME
The display name of the password helper (platform dependent)
const QgsAuthMethodMetadata * authMethodMetadata(const QString &authMethodKey)
Gets authentication method metadata via its key.
Holds data auth method key, description, and associated shared library file information.
QString description() const
Returns descriptive text for the method.
QString key() const
Returns the unique key associated with the method.
Dialog for viewing available authentication method plugins.
QgsAuthMethodPlugins(QWidget *parent=nullptr)
Construct a dialog for viewing available authentication method plugins.
Abstract base class for authentication method plugins.
QStringList supportedDataProviders() const
The data providers that the method supports, allowing for filtering out authcfgs that are not applica...
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.
void pushSuccess(const QString &title, const QString &message)
Pushes a success message with default timeout to the message bar.
bool clearWidgets()
Removes all items from the bar.
static QgsNetworkAccessManager * instance(Qt::ConnectionType connectionType=Qt::BlockingQueuedConnection)
Returns a pointer to the active QgsNetworkAccessManager for the current thread.
This class is a composition of two QSettings instances:
Definition qgssettings.h:64
void setValue(const QString &key, const QVariant &value, QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.
#define QgsDebugError(str)
Definition qgslogger.h:38