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 );
57 setupIdentitiesTree();
59 connect( treeIdentities->selectionModel(), &QItemSelectionModel::selectionChanged,
this, &QgsAuthIdentitiesEditor::selectionChanged );
61 connect( treeIdentities, &QTreeWidget::itemDoubleClicked,
this, &QgsAuthIdentitiesEditor::handleDoubleClick );
63 connect( btnViewRefresh, &QAbstractButton::clicked,
this, &QgsAuthIdentitiesEditor::refreshIdentitiesView );
65 btnGroupByOrg->setChecked(
false );
68 btnGroupByOrg->setChecked( sortbyval.toBool() );
70 populateIdentitiesView();
75void QgsAuthIdentitiesEditor::setupIdentitiesTree()
77 treeIdentities->setColumnCount( 3 );
78 treeIdentities->setHeaderLabels(
79 QStringList() << tr(
"Common Name" )
81 << tr(
"Expiry Date" )
83 treeIdentities->setColumnWidth( 0, 300 );
84 treeIdentities->setColumnWidth( 1, 75 );
87 mRootCertIdentItem =
new QTreeWidgetItem(
89 QStringList( tr(
"Certificate Bundles" ) ),
90 static_cast<int>( QgsAuthIdentitiesEditor::Section )
93 mRootCertIdentItem->setFlags( Qt::ItemIsEnabled );
94 mRootCertIdentItem->setExpanded(
true );
95 treeIdentities->insertTopLevelItem( 0, mRootCertIdentItem );
98void QgsAuthIdentitiesEditor::populateIdentitiesView()
102 populateIdentitiesSection( mRootCertIdentItem,
QgsApplication::authManager()->certIdentities(), QgsAuthIdentitiesEditor::CertIdentity );
105void QgsAuthIdentitiesEditor::refreshIdentitiesView()
107 populateIdentitiesView();
110void QgsAuthIdentitiesEditor::populateIdentitiesSection( QTreeWidgetItem *item,
const QList<QSslCertificate> &certs, QgsAuthIdentitiesEditor::IdentityType identype )
112 if ( btnGroupByOrg->isChecked() )
114 appendIdentitiesToGroup( certs, identype, item );
118 appendIdentitiesToItem( certs, identype, item );
122void QgsAuthIdentitiesEditor::appendIdentitiesToGroup(
const QList<QSslCertificate> &certs, QgsAuthIdentitiesEditor::IdentityType identype, QTreeWidgetItem *parent )
129 parent = treeIdentities->currentItem();
133 const QMap<QString, QList<QSslCertificate>> orgcerts(
137 QMap<QString, QList<QSslCertificate>>::const_iterator it = orgcerts.constBegin();
138 for ( ; it != orgcerts.constEnd(); ++it )
140 QTreeWidgetItem *grpitem(
new QTreeWidgetItem( parent, QStringList() << it.key(),
static_cast<int>( QgsAuthIdentitiesEditor::OrgName ) ) );
141 grpitem->setFirstColumnSpanned(
true );
142 grpitem->setFlags( Qt::ItemIsEnabled );
143 grpitem->setExpanded(
true );
145 QBrush orgb( grpitem->foreground( 0 ) );
146 orgb.setColor( QColor::fromRgb( 90, 90, 90 ) );
147 grpitem->setForeground( 0, orgb );
148 QFont grpf( grpitem->font( 0 ) );
149 grpf.setItalic(
true );
150 grpitem->setFont( 0, grpf );
152 appendIdentitiesToItem( it.value(), identype, grpitem );
155 parent->sortChildren( 0, Qt::AscendingOrder );
158void QgsAuthIdentitiesEditor::appendIdentitiesToItem(
const QList<QSslCertificate> &certs, QgsAuthIdentitiesEditor::IdentityType identype, QTreeWidgetItem *parent )
165 parent = treeIdentities->currentItem();
171 const auto constCerts = certs;
172 for (
const QSslCertificate &cert : constCerts )
178 coltxts << QString( cert.serialNumber() );
179 coltxts << cert.expiryDate().toString();
181 QTreeWidgetItem *item(
new QTreeWidgetItem( parent, coltxts,
static_cast<int>( identype ) ) );
186 item->setForeground( 2, redb );
190 item->setData( 0, Qt::UserRole,
id );
193 parent->sortChildren( 0, Qt::AscendingOrder );
196void QgsAuthIdentitiesEditor::showCertInfo( QTreeWidgetItem *item )
201 const QString digest( item->data( 0, Qt::UserRole ).toString() );
205 QgsDebugError( QStringLiteral(
"Certificate identity does not exist in database" ) );
212 dlg->setWindowModality( Qt::WindowModal );
213 dlg->resize( 675, 500 );
218void QgsAuthIdentitiesEditor::selectionChanged(
const QItemSelection &selected,
const QItemSelection &deselected )
221 Q_UNUSED( deselected )
225void QgsAuthIdentitiesEditor::checkSelection()
228 if ( treeIdentities->selectionModel()->selection().length() > 0 )
230 QTreeWidgetItem *item( treeIdentities->currentItem() );
232 switch ( ( QgsAuthIdentitiesEditor::IdentityType ) item->type() )
234 case QgsAuthIdentitiesEditor::CertIdentity:
242 btnRemoveIdentity->setEnabled( iscert );
243 btnInfoIdentity->setEnabled( iscert );
246void QgsAuthIdentitiesEditor::handleDoubleClick( QTreeWidgetItem *item,
int col )
251 switch ( ( QgsAuthIdentitiesEditor::IdentityType ) item->type() )
253 case QgsAuthIdentitiesEditor::Section:
256 case QgsAuthIdentitiesEditor::OrgName:
265 showCertInfo( item );
269void QgsAuthIdentitiesEditor::btnAddIdentity_clicked()
272 dlg->setWindowModality( Qt::WindowModal );
273 dlg->resize( 400, dlg->height() );
283 populateIdentitiesView();
284 mRootCertIdentItem->setExpanded(
true );
290void QgsAuthIdentitiesEditor::btnRemoveIdentity_clicked()
292 QTreeWidgetItem *item( treeIdentities->currentItem() );
296 QgsDebugMsgLevel( QStringLiteral(
"Current tree widget item not set" ), 2 );
300 const QString digest( item->data( 0, Qt::UserRole ).toString() );
302 if ( digest.isEmpty() )
310 QgsDebugError( QStringLiteral(
"Certificate identity does not exist in database" ) );
314 if ( QMessageBox::warning(
315 this, tr(
"Remove Certificate Identity" ),
316 tr(
"Are you sure you want to remove the selected "
317 "certificate identity from the database?\n\n"
318 "Operation can NOT be undone!" ),
319 QMessageBox::Ok | QMessageBox::Cancel,
322 == QMessageBox::Cancel )
333 item->parent()->removeChild( item );
337void QgsAuthIdentitiesEditor::btnInfoIdentity_clicked()
339 if ( treeIdentities->selectionModel()->selection().length() > 0 )
341 QTreeWidgetItem *item( treeIdentities->currentItem() );
342 handleDoubleClick( item, 0 );
346void QgsAuthIdentitiesEditor::btnGroupByOrg_toggled(
bool checked )
350 authMessageLog( QObject::tr(
"Could not store sort by preference." ), QObject::tr(
"Authentication Identities" ),
Qgis::MessageLevel::Warning );
352 populateIdentitiesView();
355void QgsAuthIdentitiesEditor::authMessageLog(
const QString &message,
const QString &authtag,
Qgis::MessageLevel level )
357 messageBar()->
pushMessage( authtag, message, level, 7 );
364 treeIdentities->setFocus();
366 QWidget::showEvent( e );
374int QgsAuthIdentitiesEditor::messageTimeout()
377 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 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 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)