QGIS API Documentation 4.1.0-Master (5bf3c20f3c9)
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, [] { QgsHelp::openHelp( u"auth_system/auth_overview.html#authentication-methods"_s ); } );
56
57 setupTable();
58 populateTable();
59 }
60}
61
62void QgsAuthMethodPlugins::setupTable()
63{
64 tblAuthPlugins->setColumnCount( 3 );
65 tblAuthPlugins->verticalHeader()->hide();
66 tblAuthPlugins->horizontalHeader()->setVisible( true );
67 tblAuthPlugins->setHorizontalHeaderItem( 0, new QTableWidgetItem( tr( "Method" ) ) );
68 tblAuthPlugins->setHorizontalHeaderItem( 1, new QTableWidgetItem( tr( "Description" ) ) );
69 tblAuthPlugins->setHorizontalHeaderItem( 2, new QTableWidgetItem( tr( "Works with" ) ) );
70 tblAuthPlugins->horizontalHeader()->setStretchLastSection( true );
71 tblAuthPlugins->setAlternatingRowColors( true );
72 tblAuthPlugins->setColumnWidth( 0, 150 );
73 tblAuthPlugins->setColumnWidth( 1, 300 );
74 tblAuthPlugins->setRowCount( QgsApplication::authManager()->authMethodsKeys().size() );
75 tblAuthPlugins->verticalHeader()->setSectionResizeMode( QHeaderView::ResizeToContents );
76 tblAuthPlugins->setSortingEnabled( true );
77 tblAuthPlugins->setSelectionBehavior( QAbstractItemView::SelectRows );
78}
79
80void QgsAuthMethodPlugins::populateTable()
81{
82 const QStringList authMethodKeys = QgsApplication::authManager()->authMethodsKeys();
83
84 int i = 0;
85 const auto constAuthMethodKeys = authMethodKeys;
86 for ( const QString &authMethodKey : constAuthMethodKeys )
87 {
88 const QgsAuthMethodMetadata *meta = QgsApplication::authManager()->authMethodMetadata( authMethodKey );
89 const QgsAuthMethod *method = QgsApplication::authManager()->authMethod( authMethodKey );
90 if ( !meta || !method )
91 {
92 QgsDebugError( u"Load auth method instance FAILED for auth method key (%1)"_s.arg( authMethodKey ) );
93 continue;
94 }
95
96 QTableWidgetItem *twi = new QTableWidgetItem( meta->key() );
97 twi->setFlags( twi->flags() & ~Qt::ItemIsEditable );
98 tblAuthPlugins->setItem( i, 0, twi );
99
100 twi = new QTableWidgetItem( meta->description() );
101 twi->setFlags( twi->flags() & ~Qt::ItemIsEditable );
102 tblAuthPlugins->setItem( i, 1, twi );
103
104 twi = new QTableWidgetItem( method->supportedDataProviders().join( ", "_L1 ) );
105 twi->setFlags( twi->flags() & ~Qt::ItemIsEditable );
106 tblAuthPlugins->setItem( i, 2, twi );
107
108 i++;
109 }
110 tblAuthPlugins->sortItems( 0 );
111}
112
113
115 : QWidget( parent )
116
117{
118 setupUi( this );
119 connect( btnCertManager, &QPushButton::clicked, this, &QgsAuthEditorWidgets::btnCertManager_clicked );
120 connect( btnAuthPlugins, &QPushButton::clicked, this, &QgsAuthEditorWidgets::btnAuthPlugins_clicked );
121 if ( !QgsApplication::authManager()->isDisabled() )
122 {
123 wdgtConfigEditor->setRelayMessages( false );
124 wdgtConfigEditor->setShowUtilitiesButton( false );
125 setupUtilitiesMenu();
126 }
127 else
128 {
129 grpbxManagers->setEnabled( false );
130 }
131}
132
133void QgsAuthEditorWidgets::btnCertManager_clicked()
134{
135 QgsAuthCertManager *dlg = new QgsAuthCertManager( this );
136 dlg->setWindowModality( Qt::ApplicationModal );
137 dlg->resize( 750, 500 );
138 dlg->exec();
139 dlg->deleteLater();
140}
141
142void QgsAuthEditorWidgets::btnAuthPlugins_clicked()
143{
144 QgsAuthMethodPlugins *dlg = new QgsAuthMethodPlugins( this );
145 dlg->setWindowModality( Qt::WindowModal );
146 dlg->resize( 675, 500 );
147 dlg->exec();
148 dlg->deleteLater();
149}
150
151void QgsAuthEditorWidgets::setupUtilitiesMenu()
152{
153 connect( QgsApplication::authManager(), &QgsAuthManager::messageLog, this, &QgsAuthEditorWidgets::authMessageLog );
154
156
157 // set up utility actions menu
158 mActionImportAuthenticationConfigs = new QAction( tr( "Import Authentication Configurations from File…" ), this );
159 mActionExportSelectedAuthenticationConfigs = new QAction( tr( "Export Selected Authentication Configurations to File…" ), this );
160 mActionSetMasterPassword = new QAction( tr( "Input Master Password…" ), this );
161 mActionClearCachedMasterPassword = new QAction( tr( "Clear Cached Master Password" ), this );
162 mActionResetMasterPassword = new QAction( tr( "Reset Master Password…" ), this );
163 mActionClearCachedAuthConfigs = new QAction( tr( "Clear Cached Authentication Configurations" ), this );
164 mActionRemoveAuthConfigs = new QAction( tr( "Remove all Authentication Configurations…" ), this );
165 mActionEraseAuthDatabase = new QAction( tr( "Erase Authentication Database…" ), this );
166
167 mActionClearAccessCacheNow = new QAction( tr( "Clear Network Authentication Access Cache" ), this );
168 mActionAutoClearAccessCache = new QAction( tr( "Automatically Clear Network Authentication Access Cache on SSL Errors" ), this );
169 mActionAutoClearAccessCache->setCheckable( true );
170 mActionAutoClearAccessCache->setChecked( QgsSettings().value( u"clear_auth_cache_on_errors"_s, true, QgsSettings::Section::Auth ).toBool() );
171
172 mActionPasswordHelperDelete = new QAction( tr( "Clear the Master Password from the %1…" ).arg( QgsAuthManager::passwordHelperDisplayName( true ) ), this );
173 mActionPasswordHelperEnable = new QAction( tr( "Integrate Master Password with the %1" ).arg( QgsAuthManager::passwordHelperDisplayName( true ) ), this );
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( mActionPasswordHelperDelete, &QAction::triggered, this, &QgsAuthEditorWidgets::passwordHelperDelete );
203 connect( mActionPasswordHelperEnable, &QAction::triggered, this, &QgsAuthEditorWidgets::passwordHelperEnableTriggered );
204 connect( mActionPasswordHelperLoggingEnable, &QAction::triggered, this, &QgsAuthEditorWidgets::passwordHelperLoggingEnableTriggered );
205
206 connect( mActionClearAccessCacheNow, &QAction::triggered, this, [this] {
207 QgsNetworkAccessManager::instance()->clearAccessCache();
208 messageBar()->clearWidgets();
209 messageBar()->pushSuccess( tr( "Auth cache cleared" ), tr( "Network authentication cache has been cleared" ) );
210 } );
211 connect( mActionAutoClearAccessCache, &QAction::triggered, this, []( bool checked ) { QgsSettings().setValue( u"clear_auth_cache_on_errors"_s, checked, QgsSettings::Section::Auth ); } );
212
213 mAuthUtilitiesMenu = new QMenu( this );
214 mAuthUtilitiesMenu->addAction( mActionSetMasterPassword );
215 mAuthUtilitiesMenu->addAction( mActionClearCachedMasterPassword );
216 mAuthUtilitiesMenu->addAction( mActionResetMasterPassword );
217 mAuthUtilitiesMenu->addSeparator();
218 mAuthUtilitiesMenu->addAction( mActionClearAccessCacheNow );
219 mAuthUtilitiesMenu->addAction( mActionAutoClearAccessCache );
220 mAuthUtilitiesMenu->addSeparator();
221 mAuthUtilitiesMenu->addAction( mActionPasswordHelperEnable );
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::passwordHelperEnableTriggered()
291{
292 // Only fire on real changes
293 QgsAuthGuiUtils::passwordHelperEnable( mActionPasswordHelperEnable->isChecked(), messageBar() );
294}
295
296void QgsAuthEditorWidgets::passwordHelperLoggingEnableTriggered()
297{
298 QgsAuthGuiUtils::passwordHelperLoggingEnable( mActionPasswordHelperLoggingEnable->isChecked(), messageBar() );
299}
300
301QgsMessageBar *QgsAuthEditorWidgets::messageBar()
302{
303 return mMsgBar;
304}
MessageLevel
Level for messages This will be used both for message log and message bar in application.
Definition qgis.h:160
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