QGIS API Documentation 3.41.0-Master (cea29feecf2)
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
18#include "moc_qgsautheditorwidgets.cpp"
20#include "ui_qgsauthmethodplugins.h"
21
22#include <QAction>
23#include <QMenu>
24#include <QWidget>
25#include <QTableWidget>
26
27#include "qgssettings.h"
29#include "qgsauthguiutils.h"
30#include "qgsauthmanager.h"
31#include "qgsapplication.h"
34
35
37 : QDialog( parent )
38
39{
40 if ( QgsApplication::authManager()->isDisabled() )
41 {
42 mAuthNotifyLayout = new QVBoxLayout;
43 this->setLayout( mAuthNotifyLayout );
44 mAuthNotify = new QLabel( QgsApplication::authManager()->disabledMessage(), this );
45 mAuthNotifyLayout->addWidget( mAuthNotify );
46 }
47 else
48 {
49 setupUi( this );
50 connect( buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject );
51
52 setupTable();
53 populateTable();
54 }
55}
56
57void QgsAuthMethodPlugins::setupTable()
58{
59 tblAuthPlugins->setColumnCount( 3 );
60 tblAuthPlugins->verticalHeader()->hide();
61 tblAuthPlugins->horizontalHeader()->setVisible( true );
62 tblAuthPlugins->setHorizontalHeaderItem( 0, new QTableWidgetItem( tr( "Method" ) ) );
63 tblAuthPlugins->setHorizontalHeaderItem( 1, new QTableWidgetItem( tr( "Description" ) ) );
64 tblAuthPlugins->setHorizontalHeaderItem( 2, new QTableWidgetItem( tr( "Works with" ) ) );
65 tblAuthPlugins->horizontalHeader()->setStretchLastSection( true );
66 tblAuthPlugins->setAlternatingRowColors( true );
67 tblAuthPlugins->setColumnWidth( 0, 150 );
68 tblAuthPlugins->setColumnWidth( 1, 300 );
69 tblAuthPlugins->setRowCount( QgsApplication::authManager()->authMethodsKeys().size() );
70 tblAuthPlugins->verticalHeader()->setSectionResizeMode( QHeaderView::ResizeToContents );
71 tblAuthPlugins->setSortingEnabled( true );
72 tblAuthPlugins->setSelectionBehavior( QAbstractItemView::SelectRows );
73}
74
75void QgsAuthMethodPlugins::populateTable()
76{
77 const QStringList authMethodKeys = QgsApplication::authManager()->authMethodsKeys();
78
79 int i = 0;
80 const auto constAuthMethodKeys = authMethodKeys;
81 for ( const QString &authMethodKey : constAuthMethodKeys )
82 {
84 const QgsAuthMethod *method = QgsApplication::authManager()->authMethod( authMethodKey );
85 if ( !meta || !method )
86 {
87 QgsDebugError( QStringLiteral( "Load auth method instance FAILED for auth method key (%1)" ).arg( authMethodKey ) );
88 continue;
89 }
90
91 QTableWidgetItem *twi = new QTableWidgetItem( meta->key() );
92 twi->setFlags( twi->flags() & ~Qt::ItemIsEditable );
93 tblAuthPlugins->setItem( i, 0, twi );
94
95 twi = new QTableWidgetItem( meta->description() );
96 twi->setFlags( twi->flags() & ~Qt::ItemIsEditable );
97 tblAuthPlugins->setItem( i, 1, twi );
98
99 twi = new QTableWidgetItem( method->supportedDataProviders().join( QLatin1String( ", " ) ) );
100 twi->setFlags( twi->flags() & ~Qt::ItemIsEditable );
101 tblAuthPlugins->setItem( i, 2, twi );
102
103 i++;
104 }
105 tblAuthPlugins->sortItems( 0 );
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{
148 connect( QgsApplication::authManager(), &QgsAuthManager::messageLog, this, &QgsAuthEditorWidgets::authMessageLog );
149
151
152 // set up utility actions menu
153 mActionImportAuthenticationConfigs = new QAction( tr( "Import Authentication Configurations from File…" ), this );
154 mActionExportSelectedAuthenticationConfigs = new QAction( tr( "Export Selected Authentication Configurations to File…" ), this );
155 mActionSetMasterPassword = new QAction( tr( "Input Master Password…" ), this );
156 mActionClearCachedMasterPassword = new QAction( tr( "Clear Cached Master Password" ), this );
157 mActionResetMasterPassword = new QAction( tr( "Reset Master Password…" ), this );
158 mActionClearCachedAuthConfigs = new QAction( tr( "Clear Cached Authentication Configurations" ), this );
159 mActionRemoveAuthConfigs = new QAction( tr( "Remove all Authentication Configurations…" ), this );
160 mActionEraseAuthDatabase = new QAction( tr( "Erase Authentication Database…" ), this );
161
162 mActionClearAccessCacheNow = new QAction( tr( "Clear Network Authentication Access Cache" ), this );
163 mActionAutoClearAccessCache = new QAction( tr( "Automatically Clear Network Authentication Access Cache on SSL Errors" ), this );
164 mActionAutoClearAccessCache->setCheckable( true );
165 mActionAutoClearAccessCache->setChecked( QgsSettings().value( QStringLiteral( "clear_auth_cache_on_errors" ), true, QgsSettings::Section::Auth ).toBool() );
166
167 mActionPasswordHelperSync = new QAction( tr( "Store/update the Master Password in your %1" ).arg( QgsAuthManager::AUTH_PASSWORD_HELPER_DISPLAY_NAME ), this );
168 mActionPasswordHelperDelete = new QAction( tr( "Clear the Master Password from your %1…" ).arg( QgsAuthManager::AUTH_PASSWORD_HELPER_DISPLAY_NAME ), this );
169 mActionPasswordHelperEnable = new QAction( tr( "Integrate Master Password with your %1" ).arg( QgsAuthManager::AUTH_PASSWORD_HELPER_DISPLAY_NAME ), this );
170 mActionPasswordHelperLoggingEnable = new QAction( tr( "Enable Password Helper Debug Log" ), this );
171
172 mActionPasswordHelperEnable->setCheckable( true );
173 mActionPasswordHelperEnable->setChecked( QgsApplication::authManager()->passwordHelperEnabled() );
174
175 mActionPasswordHelperLoggingEnable->setCheckable( true );
176 mActionPasswordHelperLoggingEnable->setChecked( QgsApplication::authManager()->passwordHelperLoggingEnabled() );
177
178 if ( !isReadOnly )
179 {
180 connect( mActionImportAuthenticationConfigs, &QAction::triggered, this, &QgsAuthEditorWidgets::importAuthenticationConfigs );
181 connect( mActionResetMasterPassword, &QAction::triggered, this, &QgsAuthEditorWidgets::resetMasterPassword );
182 connect( mActionRemoveAuthConfigs, &QAction::triggered, this, &QgsAuthEditorWidgets::removeAuthenticationConfigs );
183 connect( mActionEraseAuthDatabase, &QAction::triggered, this, &QgsAuthEditorWidgets::eraseAuthenticationDatabase );
184 }
185 else
186 {
187 mActionImportAuthenticationConfigs->setEnabled( false );
188 mActionResetMasterPassword->setEnabled( false );
189 mActionRemoveAuthConfigs->setEnabled( false );
190 mActionEraseAuthDatabase->setEnabled( false );
191 }
192
193 connect( mActionExportSelectedAuthenticationConfigs, &QAction::triggered, this, &QgsAuthEditorWidgets::exportSelectedAuthenticationConfigs );
194 connect( mActionSetMasterPassword, &QAction::triggered, this, &QgsAuthEditorWidgets::setMasterPassword );
195 connect( mActionClearCachedMasterPassword, &QAction::triggered, this, &QgsAuthEditorWidgets::clearCachedMasterPassword );
196 connect( mActionClearCachedAuthConfigs, &QAction::triggered, this, &QgsAuthEditorWidgets::clearCachedAuthenticationConfigs );
197
198 connect( mActionPasswordHelperSync, &QAction::triggered, this, &QgsAuthEditorWidgets::passwordHelperSync );
199 connect( mActionPasswordHelperDelete, &QAction::triggered, this, &QgsAuthEditorWidgets::passwordHelperDelete );
200 connect( mActionPasswordHelperEnable, &QAction::triggered, this, &QgsAuthEditorWidgets::passwordHelperEnableTriggered );
201 connect( mActionPasswordHelperLoggingEnable, &QAction::triggered, this, &QgsAuthEditorWidgets::passwordHelperLoggingEnableTriggered );
202
203 connect( mActionClearAccessCacheNow, &QAction::triggered, this, [=] {
204 QgsNetworkAccessManager::instance()->clearAccessCache();
205 messageBar()->clearWidgets();
206 messageBar()->pushSuccess( tr( "Auth cache cleared" ), tr( "Network authentication cache has been cleared" ) );
207 } );
208 connect( mActionAutoClearAccessCache, &QAction::triggered, this, []( bool checked ) {
209 QgsSettings().setValue( QStringLiteral( "clear_auth_cache_on_errors" ), checked, QgsSettings::Section::Auth );
210 } );
211
212 mAuthUtilitiesMenu = new QMenu( this );
213 mAuthUtilitiesMenu->addAction( mActionSetMasterPassword );
214 mAuthUtilitiesMenu->addAction( mActionClearCachedMasterPassword );
215 mAuthUtilitiesMenu->addAction( mActionResetMasterPassword );
216 mAuthUtilitiesMenu->addSeparator();
217 mAuthUtilitiesMenu->addAction( mActionClearAccessCacheNow );
218 mAuthUtilitiesMenu->addAction( mActionAutoClearAccessCache );
219 mAuthUtilitiesMenu->addSeparator();
220 mAuthUtilitiesMenu->addAction( mActionPasswordHelperEnable );
221 mAuthUtilitiesMenu->addAction( mActionPasswordHelperSync );
222 mAuthUtilitiesMenu->addAction( mActionPasswordHelperDelete );
223 mAuthUtilitiesMenu->addAction( mActionPasswordHelperLoggingEnable );
224 mAuthUtilitiesMenu->addSeparator();
225 mAuthUtilitiesMenu->addAction( mActionClearCachedAuthConfigs );
226 mAuthUtilitiesMenu->addAction( mActionRemoveAuthConfigs );
227 mAuthUtilitiesMenu->addSeparator();
228 mAuthUtilitiesMenu->addAction( mActionImportAuthenticationConfigs );
229 mAuthUtilitiesMenu->addAction( mActionExportSelectedAuthenticationConfigs );
230 mAuthUtilitiesMenu->addSeparator();
231 mAuthUtilitiesMenu->addAction( mActionEraseAuthDatabase );
232
233 btnAuthUtilities->setMenu( mAuthUtilitiesMenu );
234}
235
236void QgsAuthEditorWidgets::importAuthenticationConfigs()
237{
239}
240
241void QgsAuthEditorWidgets::exportSelectedAuthenticationConfigs()
242{
243 if ( !wdgtConfigEditor )
244 return;
245
246 QgsAuthGuiUtils::exportSelectedAuthenticationConfigs( wdgtConfigEditor->selectedAuthenticationConfigIds(), messageBar() );
247}
248
249void QgsAuthEditorWidgets::setMasterPassword()
250{
252}
253
254void QgsAuthEditorWidgets::clearCachedMasterPassword()
255{
257}
258
259void QgsAuthEditorWidgets::resetMasterPassword()
260{
261 QgsAuthGuiUtils::resetMasterPassword( messageBar(), this );
262}
263
264void QgsAuthEditorWidgets::clearCachedAuthenticationConfigs()
265{
267}
268
269void QgsAuthEditorWidgets::removeAuthenticationConfigs()
270{
272}
273
274void QgsAuthEditorWidgets::eraseAuthenticationDatabase()
275{
277}
278
279void QgsAuthEditorWidgets::authMessageLog( const QString &message, const QString &authtag, Qgis::MessageLevel level )
280{
281 messageBar()->clearWidgets();
282 messageBar()->pushMessage( authtag, message, level );
283}
284
285void QgsAuthEditorWidgets::passwordHelperDelete()
286{
287 QgsAuthGuiUtils::passwordHelperDelete( messageBar(), this );
288}
289
290void QgsAuthEditorWidgets::passwordHelperSync()
291{
293}
294
295void QgsAuthEditorWidgets::passwordHelperEnableTriggered()
296{
297 // Only fire on real changes
298 QgsAuthGuiUtils::passwordHelperEnable( mActionPasswordHelperEnable->isChecked(), messageBar() );
299}
300
301void QgsAuthEditorWidgets::passwordHelperLoggingEnableTriggered()
302{
303 QgsAuthGuiUtils::passwordHelperLoggingEnable( mActionPasswordHelperLoggingEnable->isChecked(), messageBar() );
304}
305
306QgsMessageBar *QgsAuthEditorWidgets::messageBar()
307{
308 return mMsgBar;
309}
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