18#include "ui_qgsauthserverseditor.h"
39 mAuthNotifyLayout =
new QVBoxLayout;
40 this->setLayout( mAuthNotifyLayout );
42 mAuthNotifyLayout->addWidget( mAuthNotify );
47 connect( btnAddServer, &QToolButton::clicked,
this, &QgsAuthServersEditor::btnAddServer_clicked );
48 connect( btnRemoveServer, &QToolButton::clicked,
this, &QgsAuthServersEditor::btnRemoveServer_clicked );
49 connect( btnEditServer, &QToolButton::clicked,
this, &QgsAuthServersEditor::btnEditServer_clicked );
50 connect( btnGroupByOrg, &QToolButton::toggled,
this, &QgsAuthServersEditor::btnGroupByOrg_toggled );
53 this, &QgsAuthServersEditor::authMessageLog );
56 this, &QgsAuthServersEditor::refreshSslConfigsView );
58 setupSslConfigsTree();
60 connect( treeServerConfigs->selectionModel(), &QItemSelectionModel::selectionChanged,
61 this, &QgsAuthServersEditor::selectionChanged );
63 connect( treeServerConfigs, &QTreeWidget::itemDoubleClicked,
64 this, &QgsAuthServersEditor::handleDoubleClick );
66 connect( btnViewRefresh, &QAbstractButton::clicked,
this, &QgsAuthServersEditor::refreshSslConfigsView );
68 btnGroupByOrg->setChecked(
false );
71 btnGroupByOrg->setChecked( sortbyval.toBool() );
73 populateSslConfigsView();
78static void setItemBold_( QTreeWidgetItem *item )
80 item->setFirstColumnSpanned(
true );
81 QFont secf( item->font( 0 ) );
83 item->setFont( 0, secf );
87void QgsAuthServersEditor::setupSslConfigsTree()
89 treeServerConfigs->setColumnCount( 3 );
90 treeServerConfigs->setHeaderLabels(
91 QStringList() << tr(
"Common Name" )
93 << tr(
"Expiry Date" ) );
94 treeServerConfigs->setColumnWidth( 0, 275 );
95 treeServerConfigs->setColumnWidth( 1, 200 );
98 mRootSslConfigItem =
new QTreeWidgetItem(
100 QStringList( tr(
"SSL Server Configurations" ) ),
101 static_cast<int>( QgsAuthServersEditor::Section ) );
102 setItemBold_( mRootSslConfigItem );
103 mRootSslConfigItem->setFlags( Qt::ItemIsEnabled );
104 mRootSslConfigItem->setExpanded(
true );
105 treeServerConfigs->insertTopLevelItem( 0, mRootSslConfigItem );
108static void removeChildren_( QTreeWidgetItem *item )
110 const auto constTakeChildren = item->takeChildren();
111 for ( QTreeWidgetItem *child : constTakeChildren )
117void QgsAuthServersEditor::populateSslConfigsView()
119 removeChildren_( mRootSslConfigItem );
121 populateSslConfigsSection( mRootSslConfigItem,
123 QgsAuthServersEditor::ServerConfig );
126void QgsAuthServersEditor::refreshSslConfigsView()
128 populateSslConfigsView();
131void QgsAuthServersEditor::populateSslConfigsSection( QTreeWidgetItem *item,
132 const QList<QgsAuthConfigSslServer> &configs,
133 QgsAuthServersEditor::ConfigType conftype )
135 if ( btnGroupByOrg->isChecked() )
137 appendSslConfigsToGroup( configs, conftype, item );
141 appendSslConfigsToItem( configs, conftype, item );
145void QgsAuthServersEditor::appendSslConfigsToGroup(
const QList<QgsAuthConfigSslServer> &configs,
146 QgsAuthServersEditor::ConfigType conftype,
147 QTreeWidgetItem *parent )
149 if ( configs.empty() )
154 parent = treeServerConfigs->currentItem();
158 const QMap< QString, QList<QgsAuthConfigSslServer> > orgconfigs(
161 QMap< QString, QList<QgsAuthConfigSslServer> >::const_iterator it = orgconfigs.constBegin();
162 for ( ; it != orgconfigs.constEnd(); ++it )
164 QTreeWidgetItem *grpitem(
new QTreeWidgetItem( parent,
165 QStringList() << it.key(),
166 static_cast<int>( QgsAuthServersEditor::OrgName ) ) );
167 grpitem->setFirstColumnSpanned(
true );
168 grpitem->setFlags( Qt::ItemIsEnabled );
169 grpitem->setExpanded(
true );
171 QBrush orgb( grpitem->foreground( 0 ) );
172 orgb.setColor( QColor::fromRgb( 90, 90, 90 ) );
173 grpitem->setForeground( 0, orgb );
174 QFont grpf( grpitem->font( 0 ) );
175 grpf.setItalic(
true );
176 grpitem->setFont( 0, grpf );
178 appendSslConfigsToItem( it.value(), conftype, grpitem );
181 parent->sortChildren( 0, Qt::AscendingOrder );
184void QgsAuthServersEditor::appendSslConfigsToItem(
const QList<QgsAuthConfigSslServer> &configs,
185 QgsAuthServersEditor::ConfigType conftype,
186 QTreeWidgetItem *parent )
188 if ( configs.empty() )
193 parent = treeServerConfigs->currentItem();
199 const auto constConfigs = configs;
202 const QSslCertificate cert( config.sslCertificate() );
207 coltxts << QString( config.sslHostPort() );
208 coltxts << cert.expiryDate().toString();
210 QTreeWidgetItem *item(
new QTreeWidgetItem( parent, coltxts,
static_cast<int>( conftype ) ) );
215 item->setForeground( 2, redb );
219 item->setData( 0, Qt::UserRole,
id );
222 parent->sortChildren( 0, Qt::AscendingOrder );
225void QgsAuthServersEditor::selectionChanged(
const QItemSelection &selected,
const QItemSelection &deselected )
228 Q_UNUSED( deselected )
232void QgsAuthServersEditor::checkSelection()
234 bool isconfig =
false;
235 if ( treeServerConfigs->selectionModel()->selection().length() > 0 )
237 QTreeWidgetItem *item( treeServerConfigs->currentItem() );
239 switch ( ( QgsAuthServersEditor::ConfigType )item->type() )
241 case QgsAuthServersEditor::ServerConfig :
249 btnRemoveServer->setEnabled( isconfig );
250 btnEditServer->setEnabled( isconfig );
253void QgsAuthServersEditor::handleDoubleClick( QTreeWidgetItem *item,
int col )
256 bool isconfig =
true;
258 switch ( ( QgsAuthServersEditor::ConfigType )item->type() )
260 case QgsAuthServersEditor::Section:
263 case QgsAuthServersEditor::OrgName:
272 btnEditServer_clicked();
276void QgsAuthServersEditor::btnAddServer_clicked()
279 dlg->setWindowModality( Qt::WindowModal );
280 dlg->resize( 580, 512 );
283 refreshSslConfigsView();
288void QgsAuthServersEditor::btnRemoveServer_clicked()
290 QTreeWidgetItem *item( treeServerConfigs->currentItem() );
294 QgsDebugMsgLevel( QStringLiteral(
"Current tree widget item not set" ), 2 );
298 const QString digest( item->data( 0, Qt::UserRole ).toString() );
299 const QString hostport( item->text( 1 ) );
301 if ( digest.isEmpty() )
303 messageBar()->
pushMessage( tr(
"SSL custom config id missing" ),
307 if ( hostport.isEmpty() )
309 messageBar()->
pushMessage( tr(
"SSL custom config host:port missing" ),
316 QgsDebugError( QStringLiteral(
"SSL custom config does not exist in database for host:port, id %1:" )
317 .arg( hostport, digest ) );
321 if ( QMessageBox::warning(
322 this, tr(
"Remove SSL Custom Configuration" ),
323 tr(
"Are you sure you want to remove the selected "
324 "SSL custom configuration from the database?\n\n"
325 "Operation can NOT be undone!" ),
326 QMessageBox::Ok | QMessageBox::Cancel,
327 QMessageBox::Cancel ) == QMessageBox::Cancel )
334 messageBar()->
pushMessage( tr(
"ERROR removing SSL custom config from authentication database for host:port, id %1:" )
335 .arg( hostport, digest ),
340 item->parent()->removeChild( item );
344void QgsAuthServersEditor::btnEditServer_clicked()
346 QTreeWidgetItem *item( treeServerConfigs->currentItem() );
350 QgsDebugMsgLevel( QStringLiteral(
"Current tree widget item not set" ), 2 );
354 const QString digest( item->data( 0, Qt::UserRole ).toString() );
355 const QString hostport( item->text( 1 ) );
357 if ( digest.isEmpty() )
359 messageBar()->
pushMessage( tr(
"SSL custom config id missing." ),
363 if ( hostport.isEmpty() )
365 messageBar()->
pushMessage( tr(
"SSL custom config host:port missing." ),
372 QgsDebugError( QStringLiteral(
"SSL custom config does not exist in database" ) );
377 const QSslCertificate cert( config.sslCertificate() );
381 dlg->setWindowModality( Qt::WindowModal );
382 dlg->resize( 500, 500 );
385 refreshSslConfigsView();
390void QgsAuthServersEditor::btnGroupByOrg_toggled(
bool checked )
394 authMessageLog( QObject::tr(
"Could not store sort by preference." ),
395 QObject::tr(
"Authentication SSL Configs" ),
398 populateSslConfigsView();
401void QgsAuthServersEditor::authMessageLog(
const QString &message,
const QString &authtag,
Qgis::MessageLevel level )
403 messageBar()->
pushMessage( authtag, message, level, 7 );
410 treeServerConfigs->setFocus();
412 QWidget::showEvent( e );
420int QgsAuthServersEditor::messageTimeout()
423 return settings.
value( QStringLiteral(
"qgis/messageTimeout" ), 5 ).toInt();
MessageLevel
Level for messages This will be used both for message log and message bar in application.
@ Warning
Warning message.
@ Critical
Critical/error message.
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
static QgsAuthManager * authManager()
Returns the application's authentication manager instance.
static QString resolvedCertName(const QSslCertificate &cert, bool issuer=false)
Gets the general name via RFC 5280 resolution.
static QString shaHexForCert(const QSslCertificate &cert, bool formatted=false)
Gets the sha1 hash for certificate.
static bool certIsViable(const QSslCertificate &cert)
certIsViable checks for viability errors of cert and whether it is NULL
static QMap< QString, QList< QgsAuthConfigSslServer > > sslConfigsGroupedByOrg(const QList< QgsAuthConfigSslServer > &configs)
Map SSL custom configs' certificates to their oraganization.
Configuration container for SSL server connection exceptions or overrides.
static QColor redColor()
Red color representing invalid, untrusted, etc. certificate.
void authDatabaseChanged()
Emitted when the authentication db is significantly changed, e.g. large record removal,...
QVariant authSetting(const QString &key, const QVariant &defaultValue=QVariant(), bool decrypt=false)
authSetting get an authentication setting (retrieved as string and returned as QVariant( QString ))
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.
QgsAuthServersEditor(QWidget *parent=nullptr)
Widget for editing authentication configurations directly in database.
void showEvent(QShowEvent *e) override
Dialog wrapper of widget for editing an SSL server configuration.
QgsAuthSslConfigWidget * sslCustomConfigWidget()
Access the embedded SSL server configuration widget.
Widget for importing an SSL server certificate exception into the authentication database.
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.
This class is a composition of two QSettings instances:
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
static bool isNull(const QVariant &variant, bool silenceNullWarnings=false)
Returns true if the specified variant should be considered a NULL value.
#define QgsDebugMsgLevel(str, level)
#define QgsDebugError(str)