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