18#include "moc_qgsauthserverseditor.cpp"
19#include "ui_qgsauthserverseditor.h"
40 mAuthNotifyLayout =
new QVBoxLayout;
41 this->setLayout( mAuthNotifyLayout );
43 mAuthNotifyLayout->addWidget( mAuthNotify );
48 connect( btnAddServer, &QToolButton::clicked,
this, &QgsAuthServersEditor::btnAddServer_clicked );
49 connect( btnRemoveServer, &QToolButton::clicked,
this, &QgsAuthServersEditor::btnRemoveServer_clicked );
50 connect( btnEditServer, &QToolButton::clicked,
this, &QgsAuthServersEditor::btnEditServer_clicked );
51 connect( btnGroupByOrg, &QToolButton::toggled,
this, &QgsAuthServersEditor::btnGroupByOrg_toggled );
54 this, &QgsAuthServersEditor::authMessageLog );
57 this, &QgsAuthServersEditor::refreshSslConfigsView );
59 setupSslConfigsTree();
61 connect( treeServerConfigs->selectionModel(), &QItemSelectionModel::selectionChanged,
62 this, &QgsAuthServersEditor::selectionChanged );
64 connect( treeServerConfigs, &QTreeWidget::itemDoubleClicked,
65 this, &QgsAuthServersEditor::handleDoubleClick );
67 connect( btnViewRefresh, &QAbstractButton::clicked,
this, &QgsAuthServersEditor::refreshSslConfigsView );
69 btnGroupByOrg->setChecked(
false );
72 btnGroupByOrg->setChecked( sortbyval.toBool() );
74 populateSslConfigsView();
79static void setItemBold_( QTreeWidgetItem *item )
81 item->setFirstColumnSpanned(
true );
82 QFont secf( item->font( 0 ) );
84 item->setFont( 0, secf );
88void QgsAuthServersEditor::setupSslConfigsTree()
90 treeServerConfigs->setColumnCount( 3 );
91 treeServerConfigs->setHeaderLabels(
92 QStringList() << tr(
"Common Name" )
94 << tr(
"Expiry Date" ) );
95 treeServerConfigs->setColumnWidth( 0, 275 );
96 treeServerConfigs->setColumnWidth( 1, 200 );
99 mRootSslConfigItem =
new QTreeWidgetItem(
101 QStringList( tr(
"SSL Server Configurations" ) ),
102 static_cast<int>( QgsAuthServersEditor::Section ) );
103 setItemBold_( mRootSslConfigItem );
104 mRootSslConfigItem->setFlags( Qt::ItemIsEnabled );
105 mRootSslConfigItem->setExpanded(
true );
106 treeServerConfigs->insertTopLevelItem( 0, mRootSslConfigItem );
109static void removeChildren_( QTreeWidgetItem *item )
111 const auto constTakeChildren = item->takeChildren();
112 for ( QTreeWidgetItem *child : constTakeChildren )
118void QgsAuthServersEditor::populateSslConfigsView()
120 removeChildren_( mRootSslConfigItem );
122 populateSslConfigsSection( mRootSslConfigItem,
124 QgsAuthServersEditor::ServerConfig );
127void QgsAuthServersEditor::refreshSslConfigsView()
129 populateSslConfigsView();
132void QgsAuthServersEditor::populateSslConfigsSection( QTreeWidgetItem *item,
133 const QList<QgsAuthConfigSslServer> &configs,
134 QgsAuthServersEditor::ConfigType conftype )
136 if ( btnGroupByOrg->isChecked() )
138 appendSslConfigsToGroup( configs, conftype, item );
142 appendSslConfigsToItem( configs, conftype, item );
146void QgsAuthServersEditor::appendSslConfigsToGroup(
const QList<QgsAuthConfigSslServer> &configs,
147 QgsAuthServersEditor::ConfigType conftype,
148 QTreeWidgetItem *parent )
150 if ( configs.empty() )
155 parent = treeServerConfigs->currentItem();
159 const QMap< QString, QList<QgsAuthConfigSslServer> > orgconfigs(
162 QMap< QString, QList<QgsAuthConfigSslServer> >::const_iterator it = orgconfigs.constBegin();
163 for ( ; it != orgconfigs.constEnd(); ++it )
165 QTreeWidgetItem *grpitem(
new QTreeWidgetItem( parent,
166 QStringList() << it.key(),
167 static_cast<int>( QgsAuthServersEditor::OrgName ) ) );
168 grpitem->setFirstColumnSpanned(
true );
169 grpitem->setFlags( Qt::ItemIsEnabled );
170 grpitem->setExpanded(
true );
172 QBrush orgb( grpitem->foreground( 0 ) );
173 orgb.setColor( QColor::fromRgb( 90, 90, 90 ) );
174 grpitem->setForeground( 0, orgb );
175 QFont grpf( grpitem->font( 0 ) );
176 grpf.setItalic(
true );
177 grpitem->setFont( 0, grpf );
179 appendSslConfigsToItem( it.value(), conftype, grpitem );
182 parent->sortChildren( 0, Qt::AscendingOrder );
185void QgsAuthServersEditor::appendSslConfigsToItem(
const QList<QgsAuthConfigSslServer> &configs,
186 QgsAuthServersEditor::ConfigType conftype,
187 QTreeWidgetItem *parent )
189 if ( configs.empty() )
194 parent = treeServerConfigs->currentItem();
200 const auto constConfigs = configs;
203 const QSslCertificate cert( config.sslCertificate() );
208 coltxts << QString( config.sslHostPort() );
209 coltxts << cert.expiryDate().toString();
211 QTreeWidgetItem *item(
new QTreeWidgetItem( parent, coltxts,
static_cast<int>( conftype ) ) );
216 item->setForeground( 2, redb );
220 item->setData( 0, Qt::UserRole,
id );
223 parent->sortChildren( 0, Qt::AscendingOrder );
226void QgsAuthServersEditor::selectionChanged(
const QItemSelection &selected,
const QItemSelection &deselected )
229 Q_UNUSED( deselected )
233void QgsAuthServersEditor::checkSelection()
235 bool isconfig =
false;
236 if ( treeServerConfigs->selectionModel()->selection().length() > 0 )
238 QTreeWidgetItem *item( treeServerConfigs->currentItem() );
240 switch ( ( QgsAuthServersEditor::ConfigType )item->type() )
242 case QgsAuthServersEditor::ServerConfig :
250 btnRemoveServer->setEnabled( isconfig );
251 btnEditServer->setEnabled( isconfig );
254void QgsAuthServersEditor::handleDoubleClick( QTreeWidgetItem *item,
int col )
257 bool isconfig =
true;
259 switch ( ( QgsAuthServersEditor::ConfigType )item->type() )
261 case QgsAuthServersEditor::Section:
264 case QgsAuthServersEditor::OrgName:
273 btnEditServer_clicked();
277void QgsAuthServersEditor::btnAddServer_clicked()
280 dlg->setWindowModality( Qt::WindowModal );
281 dlg->resize( 580, 512 );
284 refreshSslConfigsView();
289void QgsAuthServersEditor::btnRemoveServer_clicked()
291 QTreeWidgetItem *item( treeServerConfigs->currentItem() );
295 QgsDebugMsgLevel( QStringLiteral(
"Current tree widget item not set" ), 2 );
299 const QString digest( item->data( 0, Qt::UserRole ).toString() );
300 const QString hostport( item->text( 1 ) );
302 if ( digest.isEmpty() )
304 messageBar()->
pushMessage( tr(
"SSL custom config id missing" ),
308 if ( hostport.isEmpty() )
310 messageBar()->
pushMessage( tr(
"SSL custom config host:port missing" ),
317 QgsDebugError( QStringLiteral(
"SSL custom config does not exist in database for host:port, id %1:" )
318 .arg( hostport, digest ) );
322 if ( QMessageBox::warning(
323 this, tr(
"Remove SSL Custom Configuration" ),
324 tr(
"Are you sure you want to remove the selected "
325 "SSL custom configuration from the database?\n\n"
326 "Operation can NOT be undone!" ),
327 QMessageBox::Ok | QMessageBox::Cancel,
328 QMessageBox::Cancel ) == QMessageBox::Cancel )
335 messageBar()->
pushMessage( tr(
"ERROR removing SSL custom config from authentication database for host:port, id %1:" )
336 .arg( hostport, digest ),
341 item->parent()->removeChild( item );
345void QgsAuthServersEditor::btnEditServer_clicked()
347 QTreeWidgetItem *item( treeServerConfigs->currentItem() );
351 QgsDebugMsgLevel( QStringLiteral(
"Current tree widget item not set" ), 2 );
355 const QString digest( item->data( 0, Qt::UserRole ).toString() );
356 const QString hostport( item->text( 1 ) );
358 if ( digest.isEmpty() )
360 messageBar()->
pushMessage( tr(
"SSL custom config id missing." ),
364 if ( hostport.isEmpty() )
366 messageBar()->
pushMessage( tr(
"SSL custom config host:port missing." ),
373 QgsDebugError( QStringLiteral(
"SSL custom config does not exist in database" ) );
378 const QSslCertificate cert( config.sslCertificate() );
382 dlg->setWindowModality( Qt::WindowModal );
383 dlg->resize( 500, 500 );
386 refreshSslConfigsView();
391void QgsAuthServersEditor::btnGroupByOrg_toggled(
bool checked )
395 authMessageLog( QObject::tr(
"Could not store sort by preference." ),
396 QObject::tr(
"Authentication SSL Configs" ),
399 populateSslConfigsView();
402void QgsAuthServersEditor::authMessageLog(
const QString &message,
const QString &authtag,
Qgis::MessageLevel level )
404 messageBar()->
pushMessage( authtag, message, level, 7 );
411 treeServerConfigs->setFocus();
413 QWidget::showEvent( e );
421int QgsAuthServersEditor::messageTimeout()
424 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)