18 #include "ui_qgsauthserverseditor.h" 22 #include <QMessageBox> 38 mAuthNotifyLayout =
new QVBoxLayout;
39 this->setLayout( mAuthNotifyLayout );
41 mAuthNotifyLayout->addWidget( mAuthNotify );
46 connect( btnAddServer, &QToolButton::clicked,
this, &QgsAuthServersEditor::btnAddServer_clicked );
47 connect( btnRemoveServer, &QToolButton::clicked,
this, &QgsAuthServersEditor::btnRemoveServer_clicked );
48 connect( btnEditServer, &QToolButton::clicked,
this, &QgsAuthServersEditor::btnEditServer_clicked );
49 connect( btnGroupByOrg, &QToolButton::toggled,
this, &QgsAuthServersEditor::btnGroupByOrg_toggled );
52 this, &QgsAuthServersEditor::authMessageOut );
55 this, &QgsAuthServersEditor::refreshSslConfigsView );
57 setupSslConfigsTree();
59 connect( treeServerConfigs->selectionModel(), &QItemSelectionModel::selectionChanged,
60 this, &QgsAuthServersEditor::selectionChanged );
62 connect( treeServerConfigs, &QTreeWidget::itemDoubleClicked,
63 this, &QgsAuthServersEditor::handleDoubleClick );
65 connect( btnViewRefresh, &QAbstractButton::clicked,
this, &QgsAuthServersEditor::refreshSslConfigsView );
67 btnGroupByOrg->setChecked(
false );
69 if ( !sortbyval.isNull() )
70 btnGroupByOrg->setChecked( sortbyval.toBool() );
72 populateSslConfigsView();
77 static void setItemBold_( QTreeWidgetItem *item )
79 item->setFirstColumnSpanned(
true );
80 QFont secf( item->font( 0 ) );
82 item->setFont( 0, secf );
86 void QgsAuthServersEditor::setupSslConfigsTree()
88 treeServerConfigs->setColumnCount( 3 );
89 treeServerConfigs->setHeaderLabels(
90 QStringList() << tr(
"Common Name" )
92 << tr(
"Expiry Date" ) );
93 treeServerConfigs->setColumnWidth( 0, 275 );
94 treeServerConfigs->setColumnWidth( 1, 200 );
97 mRootSslConfigItem =
new QTreeWidgetItem(
99 QStringList( tr(
"SSL Server Configurations" ) ),
100 (
int )QgsAuthServersEditor::Section );
101 setItemBold_( mRootSslConfigItem );
102 mRootSslConfigItem->setFlags( Qt::ItemIsEnabled );
103 mRootSslConfigItem->setExpanded(
true );
104 treeServerConfigs->insertTopLevelItem( 0, mRootSslConfigItem );
107 static void removeChildren_( QTreeWidgetItem *item )
109 Q_FOREACH ( QTreeWidgetItem *child, item->takeChildren() )
115 void QgsAuthServersEditor::populateSslConfigsView()
117 removeChildren_( mRootSslConfigItem );
119 populateSslConfigsSection( mRootSslConfigItem,
121 QgsAuthServersEditor::ServerConfig );
124 void QgsAuthServersEditor::refreshSslConfigsView()
126 populateSslConfigsView();
129 void QgsAuthServersEditor::populateSslConfigsSection( QTreeWidgetItem *item,
130 const QList<QgsAuthConfigSslServer> &configs,
131 QgsAuthServersEditor::ConfigType conftype )
133 if ( btnGroupByOrg->isChecked() )
135 appendSslConfigsToGroup( configs, conftype, item );
139 appendSslConfigsToItem( configs, conftype, item );
143 void QgsAuthServersEditor::appendSslConfigsToGroup(
const QList<QgsAuthConfigSslServer> &configs,
144 QgsAuthServersEditor::ConfigType conftype,
145 QTreeWidgetItem *parent )
147 if ( configs.empty() )
152 parent = treeServerConfigs->currentItem();
156 QMap< QString, QList<QgsAuthConfigSslServer> > orgconfigs(
159 QMap< QString, QList<QgsAuthConfigSslServer> >::const_iterator it = orgconfigs.constBegin();
160 for ( ; it != orgconfigs.constEnd(); ++it )
162 QTreeWidgetItem *grpitem(
new QTreeWidgetItem( parent,
163 QStringList() << it.key(),
164 ( int )QgsAuthServersEditor::OrgName ) );
165 grpitem->setFirstColumnSpanned(
true );
166 grpitem->setFlags( Qt::ItemIsEnabled );
167 grpitem->setExpanded(
true );
169 QBrush orgb( grpitem->foreground( 0 ) );
170 orgb.setColor( QColor::fromRgb( 90, 90, 90 ) );
171 grpitem->setForeground( 0, orgb );
172 QFont grpf( grpitem->font( 0 ) );
173 grpf.setItalic(
true );
174 grpitem->setFont( 0, grpf );
176 appendSslConfigsToItem( it.value(), conftype, grpitem );
179 parent->sortChildren( 0, Qt::AscendingOrder );
182 void QgsAuthServersEditor::appendSslConfigsToItem(
const QList<QgsAuthConfigSslServer> &configs,
183 QgsAuthServersEditor::ConfigType conftype,
184 QTreeWidgetItem *parent )
186 if ( configs.empty() )
191 parent = treeServerConfigs->currentItem();
205 coltxts << cert.expiryDate().toString();
207 QTreeWidgetItem *item(
new QTreeWidgetItem( parent, coltxts, (
int )conftype ) );
212 item->setForeground( 2, redb );
216 item->setData( 0, Qt::UserRole,
id );
219 parent->sortChildren( 0, Qt::AscendingOrder );
222 void QgsAuthServersEditor::selectionChanged(
const QItemSelection &selected,
const QItemSelection &deselected )
224 Q_UNUSED( selected );
225 Q_UNUSED( deselected );
229 void QgsAuthServersEditor::checkSelection()
231 bool isconfig =
false;
232 if ( treeServerConfigs->selectionModel()->selection().length() > 0 )
234 QTreeWidgetItem *item( treeServerConfigs->currentItem() );
236 switch ( ( QgsAuthServersEditor::ConfigType )item->type() )
238 case QgsAuthServersEditor::ServerConfig :
246 btnRemoveServer->setEnabled( isconfig );
247 btnEditServer->setEnabled( isconfig );
250 void QgsAuthServersEditor::handleDoubleClick( QTreeWidgetItem *item,
int col )
253 bool isconfig =
true;
255 switch ( ( QgsAuthServersEditor::ConfigType )item->type() )
257 case QgsAuthServersEditor::Section:
260 case QgsAuthServersEditor::OrgName:
269 btnEditServer_clicked();
273 void QgsAuthServersEditor::btnAddServer_clicked()
276 dlg->setWindowModality( Qt::WindowModal );
277 dlg->resize( 580, 512 );
280 refreshSslConfigsView();
285 void QgsAuthServersEditor::btnRemoveServer_clicked()
287 QTreeWidgetItem *item( treeServerConfigs->currentItem() );
295 QString digest( item->data( 0, Qt::UserRole ).toString() );
296 QString hostport( item->text( 1 ) );
298 if ( digest.isEmpty() )
300 messageBar()->
pushMessage( tr(
"SSL custom config id missing" ),
304 if ( hostport.isEmpty() )
306 messageBar()->
pushMessage( tr(
"SSL custom config host:port missing" ),
313 QgsDebugMsg( QString(
"SSL custom config does not exist in database for host:port, id %1:" )
314 .arg( hostport, digest ) );
318 if ( QMessageBox::warning(
319 this, tr(
"Remove SSL Custom Configuration" ),
320 tr(
"Are you sure you want to remove the selected " 321 "SSL custom configuration from the database?\n\n" 322 "Operation can NOT be undone!" ),
323 QMessageBox::Ok | QMessageBox::Cancel,
324 QMessageBox::Cancel ) == QMessageBox::Cancel )
331 messageBar()->
pushMessage( tr(
"ERROR removing SSL custom config from authentication database for host:port, id %1:" )
332 .arg( hostport, digest ),
337 item->parent()->removeChild( item );
341 void QgsAuthServersEditor::btnEditServer_clicked()
343 QTreeWidgetItem *item( treeServerConfigs->currentItem() );
351 QString digest( item->data( 0, Qt::UserRole ).toString() );
352 QString hostport( item->text( 1 ) );
354 if ( digest.isEmpty() )
356 messageBar()->
pushMessage( tr(
"SSL custom config id missing." ),
360 if ( hostport.isEmpty() )
362 messageBar()->
pushMessage( tr(
"SSL custom config host:port missing." ),
369 QgsDebugMsg(
"SSL custom config does not exist in database" );
377 dlg->sslCustomConfigWidget()->setConfigCheckable(
false );
378 dlg->setWindowModality( Qt::WindowModal );
379 dlg->resize( 500, 500 );
382 refreshSslConfigsView();
387 void QgsAuthServersEditor::btnGroupByOrg_toggled(
bool checked )
391 authMessageOut( QObject::tr(
"Could not store sort by preference." ),
392 QObject::tr(
"Authentication SSL Configs" ),
395 populateSslConfigsView();
400 int levelint = ( int )level;
408 treeServerConfigs->setFocus();
410 QWidget::showEvent( e );
418 int QgsAuthServersEditor::messageTimeout()
421 return settings.
value( QStringLiteral(
"qgis/messageTimeout" ), 5 ).toInt();
void messageOut(const QString &message, const QString &tag=QgsAuthManager::AUTH_MAN_TAG, QgsAuthManager::MessageLevel level=QgsAuthManager::INFO) const
Custom logging signal to relay to console output and QgsMessageLog.
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.
A bar for displaying non-blocking messages to the user.
Configuration container for SSL server connection exceptions or overrides.
static QIcon getThemeIcon(const QString &name)
Helper to get a theme icon.
MessageLevel
Level for messages This will be used both for message log and message bar in application.
MessageLevel
Message log level (mirrors that of QgsMessageLog, so it can also output there)
static bool certIsViable(const QSslCertificate &cert)
certIsViable checks for viability errors of cert and whether it is NULL
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, erased, etc.
static QMap< QString, QList< QgsAuthConfigSslServer > > sslConfigsGroupedByOrg(const QList< QgsAuthConfigSslServer > &configs)
Map SSL custom configs' certificates to their oraganization.
const QString sslHostPort() const
Server host:port string.
void pushMessage(const QString &text, Qgis::MessageLevel level=Qgis::Info, int duration=5)
convenience method for pushing a message to the bar
static QString shaHexForCert(const QSslCertificate &cert, bool formatted=false)
Gets the sha1 hash for certificate.
static QgsAuthManager * authManager()
Returns the application's authentication manager instance.
const QSslCertificate sslCertificate() const
Server certificate object.
Dialog wrapper of widget for editing an SSL server configuration.
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 showEvent(QShowEvent *e) override
QgsAuthServersEditor(QWidget *parent=nullptr)
Widget for editing authentication configurations directly in database.
Widget for importing an SSL server certificate exception into the authentication database.
static QString resolvedCertName(const QSslCertificate &cert, bool issuer=false)
Gets the general name via RFC 5280 resolution.