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 );
57 setupSslConfigsTree();
59 connect( treeServerConfigs->selectionModel(), &QItemSelectionModel::selectionChanged,
this, &QgsAuthServersEditor::selectionChanged );
61 connect( treeServerConfigs, &QTreeWidget::itemDoubleClicked,
this, &QgsAuthServersEditor::handleDoubleClick );
63 connect( btnViewRefresh, &QAbstractButton::clicked,
this, &QgsAuthServersEditor::refreshSslConfigsView );
65 btnGroupByOrg->setChecked(
false );
68 btnGroupByOrg->setChecked( sortbyval.toBool() );
70 populateSslConfigsView();
75void QgsAuthServersEditor::setupSslConfigsTree()
77 treeServerConfigs->setColumnCount( 3 );
78 treeServerConfigs->setHeaderLabels(
79 QStringList() << tr(
"Common Name" )
81 << tr(
"Expiry Date" )
83 treeServerConfigs->setColumnWidth( 0, 275 );
84 treeServerConfigs->setColumnWidth( 1, 200 );
87 mRootSslConfigItem =
new QTreeWidgetItem(
89 QStringList( tr(
"SSL Server Configurations" ) ),
90 static_cast<int>( QgsAuthServersEditor::Section )
93 mRootSslConfigItem->setFlags( Qt::ItemIsEnabled );
94 mRootSslConfigItem->setExpanded(
true );
95 treeServerConfigs->insertTopLevelItem( 0, mRootSslConfigItem );
98void QgsAuthServersEditor::populateSslConfigsView()
102 populateSslConfigsSection( mRootSslConfigItem,
QgsApplication::authManager()->sslCertCustomConfigs(), QgsAuthServersEditor::ServerConfig );
105void QgsAuthServersEditor::refreshSslConfigsView()
107 populateSslConfigsView();
110void QgsAuthServersEditor::populateSslConfigsSection( QTreeWidgetItem *item,
const QList<QgsAuthConfigSslServer> &configs, QgsAuthServersEditor::ConfigType conftype )
112 if ( btnGroupByOrg->isChecked() )
114 appendSslConfigsToGroup( configs, conftype, item );
118 appendSslConfigsToItem( configs, conftype, item );
122void QgsAuthServersEditor::appendSslConfigsToGroup(
const QList<QgsAuthConfigSslServer> &configs, QgsAuthServersEditor::ConfigType conftype, QTreeWidgetItem *parent )
124 if ( configs.empty() )
129 parent = treeServerConfigs->currentItem();
133 const QMap<QString, QList<QgsAuthConfigSslServer>> orgconfigs(
137 QMap<QString, QList<QgsAuthConfigSslServer>>::const_iterator it = orgconfigs.constBegin();
138 for ( ; it != orgconfigs.constEnd(); ++it )
140 QTreeWidgetItem *grpitem(
new QTreeWidgetItem( parent, QStringList() << it.key(),
static_cast<int>( QgsAuthServersEditor::OrgName ) ) );
141 grpitem->setFirstColumnSpanned(
true );
142 grpitem->setFlags( Qt::ItemIsEnabled );
143 grpitem->setExpanded(
true );
145 QBrush orgb( grpitem->foreground( 0 ) );
146 orgb.setColor( QColor::fromRgb( 90, 90, 90 ) );
147 grpitem->setForeground( 0, orgb );
148 QFont grpf( grpitem->font( 0 ) );
149 grpf.setItalic(
true );
150 grpitem->setFont( 0, grpf );
152 appendSslConfigsToItem( it.value(), conftype, grpitem );
155 parent->sortChildren( 0, Qt::AscendingOrder );
158void QgsAuthServersEditor::appendSslConfigsToItem(
const QList<QgsAuthConfigSslServer> &configs, QgsAuthServersEditor::ConfigType conftype, QTreeWidgetItem *parent )
160 if ( configs.empty() )
165 parent = treeServerConfigs->currentItem();
171 const auto constConfigs = configs;
174 const QSslCertificate cert( config.sslCertificate() );
179 coltxts << QString( config.sslHostPort() );
180 coltxts << cert.expiryDate().toString();
182 QTreeWidgetItem *item(
new QTreeWidgetItem( parent, coltxts,
static_cast<int>( conftype ) ) );
187 item->setForeground( 2, redb );
191 item->setData( 0, Qt::UserRole,
id );
194 parent->sortChildren( 0, Qt::AscendingOrder );
197void QgsAuthServersEditor::selectionChanged(
const QItemSelection &selected,
const QItemSelection &deselected )
200 Q_UNUSED( deselected )
204void QgsAuthServersEditor::checkSelection()
206 bool isconfig =
false;
207 if ( treeServerConfigs->selectionModel()->selection().length() > 0 )
209 QTreeWidgetItem *item( treeServerConfigs->currentItem() );
211 switch ( ( QgsAuthServersEditor::ConfigType ) item->type() )
213 case QgsAuthServersEditor::ServerConfig:
221 btnRemoveServer->setEnabled( isconfig );
222 btnEditServer->setEnabled( isconfig );
225void QgsAuthServersEditor::handleDoubleClick( QTreeWidgetItem *item,
int col )
228 bool isconfig =
true;
230 switch ( ( QgsAuthServersEditor::ConfigType ) item->type() )
232 case QgsAuthServersEditor::Section:
235 case QgsAuthServersEditor::OrgName:
244 btnEditServer_clicked();
248void QgsAuthServersEditor::btnAddServer_clicked()
251 dlg->setWindowModality( Qt::WindowModal );
252 dlg->resize( 580, 512 );
255 refreshSslConfigsView();
260void QgsAuthServersEditor::btnRemoveServer_clicked()
262 QTreeWidgetItem *item( treeServerConfigs->currentItem() );
266 QgsDebugMsgLevel( QStringLiteral(
"Current tree widget item not set" ), 2 );
270 const QString digest( item->data( 0, Qt::UserRole ).toString() );
271 const QString hostport( item->text( 1 ) );
273 if ( digest.isEmpty() )
278 if ( hostport.isEmpty() )
286 QgsDebugError( QStringLiteral(
"SSL custom config does not exist in database for host:port, id %1:" )
287 .arg( hostport, digest ) );
291 if ( QMessageBox::warning(
292 this, tr(
"Remove SSL Custom Configuration" ),
293 tr(
"Are you sure you want to remove the selected "
294 "SSL custom configuration from the database?\n\n"
295 "Operation can NOT be undone!" ),
296 QMessageBox::Ok | QMessageBox::Cancel,
299 == QMessageBox::Cancel )
310 item->parent()->removeChild( item );
314void QgsAuthServersEditor::btnEditServer_clicked()
316 QTreeWidgetItem *item( treeServerConfigs->currentItem() );
320 QgsDebugMsgLevel( QStringLiteral(
"Current tree widget item not set" ), 2 );
324 const QString digest( item->data( 0, Qt::UserRole ).toString() );
325 const QString hostport( item->text( 1 ) );
327 if ( digest.isEmpty() )
332 if ( hostport.isEmpty() )
340 QgsDebugError( QStringLiteral(
"SSL custom config does not exist in database" ) );
345 const QSslCertificate cert( config.sslCertificate() );
349 dlg->setWindowModality( Qt::WindowModal );
350 dlg->resize( 500, 500 );
353 refreshSslConfigsView();
358void QgsAuthServersEditor::btnGroupByOrg_toggled(
bool checked )
362 authMessageLog( QObject::tr(
"Could not store sort by preference." ), QObject::tr(
"Authentication SSL Configs" ),
Qgis::MessageLevel::Warning );
364 populateSslConfigsView();
367void QgsAuthServersEditor::authMessageLog(
const QString &message,
const QString &authtag,
Qgis::MessageLevel level )
369 messageBar()->
pushMessage( authtag, message, level, 7 );
376 treeServerConfigs->setFocus();
378 QWidget::showEvent( e );
386int QgsAuthServersEditor::messageTimeout()
389 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 void setItemBold(QTreeWidgetItem *item)
Call setFirstColumnSpanned(true) on the item and make its font bold.
static void removeChildren(QTreeWidgetItem *item)
Remove the children of the passed item.
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)