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(
83 QStringList() << tr(
"Common Name" )
85 << tr(
"Expiry Date" )
87 treeServerConfigs->setColumnWidth( 0, 275 );
88 treeServerConfigs->setColumnWidth( 1, 200 );
91 mRootSslConfigItem =
new QTreeWidgetItem(
93 QStringList( tr(
"SSL Server Configurations" ) ),
94 static_cast<int>( QgsAuthServersEditor::Section )
97 mRootSslConfigItem->setFlags( Qt::ItemIsEnabled );
98 mRootSslConfigItem->setExpanded(
true );
99 treeServerConfigs->insertTopLevelItem( 0, mRootSslConfigItem );
102void QgsAuthServersEditor::populateSslConfigsView()
106 populateSslConfigsSection( mRootSslConfigItem,
QgsApplication::authManager()->sslCertCustomConfigs(), QgsAuthServersEditor::ServerConfig );
109void QgsAuthServersEditor::refreshSslConfigsView()
111 populateSslConfigsView();
114void QgsAuthServersEditor::populateSslConfigsSection( QTreeWidgetItem *item,
const QList<QgsAuthConfigSslServer> &configs, QgsAuthServersEditor::ConfigType conftype )
116 if ( btnGroupByOrg->isChecked() )
118 appendSslConfigsToGroup( configs, conftype, item );
122 appendSslConfigsToItem( configs, conftype, item );
126void QgsAuthServersEditor::appendSslConfigsToGroup(
const QList<QgsAuthConfigSslServer> &configs, QgsAuthServersEditor::ConfigType conftype, QTreeWidgetItem *parent )
128 if ( configs.empty() )
133 parent = treeServerConfigs->currentItem();
137 const QMap<QString, QList<QgsAuthConfigSslServer>> orgconfigs(
138 QgsAuthCertUtils::sslConfigsGroupedByOrg( configs )
141 QMap<QString, QList<QgsAuthConfigSslServer>>::const_iterator it = orgconfigs.constBegin();
142 for ( ; it != orgconfigs.constEnd(); ++it )
144 QTreeWidgetItem *grpitem(
new QTreeWidgetItem( parent, QStringList() << it.key(),
static_cast<int>( QgsAuthServersEditor::OrgName ) ) );
145 grpitem->setFirstColumnSpanned(
true );
146 grpitem->setFlags( Qt::ItemIsEnabled );
147 grpitem->setExpanded(
true );
149 QBrush orgb( grpitem->foreground( 0 ) );
150 orgb.setColor( QColor::fromRgb( 90, 90, 90 ) );
151 grpitem->setForeground( 0, orgb );
152 QFont grpf( grpitem->font( 0 ) );
153 grpf.setItalic(
true );
154 grpitem->setFont( 0, grpf );
156 appendSslConfigsToItem( it.value(), conftype, grpitem );
159 parent->sortChildren( 0, Qt::AscendingOrder );
162void QgsAuthServersEditor::appendSslConfigsToItem(
const QList<QgsAuthConfigSslServer> &configs, QgsAuthServersEditor::ConfigType conftype, QTreeWidgetItem *parent )
164 if ( configs.empty() )
169 parent = treeServerConfigs->currentItem();
175 const auto constConfigs = configs;
176 for (
const QgsAuthConfigSslServer &config : constConfigs )
178 const QSslCertificate cert( config.sslCertificate() );
179 const QString id( QgsAuthCertUtils::shaHexForCert( cert ) );
182 coltxts << QgsAuthCertUtils::resolvedCertName( cert );
183 coltxts << QString( config.sslHostPort() );
184 coltxts << cert.expiryDate().toString();
186 QTreeWidgetItem *item(
new QTreeWidgetItem( parent, coltxts,
static_cast<int>( conftype ) ) );
189 if ( !QgsAuthCertUtils::certIsViable( cert ) )
191 item->setForeground( 2, redb );
195 item->setData( 0, Qt::UserRole,
id );
198 parent->sortChildren( 0, Qt::AscendingOrder );
201void QgsAuthServersEditor::selectionChanged(
const QItemSelection &selected,
const QItemSelection &deselected )
204 Q_UNUSED( deselected )
208void QgsAuthServersEditor::checkSelection()
210 bool isconfig =
false;
211 if ( treeServerConfigs->selectionModel()->selection().length() > 0 )
213 QTreeWidgetItem *item( treeServerConfigs->currentItem() );
215 switch ( ( QgsAuthServersEditor::ConfigType ) item->type() )
217 case QgsAuthServersEditor::ServerConfig:
225 btnRemoveServer->setEnabled( isconfig );
226 btnEditServer->setEnabled( isconfig );
229void QgsAuthServersEditor::handleDoubleClick( QTreeWidgetItem *item,
int col )
232 bool isconfig =
true;
234 switch ( ( QgsAuthServersEditor::ConfigType ) item->type() )
236 case QgsAuthServersEditor::Section:
239 case QgsAuthServersEditor::OrgName:
248 btnEditServer_clicked();
252void QgsAuthServersEditor::btnAddServer_clicked()
254 QgsAuthSslImportDialog *dlg =
new QgsAuthSslImportDialog(
this );
255 dlg->setWindowModality( Qt::WindowModal );
256 dlg->resize( 580, 512 );
259 refreshSslConfigsView();
264void QgsAuthServersEditor::btnRemoveServer_clicked()
266 QTreeWidgetItem *item( treeServerConfigs->currentItem() );
274 const QString digest( item->data( 0, Qt::UserRole ).toString() );
275 const QString hostport( item->text( 1 ) );
277 if ( digest.isEmpty() )
282 if ( hostport.isEmpty() )
290 QgsDebugError( u
"SSL custom config does not exist in database for host:port, id %1:"_s
291 .arg( hostport, digest ) );
295 if ( QMessageBox::warning(
296 this, tr(
"Remove SSL Custom Configuration" ),
297 tr(
"Are you sure you want to remove the selected "
298 "SSL custom configuration from the database?\n\n"
299 "Operation can NOT be undone!" ),
300 QMessageBox::Ok | QMessageBox::Cancel,
303 == QMessageBox::Cancel )
310 messageBar()->pushMessage( tr(
"ERROR removing SSL custom config from authentication storage for host:port, id %1:" ).arg( hostport, digest ),
Qgis::MessageLevel::Critical );
314 item->parent()->removeChild( item );
318void QgsAuthServersEditor::btnEditServer_clicked()
320 QTreeWidgetItem *item( treeServerConfigs->currentItem() );
328 const QString digest( item->data( 0, Qt::UserRole ).toString() );
329 const QString hostport( item->text( 1 ) );
331 if ( digest.isEmpty() )
336 if ( hostport.isEmpty() )
344 QgsDebugError( u
"SSL custom config does not exist in database"_s );
349 const QSslCertificate cert( config.sslCertificate() );
351 QgsAuthSslConfigDialog *dlg =
new QgsAuthSslConfigDialog(
this, cert, hostport );
353 dlg->setWindowModality( Qt::WindowModal );
354 dlg->resize( 500, 500 );
357 refreshSslConfigsView();
362void QgsAuthServersEditor::btnGroupByOrg_toggled(
bool checked )
366 authMessageLog( QObject::tr(
"Could not store sort by preference." ), QObject::tr(
"Authentication SSL Configs" ),
Qgis::MessageLevel::Warning );
368 populateSslConfigsView();
371void QgsAuthServersEditor::authMessageLog(
const QString &message,
const QString &authtag,
Qgis::MessageLevel level )
373 messageBar()->pushMessage( authtag, message, level, 7 );
380 treeServerConfigs->setFocus();
382 QWidget::showEvent( e );
390int QgsAuthServersEditor::messageTimeout()
392 const QgsSettings settings;
393 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)