17#include "ui_qgsauthserverseditor.h"
34#include "moc_qgsauthserverseditor.cpp"
36using namespace Qt::StringLiterals;
44 mAuthNotifyLayout =
new QVBoxLayout;
45 this->setLayout( mAuthNotifyLayout );
47 mAuthNotifyLayout->addWidget( mAuthNotify );
52 connect( btnAddServer, &QToolButton::clicked,
this, &QgsAuthServersEditor::btnAddServer_clicked );
53 connect( btnRemoveServer, &QToolButton::clicked,
this, &QgsAuthServersEditor::btnRemoveServer_clicked );
54 connect( btnEditServer, &QToolButton::clicked,
this, &QgsAuthServersEditor::btnEditServer_clicked );
55 connect( btnGroupByOrg, &QToolButton::toggled,
this, &QgsAuthServersEditor::btnGroupByOrg_toggled );
61 setupSslConfigsTree();
63 connect( treeServerConfigs->selectionModel(), &QItemSelectionModel::selectionChanged,
this, &QgsAuthServersEditor::selectionChanged );
65 connect( treeServerConfigs, &QTreeWidget::itemDoubleClicked,
this, &QgsAuthServersEditor::handleDoubleClick );
67 connect( btnViewRefresh, &QAbstractButton::clicked,
this, &QgsAuthServersEditor::refreshSslConfigsView );
69 btnGroupByOrg->setChecked(
false );
72 btnGroupByOrg->setChecked( sortbyval.toBool() );
74 populateSslConfigsView();
79void QgsAuthServersEditor::setupSslConfigsTree()
81 treeServerConfigs->setColumnCount( 3 );
82 treeServerConfigs->setHeaderLabels( QStringList() << tr(
"Common Name" ) << tr(
"Host" ) << tr(
"Expiry Date" ) );
83 treeServerConfigs->setColumnWidth( 0, 275 );
84 treeServerConfigs->setColumnWidth( 1, 200 );
87 mRootSslConfigItem =
new QTreeWidgetItem( treeServerConfigs, QStringList( tr(
"SSL Server Configurations" ) ),
static_cast<int>( QgsAuthServersEditor::Section ) );
89 mRootSslConfigItem->setFlags( Qt::ItemIsEnabled );
90 mRootSslConfigItem->setExpanded(
true );
91 treeServerConfigs->insertTopLevelItem( 0, mRootSslConfigItem );
94void QgsAuthServersEditor::populateSslConfigsView()
98 populateSslConfigsSection( mRootSslConfigItem,
QgsApplication::authManager()->sslCertCustomConfigs(), QgsAuthServersEditor::ServerConfig );
101void QgsAuthServersEditor::refreshSslConfigsView()
103 populateSslConfigsView();
106void QgsAuthServersEditor::populateSslConfigsSection( QTreeWidgetItem *item,
const QList<QgsAuthConfigSslServer> &configs, QgsAuthServersEditor::ConfigType conftype )
108 if ( btnGroupByOrg->isChecked() )
110 appendSslConfigsToGroup( configs, conftype, item );
114 appendSslConfigsToItem( configs, conftype, item );
118void QgsAuthServersEditor::appendSslConfigsToGroup(
const QList<QgsAuthConfigSslServer> &configs, QgsAuthServersEditor::ConfigType conftype, QTreeWidgetItem *parent )
120 if ( configs.empty() )
125 parent = treeServerConfigs->currentItem();
129 const QMap<QString, QList<QgsAuthConfigSslServer>> orgconfigs( QgsAuthCertUtils::sslConfigsGroupedByOrg( configs ) );
131 QMap<QString, QList<QgsAuthConfigSslServer>>::const_iterator it = orgconfigs.constBegin();
132 for ( ; it != orgconfigs.constEnd(); ++it )
134 QTreeWidgetItem *grpitem(
new QTreeWidgetItem( parent, QStringList() << it.key(),
static_cast<int>( QgsAuthServersEditor::OrgName ) ) );
135 grpitem->setFirstColumnSpanned(
true );
136 grpitem->setFlags( Qt::ItemIsEnabled );
137 grpitem->setExpanded(
true );
139 QBrush orgb( grpitem->foreground( 0 ) );
140 orgb.setColor( QColor::fromRgb( 90, 90, 90 ) );
141 grpitem->setForeground( 0, orgb );
142 QFont grpf( grpitem->font( 0 ) );
143 grpf.setItalic(
true );
144 grpitem->setFont( 0, grpf );
146 appendSslConfigsToItem( it.value(), conftype, grpitem );
149 parent->sortChildren( 0, Qt::AscendingOrder );
152void QgsAuthServersEditor::appendSslConfigsToItem(
const QList<QgsAuthConfigSslServer> &configs, QgsAuthServersEditor::ConfigType conftype, QTreeWidgetItem *parent )
154 if ( configs.empty() )
159 parent = treeServerConfigs->currentItem();
165 const auto constConfigs = configs;
166 for (
const QgsAuthConfigSslServer &config : constConfigs )
168 const QSslCertificate cert( config.sslCertificate() );
169 const QString id( QgsAuthCertUtils::shaHexForCert( cert ) );
172 coltxts << QgsAuthCertUtils::resolvedCertName( cert );
173 coltxts << QString( config.sslHostPort() );
174 coltxts << cert.expiryDate().toString();
176 QTreeWidgetItem *item(
new QTreeWidgetItem( parent, coltxts,
static_cast<int>( conftype ) ) );
179 if ( !QgsAuthCertUtils::certIsViable( cert ) )
181 item->setForeground( 2, redb );
185 item->setData( 0, Qt::UserRole,
id );
188 parent->sortChildren( 0, Qt::AscendingOrder );
191void QgsAuthServersEditor::selectionChanged(
const QItemSelection &selected,
const QItemSelection &deselected )
194 Q_UNUSED( deselected )
198void QgsAuthServersEditor::checkSelection()
200 bool isconfig =
false;
201 if ( treeServerConfigs->selectionModel()->selection().length() > 0 )
203 QTreeWidgetItem *item( treeServerConfigs->currentItem() );
205 switch ( ( QgsAuthServersEditor::ConfigType ) item->type() )
207 case QgsAuthServersEditor::ServerConfig:
215 btnRemoveServer->setEnabled( isconfig );
216 btnEditServer->setEnabled( isconfig );
219void QgsAuthServersEditor::handleDoubleClick( QTreeWidgetItem *item,
int col )
222 bool isconfig =
true;
224 switch ( ( QgsAuthServersEditor::ConfigType ) item->type() )
226 case QgsAuthServersEditor::Section:
229 case QgsAuthServersEditor::OrgName:
238 btnEditServer_clicked();
242void QgsAuthServersEditor::btnAddServer_clicked()
244 QgsAuthSslImportDialog *dlg =
new QgsAuthSslImportDialog(
this );
245 dlg->setWindowModality( Qt::WindowModal );
246 dlg->resize( 580, 512 );
249 refreshSslConfigsView();
254void QgsAuthServersEditor::btnRemoveServer_clicked()
256 QTreeWidgetItem *item( treeServerConfigs->currentItem() );
264 const QString digest( item->data( 0, Qt::UserRole ).toString() );
265 const QString hostport( item->text( 1 ) );
267 if ( digest.isEmpty() )
272 if ( hostport.isEmpty() )
280 QgsDebugError( u
"SSL custom config does not exist in database for host:port, id %1:"_s.arg( hostport, digest ) );
284 if ( QMessageBox::warning(
286 tr(
"Remove SSL Custom Configuration" ),
288 "Are you sure you want to remove the selected "
289 "SSL custom configuration from the database?\n\n"
290 "Operation can NOT be undone!"
292 QMessageBox::Ok | QMessageBox::Cancel,
295 == QMessageBox::Cancel )
302 messageBar()->pushMessage( tr(
"ERROR removing SSL custom config from authentication storage for host:port, id %1:" ).arg( hostport, digest ),
Qgis::MessageLevel::Critical );
306 item->parent()->removeChild( item );
310void QgsAuthServersEditor::btnEditServer_clicked()
312 QTreeWidgetItem *item( treeServerConfigs->currentItem() );
320 const QString digest( item->data( 0, Qt::UserRole ).toString() );
321 const QString hostport( item->text( 1 ) );
323 if ( digest.isEmpty() )
328 if ( hostport.isEmpty() )
336 QgsDebugError( u
"SSL custom config does not exist in database"_s );
341 const QSslCertificate cert( config.sslCertificate() );
343 QgsAuthSslConfigDialog *dlg =
new QgsAuthSslConfigDialog(
this, cert, hostport );
345 dlg->setWindowModality( Qt::WindowModal );
346 dlg->resize( 500, 500 );
349 refreshSslConfigsView();
354void QgsAuthServersEditor::btnGroupByOrg_toggled(
bool checked )
358 authMessageLog( QObject::tr(
"Could not store sort by preference." ), QObject::tr(
"Authentication SSL Configs" ),
Qgis::MessageLevel::Warning );
360 populateSslConfigsView();
363void QgsAuthServersEditor::authMessageLog(
const QString &message,
const QString &authtag,
Qgis::MessageLevel level )
365 messageBar()->pushMessage( authtag, message, level, 7 );
372 treeServerConfigs->setFocus();
374 QWidget::showEvent( e );
382int QgsAuthServersEditor::messageTimeout()
384 const QgsSettings settings;
385 return settings.
value( u
"qgis/messageTimeout"_s, 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 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)