17#include "ui_qgsauthserverseditor.h"
33#include "moc_qgsauthserverseditor.cpp"
41 mAuthNotifyLayout =
new QVBoxLayout;
42 this->setLayout( mAuthNotifyLayout );
44 mAuthNotifyLayout->addWidget( mAuthNotify );
49 connect( btnAddServer, &QToolButton::clicked,
this, &QgsAuthServersEditor::btnAddServer_clicked );
50 connect( btnRemoveServer, &QToolButton::clicked,
this, &QgsAuthServersEditor::btnRemoveServer_clicked );
51 connect( btnEditServer, &QToolButton::clicked,
this, &QgsAuthServersEditor::btnEditServer_clicked );
52 connect( btnGroupByOrg, &QToolButton::toggled,
this, &QgsAuthServersEditor::btnGroupByOrg_toggled );
58 setupSslConfigsTree();
60 connect( treeServerConfigs->selectionModel(), &QItemSelectionModel::selectionChanged,
this, &QgsAuthServersEditor::selectionChanged );
62 connect( treeServerConfigs, &QTreeWidget::itemDoubleClicked,
this, &QgsAuthServersEditor::handleDoubleClick );
64 connect( btnViewRefresh, &QAbstractButton::clicked,
this, &QgsAuthServersEditor::refreshSslConfigsView );
66 btnGroupByOrg->setChecked(
false );
69 btnGroupByOrg->setChecked( sortbyval.toBool() );
71 populateSslConfigsView();
76void QgsAuthServersEditor::setupSslConfigsTree()
78 treeServerConfigs->setColumnCount( 3 );
79 treeServerConfigs->setHeaderLabels(
80 QStringList() << tr(
"Common Name" )
82 << tr(
"Expiry Date" )
84 treeServerConfigs->setColumnWidth( 0, 275 );
85 treeServerConfigs->setColumnWidth( 1, 200 );
88 mRootSslConfigItem =
new QTreeWidgetItem(
90 QStringList( tr(
"SSL Server Configurations" ) ),
91 static_cast<int>( QgsAuthServersEditor::Section )
94 mRootSslConfigItem->setFlags( Qt::ItemIsEnabled );
95 mRootSslConfigItem->setExpanded(
true );
96 treeServerConfigs->insertTopLevelItem( 0, mRootSslConfigItem );
99void QgsAuthServersEditor::populateSslConfigsView()
103 populateSslConfigsSection( mRootSslConfigItem,
QgsApplication::authManager()->sslCertCustomConfigs(), QgsAuthServersEditor::ServerConfig );
106void QgsAuthServersEditor::refreshSslConfigsView()
108 populateSslConfigsView();
111void QgsAuthServersEditor::populateSslConfigsSection( QTreeWidgetItem *item,
const QList<QgsAuthConfigSslServer> &configs, QgsAuthServersEditor::ConfigType conftype )
113 if ( btnGroupByOrg->isChecked() )
115 appendSslConfigsToGroup( configs, conftype, item );
119 appendSslConfigsToItem( configs, conftype, item );
123void QgsAuthServersEditor::appendSslConfigsToGroup(
const QList<QgsAuthConfigSslServer> &configs, QgsAuthServersEditor::ConfigType conftype, QTreeWidgetItem *parent )
125 if ( configs.empty() )
130 parent = treeServerConfigs->currentItem();
134 const QMap<QString, QList<QgsAuthConfigSslServer>> orgconfigs(
138 QMap<QString, QList<QgsAuthConfigSslServer>>::const_iterator it = orgconfigs.constBegin();
139 for ( ; it != orgconfigs.constEnd(); ++it )
141 QTreeWidgetItem *grpitem(
new QTreeWidgetItem( parent, QStringList() << it.key(),
static_cast<int>( QgsAuthServersEditor::OrgName ) ) );
142 grpitem->setFirstColumnSpanned(
true );
143 grpitem->setFlags( Qt::ItemIsEnabled );
144 grpitem->setExpanded(
true );
146 QBrush orgb( grpitem->foreground( 0 ) );
147 orgb.setColor( QColor::fromRgb( 90, 90, 90 ) );
148 grpitem->setForeground( 0, orgb );
149 QFont grpf( grpitem->font( 0 ) );
150 grpf.setItalic(
true );
151 grpitem->setFont( 0, grpf );
153 appendSslConfigsToItem( it.value(), conftype, grpitem );
156 parent->sortChildren( 0, Qt::AscendingOrder );
159void QgsAuthServersEditor::appendSslConfigsToItem(
const QList<QgsAuthConfigSslServer> &configs, QgsAuthServersEditor::ConfigType conftype, QTreeWidgetItem *parent )
161 if ( configs.empty() )
166 parent = treeServerConfigs->currentItem();
172 const auto constConfigs = configs;
173 for (
const QgsAuthConfigSslServer &config : constConfigs )
175 const QSslCertificate cert( config.sslCertificate() );
180 coltxts << QString( config.sslHostPort() );
181 coltxts << cert.expiryDate().toString();
183 QTreeWidgetItem *item(
new QTreeWidgetItem( parent, coltxts,
static_cast<int>( conftype ) ) );
188 item->setForeground( 2, redb );
192 item->setData( 0, Qt::UserRole,
id );
195 parent->sortChildren( 0, Qt::AscendingOrder );
198void QgsAuthServersEditor::selectionChanged(
const QItemSelection &selected,
const QItemSelection &deselected )
201 Q_UNUSED( deselected )
205void QgsAuthServersEditor::checkSelection()
207 bool isconfig =
false;
208 if ( treeServerConfigs->selectionModel()->selection().length() > 0 )
210 QTreeWidgetItem *item( treeServerConfigs->currentItem() );
212 switch ( ( QgsAuthServersEditor::ConfigType ) item->type() )
214 case QgsAuthServersEditor::ServerConfig:
222 btnRemoveServer->setEnabled( isconfig );
223 btnEditServer->setEnabled( isconfig );
226void QgsAuthServersEditor::handleDoubleClick( QTreeWidgetItem *item,
int col )
229 bool isconfig =
true;
231 switch ( ( QgsAuthServersEditor::ConfigType ) item->type() )
233 case QgsAuthServersEditor::Section:
236 case QgsAuthServersEditor::OrgName:
245 btnEditServer_clicked();
249void QgsAuthServersEditor::btnAddServer_clicked()
251 QgsAuthSslImportDialog *dlg =
new QgsAuthSslImportDialog(
this );
252 dlg->setWindowModality( Qt::WindowModal );
253 dlg->resize( 580, 512 );
256 refreshSslConfigsView();
261void QgsAuthServersEditor::btnRemoveServer_clicked()
263 QTreeWidgetItem *item( treeServerConfigs->currentItem() );
267 QgsDebugMsgLevel( QStringLiteral(
"Current tree widget item not set" ), 2 );
271 const QString digest( item->data( 0, Qt::UserRole ).toString() );
272 const QString hostport( item->text( 1 ) );
274 if ( digest.isEmpty() )
279 if ( hostport.isEmpty() )
287 QgsDebugError( QStringLiteral(
"SSL custom config does not exist in database for host:port, id %1:" )
288 .arg( hostport, digest ) );
292 if ( QMessageBox::warning(
293 this, tr(
"Remove SSL Custom Configuration" ),
294 tr(
"Are you sure you want to remove the selected "
295 "SSL custom configuration from the database?\n\n"
296 "Operation can NOT be undone!" ),
297 QMessageBox::Ok | QMessageBox::Cancel,
300 == QMessageBox::Cancel )
307 messageBar()->pushMessage( tr(
"ERROR removing SSL custom config from authentication storage for host:port, id %1:" ).arg( hostport, digest ),
Qgis::MessageLevel::Critical );
311 item->parent()->removeChild( item );
315void QgsAuthServersEditor::btnEditServer_clicked()
317 QTreeWidgetItem *item( treeServerConfigs->currentItem() );
321 QgsDebugMsgLevel( QStringLiteral(
"Current tree widget item not set" ), 2 );
325 const QString digest( item->data( 0, Qt::UserRole ).toString() );
326 const QString hostport( item->text( 1 ) );
328 if ( digest.isEmpty() )
333 if ( hostport.isEmpty() )
341 QgsDebugError( QStringLiteral(
"SSL custom config does not exist in database" ) );
346 const QSslCertificate cert( config.sslCertificate() );
348 QgsAuthSslConfigDialog *dlg =
new QgsAuthSslConfigDialog(
this, cert, hostport );
350 dlg->setWindowModality( Qt::WindowModal );
351 dlg->resize( 500, 500 );
354 refreshSslConfigsView();
359void QgsAuthServersEditor::btnGroupByOrg_toggled(
bool checked )
363 authMessageLog( QObject::tr(
"Could not store sort by preference." ), QObject::tr(
"Authentication SSL Configs" ),
Qgis::MessageLevel::Warning );
365 populateSslConfigsView();
368void QgsAuthServersEditor::authMessageLog(
const QString &message,
const QString &authtag,
Qgis::MessageLevel level )
370 messageBar()->pushMessage( authtag, message, level, 7 );
377 treeServerConfigs->setFocus();
379 QWidget::showEvent( e );
387int QgsAuthServersEditor::messageTimeout()
389 const QgsSettings settings;
390 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.
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)
Returns a previously set authentication setting.
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
QgsAuthSslConfigWidget * sslCustomConfigWidget()
Access the embedded SSL server configuration widget.
A bar for displaying non-blocking messages to the user.
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)