18#include "moc_qgsauthidentitieseditor.cpp"
19#include "ui_qgsauthidentitieseditor.h"
40 mAuthNotifyLayout =
new QVBoxLayout;
41 this->setLayout( mAuthNotifyLayout );
43 mAuthNotifyLayout->addWidget( mAuthNotify );
48 connect( btnAddIdentity, &QToolButton::clicked,
this, &QgsAuthIdentitiesEditor::btnAddIdentity_clicked );
49 connect( btnRemoveIdentity, &QToolButton::clicked,
this, &QgsAuthIdentitiesEditor::btnRemoveIdentity_clicked );
50 connect( btnInfoIdentity, &QToolButton::clicked,
this, &QgsAuthIdentitiesEditor::btnInfoIdentity_clicked );
51 connect( btnGroupByOrg, &QToolButton::toggled,
this, &QgsAuthIdentitiesEditor::btnGroupByOrg_toggled );
54 this, &QgsAuthIdentitiesEditor::authMessageLog );
57 this, &QgsAuthIdentitiesEditor::refreshIdentitiesView );
59 setupIdentitiesTree();
61 connect( treeIdentities->selectionModel(), &QItemSelectionModel::selectionChanged,
62 this, &QgsAuthIdentitiesEditor::selectionChanged );
64 connect( treeIdentities, &QTreeWidget::itemDoubleClicked,
65 this, &QgsAuthIdentitiesEditor::handleDoubleClick );
67 connect( btnViewRefresh, &QAbstractButton::clicked,
this, &QgsAuthIdentitiesEditor::refreshIdentitiesView );
69 btnGroupByOrg->setChecked(
false );
72 btnGroupByOrg->setChecked( sortbyval.toBool() );
74 populateIdentitiesView();
79static void setItemBold_( QTreeWidgetItem *item )
81 item->setFirstColumnSpanned(
true );
82 QFont secf( item->font( 0 ) );
84 item->setFont( 0, secf );
87void QgsAuthIdentitiesEditor::setupIdentitiesTree()
89 treeIdentities->setColumnCount( 3 );
90 treeIdentities->setHeaderLabels(
91 QStringList() << tr(
"Common Name" )
93 << tr(
"Expiry Date" ) );
94 treeIdentities->setColumnWidth( 0, 300 );
95 treeIdentities->setColumnWidth( 1, 75 );
98 mRootCertIdentItem =
new QTreeWidgetItem(
100 QStringList( tr(
"Certificate Bundles" ) ),
101 static_cast<int>( QgsAuthIdentitiesEditor::Section ) );
102 setItemBold_( mRootCertIdentItem );
103 mRootCertIdentItem->setFlags( Qt::ItemIsEnabled );
104 mRootCertIdentItem->setExpanded(
true );
105 treeIdentities->insertTopLevelItem( 0, mRootCertIdentItem );
108static void removeChildren_( QTreeWidgetItem *item )
110 const auto constTakeChildren = item->takeChildren();
111 for ( QTreeWidgetItem *child : constTakeChildren )
117void QgsAuthIdentitiesEditor::populateIdentitiesView()
119 removeChildren_( mRootCertIdentItem );
121 populateIdentitiesSection( mRootCertIdentItem,
123 QgsAuthIdentitiesEditor::CertIdentity );
126void QgsAuthIdentitiesEditor::refreshIdentitiesView()
128 populateIdentitiesView();
131void QgsAuthIdentitiesEditor::populateIdentitiesSection( QTreeWidgetItem *item,
const QList<QSslCertificate> &certs,
132 QgsAuthIdentitiesEditor::IdentityType identype )
134 if ( btnGroupByOrg->isChecked() )
136 appendIdentitiesToGroup( certs, identype, item );
140 appendIdentitiesToItem( certs, identype, item );
144void QgsAuthIdentitiesEditor::appendIdentitiesToGroup(
const QList<QSslCertificate> &certs,
145 QgsAuthIdentitiesEditor::IdentityType identype,
146 QTreeWidgetItem *parent )
153 parent = treeIdentities->currentItem();
157 const QMap< QString, QList<QSslCertificate> > orgcerts(
160 QMap< QString, QList<QSslCertificate> >::const_iterator it = orgcerts.constBegin();
161 for ( ; it != orgcerts.constEnd(); ++it )
163 QTreeWidgetItem *grpitem(
new QTreeWidgetItem( parent,
164 QStringList() << it.key(),
165 static_cast<int>( QgsAuthIdentitiesEditor::OrgName ) ) );
166 grpitem->setFirstColumnSpanned(
true );
167 grpitem->setFlags( Qt::ItemIsEnabled );
168 grpitem->setExpanded(
true );
170 QBrush orgb( grpitem->foreground( 0 ) );
171 orgb.setColor( QColor::fromRgb( 90, 90, 90 ) );
172 grpitem->setForeground( 0, orgb );
173 QFont grpf( grpitem->font( 0 ) );
174 grpf.setItalic(
true );
175 grpitem->setFont( 0, grpf );
177 appendIdentitiesToItem( it.value(), identype, grpitem );
180 parent->sortChildren( 0, Qt::AscendingOrder );
183void QgsAuthIdentitiesEditor::appendIdentitiesToItem(
const QList<QSslCertificate> &certs,
184 QgsAuthIdentitiesEditor::IdentityType identype,
185 QTreeWidgetItem *parent )
192 parent = treeIdentities->currentItem();
198 const auto constCerts = certs;
199 for (
const QSslCertificate &cert : constCerts )
205 coltxts << QString( cert.serialNumber() );
206 coltxts << cert.expiryDate().toString();
208 QTreeWidgetItem *item(
new QTreeWidgetItem( parent, coltxts,
static_cast<int>( identype ) ) );
213 item->setForeground( 2, redb );
217 item->setData( 0, Qt::UserRole,
id );
220 parent->sortChildren( 0, Qt::AscendingOrder );
223void QgsAuthIdentitiesEditor::showCertInfo( QTreeWidgetItem *item )
228 const QString digest( item->data( 0, Qt::UserRole ).toString() );
232 QgsDebugError( QStringLiteral(
"Certificate identity does not exist in database" ) );
239 dlg->setWindowModality( Qt::WindowModal );
240 dlg->resize( 675, 500 );
245void QgsAuthIdentitiesEditor::selectionChanged(
const QItemSelection &selected,
const QItemSelection &deselected )
248 Q_UNUSED( deselected )
252void QgsAuthIdentitiesEditor::checkSelection()
255 if ( treeIdentities->selectionModel()->selection().length() > 0 )
257 QTreeWidgetItem *item( treeIdentities->currentItem() );
259 switch ( ( QgsAuthIdentitiesEditor::IdentityType )item->type() )
261 case QgsAuthIdentitiesEditor::CertIdentity:
269 btnRemoveIdentity->setEnabled( iscert );
270 btnInfoIdentity->setEnabled( iscert );
273void QgsAuthIdentitiesEditor::handleDoubleClick( QTreeWidgetItem *item,
int col )
278 switch ( ( QgsAuthIdentitiesEditor::IdentityType )item->type() )
280 case QgsAuthIdentitiesEditor::Section:
283 case QgsAuthIdentitiesEditor::OrgName:
292 showCertInfo( item );
296void QgsAuthIdentitiesEditor::btnAddIdentity_clicked()
299 dlg->setWindowModality( Qt::WindowModal );
300 dlg->resize( 400, dlg->height() );
308 messageBar()->
pushMessage( tr(
"ERROR storing identity bundle in authentication database." ),
311 populateIdentitiesView();
312 mRootCertIdentItem->setExpanded(
true );
318void QgsAuthIdentitiesEditor::btnRemoveIdentity_clicked()
320 QTreeWidgetItem *item( treeIdentities->currentItem() );
324 QgsDebugMsgLevel( QStringLiteral(
"Current tree widget item not set" ), 2 );
328 const QString digest( item->data( 0, Qt::UserRole ).toString() );
330 if ( digest.isEmpty() )
332 messageBar()->
pushMessage( tr(
"Certificate id missing." ),
339 QgsDebugError( QStringLiteral(
"Certificate identity does not exist in database" ) );
343 if ( QMessageBox::warning(
344 this, tr(
"Remove Certificate Identity" ),
345 tr(
"Are you sure you want to remove the selected "
346 "certificate identity from the database?\n\n"
347 "Operation can NOT be undone!" ),
348 QMessageBox::Ok | QMessageBox::Cancel,
349 QMessageBox::Cancel ) == QMessageBox::Cancel )
356 messageBar()->
pushMessage( tr(
"ERROR removing cert identity from authentication database for id %1:" ).arg( digest ),
361 item->parent()->removeChild( item );
365void QgsAuthIdentitiesEditor::btnInfoIdentity_clicked()
367 if ( treeIdentities->selectionModel()->selection().length() > 0 )
369 QTreeWidgetItem *item( treeIdentities->currentItem() );
370 handleDoubleClick( item, 0 );
374void QgsAuthIdentitiesEditor::btnGroupByOrg_toggled(
bool checked )
378 authMessageLog( QObject::tr(
"Could not store sort by preference." ),
379 QObject::tr(
"Authentication Identities" ),
382 populateIdentitiesView();
385void QgsAuthIdentitiesEditor::authMessageLog(
const QString &message,
const QString &authtag,
Qgis::MessageLevel level )
387 messageBar()->
pushMessage( authtag, message, level, 7 );
394 treeIdentities->setFocus();
396 QWidget::showEvent( e );
404int QgsAuthIdentitiesEditor::messageTimeout()
407 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.
Dialog wrapper for widget displaying detailed info on a certificate and its hierarchical trust chain.
static QString resolvedCertName(const QSslCertificate &cert, bool issuer=false)
Gets the general name via RFC 5280 resolution.
static QMap< QString, QList< QSslCertificate > > certsGroupedByOrg(const QList< QSslCertificate > &certs)
Map certificates to their oraganization.
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 QColor redColor()
Red color representing invalid, untrusted, etc. certificate.
void showEvent(QShowEvent *e) override
Overridden show event of base widget.
QgsAuthIdentitiesEditor(QWidget *parent=nullptr)
Widget for editing authentication configurations directly in database.
Widget for importing an identity certificate/key bundle into the authentication database.
QgsAuthImportIdentityDialog::IdentityType identityType()
Gets identity type.
const QPair< QSslCertificate, QSslKey > certBundleToImport()
Gets certificate/key bundle to be imported.
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)
authSetting get an authentication setting (retrieved as string and returned as QVariant( QString ))
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.
A bar for displaying non-blocking messages to the user.
void pushMessage(const QString &text, Qgis::MessageLevel level=Qgis::MessageLevel::Info, int duration=-1)
A convenience method for pushing a message with the specified text to the bar.
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.
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)