17#include "ui_qgsauthserverseditor.h"
35#include "moc_qgsauthserverseditor.cpp"
37using namespace Qt::StringLiterals;
45 mAuthNotifyLayout =
new QVBoxLayout;
46 this->setLayout( mAuthNotifyLayout );
48 mAuthNotifyLayout->addWidget( mAuthNotify );
53 connect( btnAddServer, &QToolButton::clicked,
this, &QgsAuthServersEditor::btnAddServer_clicked );
54 connect( btnRemoveServer, &QToolButton::clicked,
this, &QgsAuthServersEditor::btnRemoveServer_clicked );
55 connect( btnEditServer, &QToolButton::clicked,
this, &QgsAuthServersEditor::btnEditServer_clicked );
56 connect( btnGroupByOrg, &QToolButton::toggled,
this, &QgsAuthServersEditor::btnGroupByOrg_toggled );
62 setupSslConfigsTree();
64 connect( treeServerConfigs->selectionModel(), &QItemSelectionModel::selectionChanged,
this, &QgsAuthServersEditor::selectionChanged );
66 connect( treeServerConfigs, &QTreeWidget::itemDoubleClicked,
this, &QgsAuthServersEditor::handleDoubleClick );
68 connect( btnViewRefresh, &QAbstractButton::clicked,
this, &QgsAuthServersEditor::refreshSslConfigsView );
70 btnGroupByOrg->setChecked(
false );
73 btnGroupByOrg->setChecked( sortbyval.toBool() );
75 populateSslConfigsView();
80void QgsAuthServersEditor::setupSslConfigsTree()
82 treeServerConfigs->setColumnCount( 3 );
83 treeServerConfigs->setHeaderLabels( QStringList() << tr(
"Common Name" ) << tr(
"Host" ) << tr(
"Expiry Date" ) );
84 treeServerConfigs->setColumnWidth( 0, 275 );
85 treeServerConfigs->setColumnWidth( 1, 200 );
88 mRootSslConfigItem =
new QTreeWidgetItem( treeServerConfigs, QStringList( tr(
"SSL Server Configurations" ) ),
static_cast<int>( QgsAuthServersEditor::Section ) );
90 mRootSslConfigItem->setFlags( Qt::ItemIsEnabled );
91 mRootSslConfigItem->setExpanded(
true );
92 treeServerConfigs->insertTopLevelItem( 0, mRootSslConfigItem );
95void QgsAuthServersEditor::populateSslConfigsView()
99 populateSslConfigsSection( mRootSslConfigItem,
QgsApplication::authManager()->sslCertCustomConfigs(), QgsAuthServersEditor::ServerConfig );
102void QgsAuthServersEditor::refreshSslConfigsView()
104 populateSslConfigsView();
107void QgsAuthServersEditor::populateSslConfigsSection( QTreeWidgetItem *item,
const QList<QgsAuthConfigSslServer> &configs, QgsAuthServersEditor::ConfigType conftype )
109 if ( btnGroupByOrg->isChecked() )
111 appendSslConfigsToGroup( configs, conftype, item );
115 appendSslConfigsToItem( configs, conftype, item );
119void QgsAuthServersEditor::appendSslConfigsToGroup(
const QList<QgsAuthConfigSslServer> &configs, QgsAuthServersEditor::ConfigType conftype, QTreeWidgetItem *parent )
121 if ( configs.empty() )
126 parent = treeServerConfigs->currentItem();
130 const QMap<QString, QList<QgsAuthConfigSslServer>> orgconfigs( QgsAuthCertUtils::sslConfigsGroupedByOrg( configs ) );
132 QMap<QString, QList<QgsAuthConfigSslServer>>::const_iterator it = orgconfigs.constBegin();
133 for ( ; it != orgconfigs.constEnd(); ++it )
135 QTreeWidgetItem *grpitem(
new QTreeWidgetItem( parent, QStringList() << it.key(),
static_cast<int>( QgsAuthServersEditor::OrgName ) ) );
136 grpitem->setFirstColumnSpanned(
true );
137 grpitem->setFlags( Qt::ItemIsEnabled );
138 grpitem->setExpanded(
true );
140 QBrush orgb( grpitem->foreground( 0 ) );
141 orgb.setColor( QColor::fromRgb( 90, 90, 90 ) );
142 grpitem->setForeground( 0, orgb );
143 QFont grpf( grpitem->font( 0 ) );
144 grpf.setItalic(
true );
145 grpitem->setFont( 0, grpf );
147 appendSslConfigsToItem( it.value(), conftype, grpitem );
150 parent->sortChildren( 0, Qt::AscendingOrder );
153void QgsAuthServersEditor::appendSslConfigsToItem(
const QList<QgsAuthConfigSslServer> &configs, QgsAuthServersEditor::ConfigType conftype, QTreeWidgetItem *parent )
155 if ( configs.empty() )
160 parent = treeServerConfigs->currentItem();
166 const auto constConfigs = configs;
167 for (
const QgsAuthConfigSslServer &config : constConfigs )
169 const QSslCertificate cert( config.sslCertificate() );
170 const QString id( QgsAuthCertUtils::shaHexForCert( cert ) );
173 coltxts << QgsAuthCertUtils::resolvedCertName( cert );
174 coltxts << QString( config.sslHostPort() );
175 coltxts << cert.expiryDate().toString();
177 QTreeWidgetItem *item(
new QTreeWidgetItem( parent, coltxts,
static_cast<int>( conftype ) ) );
180 if ( !QgsAuthCertUtils::certIsViable( cert ) )
182 item->setForeground( 2, redb );
186 item->setData( 0, Qt::UserRole,
id );
189 parent->sortChildren( 0, Qt::AscendingOrder );
192void QgsAuthServersEditor::selectionChanged(
const QItemSelection &selected,
const QItemSelection &deselected )
195 Q_UNUSED( deselected )
199void QgsAuthServersEditor::checkSelection()
201 bool isconfig =
false;
202 if ( treeServerConfigs->selectionModel()->selection().length() > 0 )
204 QTreeWidgetItem *item( treeServerConfigs->currentItem() );
206 switch ( ( QgsAuthServersEditor::ConfigType ) item->type() )
208 case QgsAuthServersEditor::ServerConfig:
216 btnRemoveServer->setEnabled( isconfig );
217 btnEditServer->setEnabled( isconfig );
220void QgsAuthServersEditor::handleDoubleClick( QTreeWidgetItem *item,
int col )
223 bool isconfig =
true;
225 switch ( ( QgsAuthServersEditor::ConfigType ) item->type() )
227 case QgsAuthServersEditor::Section:
230 case QgsAuthServersEditor::OrgName:
239 btnEditServer_clicked();
243void QgsAuthServersEditor::btnAddServer_clicked()
245 QgsAuthSslImportDialog *dlg =
new QgsAuthSslImportDialog(
this );
246 dlg->setWindowModality( Qt::WindowModal );
247 dlg->resize( 580, 512 );
250 refreshSslConfigsView();
255void QgsAuthServersEditor::btnRemoveServer_clicked()
257 QTreeWidgetItem *item( treeServerConfigs->currentItem() );
265 const QString digest( item->data( 0, Qt::UserRole ).toString() );
266 const QString hostport( item->text( 1 ) );
268 if ( digest.isEmpty() )
273 if ( hostport.isEmpty() )
281 QgsDebugError( u
"SSL custom config does not exist in database for host:port, id %1:"_s.arg( hostport, digest ) );
285 if ( QMessageBox::warning(
287 tr(
"Remove SSL Custom Configuration" ),
289 "Are you sure you want to remove the selected "
290 "SSL custom configuration from the database?\n\n"
291 "Operation can NOT be undone!"
293 QMessageBox::Ok | QMessageBox::Cancel,
296 == QMessageBox::Cancel )
303 messageBar()->pushMessage( tr(
"ERROR removing SSL custom config from authentication storage for host:port, id %1:" ).arg( hostport, digest ),
Qgis::MessageLevel::Critical );
307 item->parent()->removeChild( item );
311void QgsAuthServersEditor::btnEditServer_clicked()
313 QTreeWidgetItem *item( treeServerConfigs->currentItem() );
321 const QString digest( item->data( 0, Qt::UserRole ).toString() );
322 const QString hostport( item->text( 1 ) );
324 if ( digest.isEmpty() )
329 if ( hostport.isEmpty() )
337 QgsDebugError( u
"SSL custom config does not exist in database"_s );
342 const QSslCertificate cert( config.sslCertificate() );
344 QgsAuthSslConfigDialog *dlg =
new QgsAuthSslConfigDialog(
this, cert, hostport );
346 dlg->setWindowModality( Qt::WindowModal );
347 dlg->resize( 500, 500 );
350 refreshSslConfigsView();
355void QgsAuthServersEditor::btnGroupByOrg_toggled(
bool checked )
359 authMessageLog( QObject::tr(
"Could not store sort by preference." ), QObject::tr(
"Authentication SSL Configs" ),
Qgis::MessageLevel::Warning );
361 populateSslConfigsView();
364void QgsAuthServersEditor::authMessageLog(
const QString &message,
const QString &authtag,
Qgis::MessageLevel level )
366 messageBar()->pushMessage( authtag, message, level, 7 );
373 treeServerConfigs->setFocus();
375 QWidget::showEvent( e );
383int QgsAuthServersEditor::messageTimeout()
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.
T value(const QString &dynamicKeyPart=QString()) const
Returns settings value.
static const QgsSettingsEntryInteger * settingsMessageTimeout
Settings entry message timeout in seconds.
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)