21#include <QCoreApplication>
30#include "moc_qgsauthconfigurationstoragedb.cpp"
32using namespace Qt::StringLiterals;
47 u
"Auth db connection settings: driver=%1, database='%2', host=%3, port=%4, user='%5', schema=%6, options=%7"_s
59 QMutexLocker locker( &
mMutex );
61 QMapIterator<QThread *, QMetaObject::Connection> iterator( mConnectedThreads );
62 while ( iterator.hasNext() )
65 QThread::disconnect( iterator.value() );
73 QMutexLocker locker( &
mMutex );
75 const QString connectionName = u
"authentication.configs:0x%1"_s.arg(
reinterpret_cast<quintptr
>( QThread::currentThread() ), 2 * QT_POINTER_SIZE, 16,
'0'_L1 );
76 QgsDebugMsgLevel( u
"Using auth db connection name: %1 "_s.arg( connectionName ), 3 );
77 if ( !QSqlDatabase::contains( connectionName ) )
80 authdb = QSqlDatabase::addDatabase(
mDriver, connectionName );
84 if ( !QSqlDatabase::isDriverAvailable(
mDriver ) )
91 authdb.setHostName(
mHost );
92 authdb.setPort(
mPort );
93 authdb.setUserName(
mUser );
98 if ( !authdb.isValid() )
105 if ( QCoreApplication::instance() && QThread::currentThread() != QCoreApplication::instance()->thread() )
118 QMetaObject::Connection connection = connect(
119 QThread::currentThread(),
122 [connectionName,
this] {
123 QMutexLocker locker( &
mMutex );
124 QSqlDatabase::removeDatabase( connectionName );
125 mConnectedThreads.remove( QThread::currentThread() );
130 mConnectedThreads.insert( QThread::currentThread(), connection );
136 authdb = QSqlDatabase::database( connectionName,
false );
141 if ( !authdb.isOpen() )
143 if ( !authdb.open() )
154 QMutexLocker locker( &
mMutex );
157 if ( !authdb.isOpen() )
159 if ( !authdb.open() )
162 = tr(
"Unable to establish database connection\nDatabase: %1\nDriver error: %2\nDatabase error: %3" ).arg(
mDatabase, authdb.lastError().driverText(), authdb.lastError().databaseText() );
174 QMutexLocker locker( &
mMutex );
175 query->setForwardOnly(
true );
176 const bool result { sql.isEmpty() ? query->exec() : query->exec( sql ) };
178 auto boundQuery = [](
const QSqlQuery *query ) -> QString {
179 QString str = query->lastQuery();
180 const QStringList keys = query->boundValueNames();
181 const QVariantList values = query->boundValues();
182 QMap<QString, QVariant> boundValues;
183 for (
int i = 0; i < keys.count(); i++ )
185 boundValues.insert( keys.at( i ), values.at( i ).toString() );
187 QMapIterator<QString, QVariant> it = QMapIterator<QString, QVariant>( boundValues );
188 while ( it.hasNext() )
191 str.replace( it.key(), it.value().toString() );
198 if ( query->lastError().isValid() )
202 QgsDebugMsgLevel( u
"Auth db query FAILED: %1"_s.arg( sql.isEmpty() ? boundQuery( query ) : sql ), 2 );
208 QgsDebugMsgLevel( u
"Auth db query FAILED: %1"_s.arg( sql.isEmpty() ? boundQuery( query ) : sql ), 2 );
218 QMutexLocker locker( &
mMutex );
239 QMutexLocker locker( &
mMutex );
241 if ( !authdb.isValid() || !authdb.isOpen() )
243 setError( tr(
"Auth db could not be opened" ) );
268 { u
"driver"_s, tr(
"SQL Driver (see https://doc.qt.io/qt/sql-driver.html)" ), QVariant::String },
269 { u
"database"_s, tr(
"Database" ), QVariant::String },
270 { u
"schema"_s, tr(
"Schema for all tables" ), QVariant::String },
271 { u
"host"_s, tr(
"Host" ), QVariant::String },
272 { u
"port"_s, tr(
"Port" ), QVariant::Int },
273 { u
"user"_s, tr(
"User" ), QVariant::String },
274 { u
"password"_s, tr(
"Password" ), QVariant::String },
275 { u
"options"_s, tr(
"Connection options" ), QVariant::String },
283 QMutexLocker locker( &
mMutex );
285 const QString
id { QgsAuthCertUtils::shaHexForCert( cert ) };
299 setError( tr(
"Auth db could not be opened" ) );
305 setError( tr(
"Certificate is NULL" ) );
310 const QString certPem { cert.toPem() };
313 query.bindValue( u
":id"_s,
id );
314 query.bindValue( u
":key"_s, keyPem );
315 query.bindValue( u
":cert"_s, certPem );
327 QMutexLocker locker( &
mMutex );
333 setError( tr(
"Auth db could not be opened" ) );
340 query.bindValue( u
":id"_s, cert.digest().toHex() );
355 QMutexLocker locker( &
mMutex );
359 QSslCertificate emptycert;
373 query.bindValue( u
":id"_s,
id );
378 QSslCertificate cert;
380 if ( query.isActive() && query.isSelect() )
384 cert = QSslCertificate( query.value( 0 ).toByteArray(), QSsl::Pem );
385 QgsDebugMsgLevel( u
"Certificate identity retrieved for id: %1"_s.arg(
id ), 2 );
403 QMutexLocker locker( &
mMutex );
407 QPair<QSslCertificate, QString> bundle;
422 query.bindValue( u
":id"_s,
id );
427 if ( query.isActive() && query.isSelect() )
429 QSslCertificate cert;
433 key = query.value( 0 ).toString();
439 cert = QSslCertificate( query.value( 1 ).toByteArray(), QSsl::Pem );
445 QgsDebugMsgLevel( u
"Certificate identity bundle retrieved for id: %1"_s.arg(
id ), 2 );
452 bundle = qMakePair( cert, key );
459 QMutexLocker locker( &
mMutex );
463 QList<QSslCertificate> certs;
478 if ( query.isActive() && query.isSelect() )
480 while ( query.next() )
482 QSslCertificate cert( query.value( 0 ).toByteArray(), QSsl::Pem );
483 if ( !cert.isNull() )
485 certs.append( cert );
494 QMutexLocker locker( &
mMutex );
512 if ( query.isActive() && query.isSelect() )
514 while ( query.next() )
516 ids.append( query.value( 0 ).toString() );
524 QMutexLocker locker( &
mMutex );
540 query.bindValue( u
":id"_s,
id );
547 if ( query.isActive() && query.isSelect() )
564 QMutexLocker locker( &
mMutex );
570 setError( tr(
"Auth db could not be opened" ) );
577 query.bindValue( u
":id"_s,
id );
585 if ( query.numRowsAffected() == 0 )
598 QMutexLocker locker( &
mMutex );
601 QString
id( QgsAuthCertUtils::shaHexForCert( cert ) );
621 setError( tr(
"Auth db could not be opened" ) );
625 QString certpem( cert.toPem() );
630 query.bindValue( u
":id"_s,
id );
631 query.bindValue( u
":host"_s, config.
sslHostPort().trimmed() );
632 query.bindValue( u
":cert"_s, certpem );
638 QgsDebugMsgLevel( u
"Store SSL cert custom config SUCCESS for host:port, id: %1, %2"_s.arg( config.
sslHostPort().trimmed(),
id ), 2 );
647 QMutexLocker locker( &
mMutex );
665 if ( query.isActive() && query.isSelect() )
667 while ( query.next() )
669 ids.append( query.value( 0 ).toString() );
677 QMutexLocker locker( &
mMutex );
683 if (
id.isEmpty() || hostport.isEmpty() )
685 QgsDebugError( u
"Passed config ID or host:port is empty"_s );
697 query.bindValue( u
":id"_s,
id );
698 query.bindValue( u
":host"_s, hostport.trimmed() );
703 if ( query.isActive() && query.isSelect() )
707 config.
setSslCertificate( QSslCertificate( query.value( 1 ).toByteArray(), QSsl::Pem ) );
710 QgsDebugMsgLevel( u
"SSL cert custom config retrieved for host:port, id: %1, %2"_s.arg( hostport,
id ), 2 );
725 QMutexLocker locker( &
mMutex );
741 query.bindValue( u
":host"_s, hostport.trimmed() );
746 if ( query.isActive() && query.isSelect() )
750 config.
setSslCertificate( QSslCertificate( query.value( 1 ).toByteArray(), QSsl::Pem ) );
753 QgsDebugMsgLevel( u
"SSL cert custom config retrieved for host:port %1"_s.arg( hostport ), 2 );
767 QMutexLocker locker( &
mMutex );
771 QList<QgsAuthConfigSslServer> configs;
786 if ( query.isActive() && query.isSelect() )
788 while ( query.next() )
791 config.
setSslCertificate( QSslCertificate( query.value( 2 ).toByteArray(), QSsl::Pem ) );
794 configs.append( config );
802 QMutexLocker locker( &
mMutex );
806 if (
id.isEmpty() || hostport.isEmpty() )
808 QgsDebugError( u
"Passed config ID or host:port is empty"_s );
814 setError( tr(
"Auth db could not be opened" ) );
821 query.bindValue( u
":id"_s,
id );
822 query.bindValue( u
":host"_s, hostport.trimmed() );
828 if ( query.isActive() && query.isSelect() )
832 QgsDebugMsgLevel( u
"SSL cert custom config exists for host:port, id: %1, %2"_s.arg( hostport,
id ), 2 );
837 QgsDebugError( u
"Retrieved more than one SSL cert custom config for host:port, id: %1, %2"_s.arg( hostport,
id ) );
847 QMutexLocker locker( &
mMutex );
851 if (
id.isEmpty() || hostport.isEmpty() )
853 QgsDebugError( u
"Passed config ID or host:port is empty"_s );
868 query.bindValue( u
":id"_s,
id );
869 query.bindValue( u
":host"_s, hostport.trimmed() );
877 if ( query.numRowsAffected() == 0 )
890 QMutexLocker locker( &
mMutex );
908 if ( query.isActive() && query.isSelect() )
910 while ( query.next() )
912 ids.append( query.value( 0 ).toString() );
920 QMutexLocker locker( &
mMutex );
946 const QString
id( QgsAuthCertUtils::shaHexForCert( cert ) );
947 const QString pem( cert.toPem() );
953 query.bindValue( u
":id"_s,
id );
954 query.bindValue( u
":cert"_s, pem );
959 QgsDebugMsgLevel( u
"Store certificate authority SUCCESS for id: %1"_s.arg(
id ), 2 );
967 QMutexLocker locker( &
mMutex );
971 QSslCertificate emptycert;
985 query.bindValue( u
":id"_s,
id );
990 QSslCertificate cert;
992 if ( query.isActive() && query.isSelect() )
996 cert = QSslCertificate( query.value( 0 ).toByteArray(), QSsl::Pem );
997 QgsDebugMsgLevel( u
"Certificate authority retrieved for id: %1"_s.arg(
id ), 2 );
1010 QMutexLocker locker( &
mMutex );
1014 if ( cert.isNull() )
1026 const QString
id( QgsAuthCertUtils::shaHexForCert( cert ) );
1031 query.bindValue( u
":id"_s,
id );
1037 if ( query.isActive() && query.isSelect() )
1039 if ( query.first() )
1041 QgsDebugMsgLevel( u
"Certificate authority exists for id: %1"_s.arg(
id ), 2 );
1056 QMutexLocker locker( &
mMutex );
1060 if ( cert.isNull() )
1068 setError( tr(
"Auth db could not be opened" ) );
1072 const QString
id( QgsAuthCertUtils::shaHexForCert( cert ) );
1078 query.bindValue( u
":id"_s,
id );
1086 if ( query.numRowsAffected() == 0 )
1099 QMutexLocker locker( &
mMutex );
1103 QMap<QString, QgsAuthCertUtils::CertTrustPolicy> trustedCerts;
1108 return trustedCerts;
1116 return trustedCerts;
1118 if ( query.isActive() && query.isSelect() )
1120 while ( query.next() )
1122 QString
id( query.value( 0 ).toString() );
1123 int policy = query.value( 1 ).toInt();
1125 trustedCerts[
id] = trustPolicy;
1129 return trustedCerts;
1134 QMutexLocker locker( &
mMutex );
1138 QList<QSslCertificate> authorities;
1153 if ( query.isActive() && query.isSelect() )
1155 while ( query.next() )
1157 const QSslCertificate cert( query.value( 1 ).toByteArray(), QSsl::Pem );
1158 if ( !cert.isNull() )
1160 authorities.append( cert );
1164 const QString
id { query.value( 0 ).toString() };
1174 QMutexLocker locker( &
mMutex );
1178 if ( policyExisted )
1187 if ( cert.isNull() )
1195 setError( tr(
"Auth db could not be opened" ) );
1199 const QString
id( QgsAuthCertUtils::shaHexForCert( cert ) );
1204 if ( !policyExisted )
1206 QgsDebugMsgLevel( u
"Passed policy was default, no cert records in database for id: %1"_s.arg(
id ), 2 );
1212 setError( tr(
"Failed to remove certificate trust policy for id: %1" ).arg(
id ) );
1216 QgsDebugMsgLevel( u
"Passed policy was default, all cert records in database were removed for id: %1"_s.arg(
id ), 2 );
1226 setError( tr(
"Failed to remove certificate trust policy for id: %1" ).arg(
id ) );
1234 query.bindValue( u
":id"_s,
id );
1235 query.bindValue( u
":policy"_s,
static_cast< int >( policy ) );
1240 QgsDebugMsgLevel( u
"Store certificate trust policy SUCCESS for id: %1"_s.arg(
id ), 2 );
1248 QMutexLocker locker( &
mMutex );
1252 if ( cert.isNull() )
1258 QString
id( QgsAuthCertUtils::shaHexForCert( cert ) );
1269 query.bindValue( u
":id"_s,
id );
1274 if ( query.isActive() && query.isSelect() )
1276 if ( query.first() )
1278 int policy = query.value( 0 ).toInt();
1279 QgsDebugMsgLevel( u
"Certificate trust policy retrieved for id: %1"_s.arg(
id ), 2 );
1293 QMutexLocker locker( &
mMutex );
1297 if ( cert.isNull() )
1303 QString
id( QgsAuthCertUtils::shaHexForCert( cert ) );
1307 setError( tr(
"Auth db could not be opened" ) );
1314 query.bindValue( u
":id"_s,
id );
1318 setError( tr(
"Failed to remove certificate trust policy '%1'" ).arg(
id ) );
1322 if ( query.numRowsAffected() == 0 )
1324 setError( tr(
"No certificate trust policy found for id: %1" ).arg(
id ) );
1335 QMutexLocker locker( &
mMutex );
1339 if ( cert.isNull() )
1345 QString
id( QgsAuthCertUtils::shaHexForCert( cert ) );
1356 query.bindValue( u
":id"_s,
id );
1361 if ( query.isActive() && query.isSelect() )
1363 if ( query.first() )
1365 return query.value( 0 ).toInt() > 0;
1375 QMutexLocker locker( &
mMutex );
1379 QList<QgsAuthConfigurationStorage::MasterPasswordConfig> passwords;
1393 if ( query.isActive() && query.isSelect() )
1395 while ( query.next() )
1397 const QString salt = query.value( 0 ).toString();
1398 const QString civ = query.value( 1 ).toString();
1399 const QString hash = query.value( 2 ).toString();
1400 passwords.append( { salt, civ, hash } );
1408 QMutexLocker locker( &
mMutex );
1414 setError( tr(
"Auth db could not be opened" ) );
1421 query.bindValue( u
":salt"_s, config.
salt );
1422 query.bindValue( u
":civ"_s, config.
civ );
1423 query.bindValue( u
":hash"_s, config.
hash );
1435 QMutexLocker locker( &
mMutex );
1451 return u
"auth_configs"_s;
1456 return u
"auth_settings"_s;
1461 return u
"auth_identities"_s;
1466 return u
"auth_servers"_s;
1471 return u
"auth_authorities"_s;
1476 return u
"auth_trust"_s;
1481 return u
"auth_pass"_s;
1486 const QString schema {
mConfiguration.value( u
"schema"_s ).toString() };
1487 if ( schema.isEmpty() )
1511 return u
"DB-%2"_s.arg(
mDriver );
1516 return tr(
"Store credentials in a %1 database" ).arg(
name() );
1521 QMutexLocker locker( &
mMutex );
1523 if (
mId.isEmpty() )
1526 QCryptographicHash hash( QCryptographicHash::Sha256 );
1527 hash.addData(
mDriver.toUtf8() );
1529 hash.addData( QString::number(
mPort ).toUtf8() );
1530 hash.addData(
mHost.toUtf8() );
1531 hash.addData(
mUser.toUtf8() );
1532 mId = QString( hash.result().toHex() );
1539 QMutexLocker locker( &
mMutex );
1543 setError( tr(
"Auth db could not be opened" ) );
1552 qstr = QStringLiteral(
1553 "CREATE TABLE IF NOT EXISTS %1 (\n"
1554 " salt TEXT NOT NULL,\n"
1555 " civ TEXT NOT NULL\n"
1556 ", hash TEXT NOT NULL);"
1565 qstr = QStringLiteral(
1566 "CREATE TABLE IF NOT EXISTS %1 (\n"
1567 " id TEXT NOT NULL,\n"
1568 " name TEXT NOT NULL,\n"
1570 " type TEXT NOT NULL,\n"
1571 " version INTEGER NOT NULL\n"
1572 ", config TEXT NOT NULL);"
1597 QMutexLocker locker( &
mMutex );
1601 setError( tr(
"Auth db could not be opened" ) );
1612 qstr = QStringLiteral(
1613 "CREATE TABLE IF NOT EXISTS %1 (\n"
1614 " setting TEXT NOT NULL\n"
1624 qstr = QStringLiteral(
1625 "CREATE TABLE IF NOT EXISTS %1 (\n"
1626 " id TEXT NOT NULL,\n"
1627 " key TEXT NOT NULL\n"
1628 ", cert TEXT NOT NULL);"
1646 qstr = QStringLiteral(
1647 "CREATE TABLE IF NOT EXISTS %1 (\n"
1648 " id TEXT NOT NULL,\n"
1649 " host TEXT NOT NULL,\n"
1651 ", config TEXT NOT NULL);"
1669 qstr = QStringLiteral(
1670 "CREATE TABLE IF NOT EXISTS %1 (\n"
1671 " id TEXT NOT NULL\n"
1672 ", cert TEXT NOT NULL);"
1690 qstr = QStringLiteral(
1691 "CREATE TABLE IF NOT EXISTS %1 (\n"
1692 " id TEXT NOT NULL\n"
1693 ", policy TEXT NOT NULL);"
1715 QMutexLocker locker( &
mMutex );
1738 if ( query.isActive() && query.isSelect() )
1740 while ( query.next() )
1742 QString authcfg = query.value( 0 ).toString();
1744 config.
setId( authcfg );
1745 config.
setName( query.value( 1 ).toString() );
1746 config.
setUri( query.value( 2 ).toString() );
1747 config.
setMethod( query.value( 3 ).toString() );
1748 config.
setVersion( query.value( 4 ).toInt() );
1750 if ( !allowedMethods.isEmpty() && !allowedMethods.contains( config.
method() ) )
1755 baseConfigs.insert( authcfg, config );
1763 QMutexLocker locker( &
mMutex );
1786 if ( query.isActive() && query.isSelect() )
1788 while ( query.next() )
1790 QString authcfg = query.value( 0 ).toString();
1792 config.
setId( authcfg );
1793 config.
setName( query.value( 1 ).toString() );
1794 config.
setUri( query.value( 2 ).toString() );
1795 config.
setMethod( query.value( 3 ).toString() );
1796 config.
setVersion( query.value( 4 ).toInt() );
1797 config.
setConfig( u
"encrypted_payload"_s, query.value( 5 ).toString() );
1798 baseConfigs.insert( authcfg, config );
1806 QMutexLocker locker( &
mMutex );
1815 setError( tr(
"Auth db could not be opened" ) );
1822 QString schema {
mConfiguration.value( u
"schema"_s ).toString() };
1823 if ( !schema.isEmpty() )
1920 QMutexLocker locker( &
mMutex );
1943 query.bindValue( u
":id"_s,
id );
1950 if ( query.isActive() && query.isSelect() )
1952 if ( query.first() )
1955 config.
setName( query.value( 0 ).toString() );
1956 config.
setUri( query.value( 1 ).toString() );
1957 config.
setMethod( query.value( 2 ).toString() );
1958 config.
setVersion( query.value( 3 ).toInt() );
1961 payload = query.value( 4 ).toString();
1975 QMutexLocker locker( &
mMutex );
1988 setError( tr(
"Auth db could not be opened" ) );
1992 if ( payload.isEmpty() )
1998 if ( !config.
isValid(
true ) )
2010 query.prepare( u
"INSERT INTO %1 (id, name, uri, type, version, config) VALUES (:id, :name, :uri, :type, :version, :config)"_s.arg(
quotedQualifiedIdentifier(
methodConfigTableName() ) ) );
2011 query.bindValue( u
":id"_s, config.
id() );
2012 query.bindValue( u
":name"_s, config.
name() );
2013 query.bindValue( u
":uri"_s, config.
uri() );
2014 query.bindValue( u
":type"_s, config.
method() );
2015 query.bindValue( u
":version"_s, config.
version() );
2016 query.bindValue( u
":config"_s, payload );
2031 QMutexLocker locker( &
mMutex );
2037 setError( tr(
"Auth db could not be opened" ) );
2044 query.bindValue( u
":id"_s,
id );
2052 if ( query.numRowsAffected() == 0 )
2065 QMutexLocker locker( &
mMutex );
2078 query.bindValue( u
":id"_s,
id );
2088 return query.value( 0 ).toInt() > 0;
2096 QMutexLocker locker( &
mMutex );
2110 setError( tr(
"Auth db could not be opened" ) );
2117 query.bindValue( u
":setting"_s, key );
2118 query.bindValue( u
":value"_s, value );
2134 QMutexLocker locker( &
mMutex );
2147 query.bindValue( u
":setting"_s, key );
2157 return query.value( 0 ).toString();
2170 QMutexLocker locker( &
mMutex );
2183 query.bindValue( u
":setting"_s, key );
2191 if ( query.numRowsAffected() == 0 )
2204 QMutexLocker locker( &
mMutex );
2217 query.bindValue( u
":setting"_s, key );
2227 return query.value( 0 ).toInt() > 0;
2234bool QgsAuthConfigurationStorageDb::clearTables(
const QStringList &tables )
2236 QMutexLocker locker( &
mMutex );
2240 setError( tr(
"Auth db could not be opened" ) );
2246 for (
const auto &table : std::as_const( tables ) )
2287 throw QgsNotSupportedException( tr(
"Failed to empty table '%1': unsupported table" ).arg( table ) );
2303 QString schema {
mConfiguration.value( u
"schema"_s ).toString() };
2304 if ( !schema.isEmpty() )
2311const QMap<QString, QVariant> QgsAuthConfigurationStorageDb::uriToSettings(
const QString &uri )
2316 if ( url.isValid() )
2318 settings.insert( u
"driver"_s, url.scheme().toUpper() );
2319 settings.insert( u
"host"_s, url.host() );
2320 settings.insert( u
"port"_s, QString::number( url.port() ) );
2321 QString path { url.path() };
2323 if ( path.startsWith(
'/'_L1 ) && !(
settings.value( u
"driver"_s ) ==
"QSQLITE"_L1 ||
settings.value( u
"driver"_s ) ==
"QSPATIALITE"_L1 ) )
2325 path = path.mid( 1 );
2327 settings.insert( u
"database"_s, path );
2328 settings.insert( u
"user"_s, url.userName() );
2329 settings.insert( u
"password"_s, url.password() );
2330 QUrlQuery query { url };
2333 QString schemaName { query.queryItemValue( u
"schema"_s ) };
2334 if ( schemaName.isEmpty() )
2336 schemaName = query.queryItemValue( u
"SCHEMA"_s );
2339 if ( !schemaName.isEmpty() )
2341 settings.insert( u
"schema"_s, schemaName );
2342 query.removeAllQueryItems( u
"schema"_s );
2343 query.removeAllQueryItems( u
"SCHEMA"_s );
2346 settings.insert( u
"options"_s, query.toString() );
2383 QMutexLocker locker( &
mMutex );
QFlags< AuthConfigurationStorageCapability > AuthConfigurationStorageCapabilities
Authentication configuration storage capabilities.
@ Warning
Warning message.
@ Critical
Critical/error message.
@ CreateSetting
Can create a new authentication setting.
@ UpdateSetting
Can update the authentication setting.
@ CreateConfiguration
Can create a new authentication configuration.
@ ClearStorage
Can clear all configurations from storage.
@ DeleteCertificateAuthority
Can delete a certificate authority.
@ DeleteSslCertificateCustomConfig
Can delete a SSL certificate custom config.
@ DeleteSetting
Can delete the authentication setting.
@ ReadSslCertificateCustomConfig
Can read a SSL certificate custom config.
@ DeleteMasterPassword
Can delete the master password.
@ CreateSslCertificateCustomConfig
Can create a new SSL certificate custom config.
@ ReadCertificateTrustPolicy
Can read a certificate trust policy.
@ ReadConfiguration
Can read an authentication configuration.
@ UpdateConfiguration
Can update an authentication configuration.
@ UpdateCertificateTrustPolicy
Can update a certificate trust policy.
@ ReadCertificateAuthority
Can read a certificate authority.
@ CreateCertificateAuthority
Can create a new certificate authority.
@ DeleteConfiguration
Can deleet an authentication configuration.
@ ReadSetting
Can read the authentication settings.
@ UpdateMasterPassword
Can update the master password.
@ UpdateCertificateAuthority
Can update a certificate authority.
@ CreateCertificateIdentity
Can create a new certificate identity.
@ ReadCertificateIdentity
Can read a certificate identity.
@ CreateCertificateTrustPolicy
Can create a new certificate trust policy.
@ ReadMasterPassword
Can read the master password.
@ CreateMasterPassword
Can create a new master password.
@ UpdateCertificateIdentity
Can update a certificate identity.
@ DeleteCertificateTrustPolicy
Can delete a certificate trust policy.
@ DeleteCertificateIdentity
Can delete a certificate identity.
@ UpdateSslCertificateCustomConfig
Can update a SSL certificate custom config.
CertTrustPolicy
Type of certificate trust policy.
Configuration container for SSL server connection exceptions or overrides.
void setSslCertificate(const QSslCertificate &cert)
Sets server certificate object.
void setSslHostPort(const QString &hostport)
Sets server host:port string.
const QSslCertificate sslCertificate() const
Server certificate object.
const QString sslHostPort() const
Server host:port string.
const QString configString() const
Configuration as a concatenated string.
void loadConfigString(const QString &config=QString())
Load concatenated string into configuration, e.g. from auth database.
QgsAuthConfigurationStorageDb(const QMap< QString, QVariant > &settings)
Creates a new QgsAuthConfigurationStorageDb instance from the specified settings.
bool removeCertTrustPolicy(const QSslCertificate &cert) override
Remove certificate trust policy.
bool authDbTransactionQuery(QSqlQuery *query)
Executes the specified query on the database using a transaction.
virtual bool tableExists(const QString &table) const
Returns true if the specified table exists in the database, false otherwise.
bool storeCertTrustPolicy(const QSslCertificate &cert, QgsAuthCertUtils::CertTrustPolicy policy) override
Store certificate trust policy.
QStringList certAuthorityIds() const override
Returns the list of certificate authority IDs in the storage.
const QgsAuthConfigSslServer loadSslCertCustomConfigByHost(const QString &hostport) const override
Loads an SSL certificate custom config by hostport (host:port).
QString loadAuthSetting(const QString &key) const override
Load an authentication setting from the storage.
bool removeAuthSetting(const QString &key) override
Remove an authentication setting from the storage.
const QMap< QString, QgsAuthCertUtils::CertTrustPolicy > caCertsPolicy() const override
Returns the map of CA certificates hashes in the storages and their trust policy.
QgsAuthCertUtils::CertTrustPolicy loadCertTrustPolicy(const QSslCertificate &cert) const override
Load certificate trust policy.
bool sslCertCustomConfigExists(const QString &id, const QString &hostport) override
Check if SSL certificate custom config exists.
virtual void checkCapabilities()
Checks the capabilities of the storage.
bool authDbQuery(QSqlQuery *query, const QString &sql=QString()) const
Runs the specified query on the database.
bool storeAuthSetting(const QString &key, const QString &value) override
Store an authentication setting in the storage.
bool removeCertIdentity(const QSslCertificate &cert) override
Remove a certificate identity from the storage.
const QPair< QSslCertificate, QString > loadCertIdentityBundle(const QString &id) const override
Returns a certificate identity bundle by id (sha hash).
const QList< QgsAuthConfigurationStorage::MasterPasswordConfig > masterPasswords() const override
Returns the list of (encrypted) master passwords stored in the database.
bool clearMethodConfigs() override
Remove all authentications configurations from the storage.
bool createCertTables()
Creates the certificate tables in the database.
~QgsAuthConfigurationStorageDb() override
bool storeSslCertCustomConfig(const QgsAuthConfigSslServer &config) override
Store an SSL certificate custom config.
virtual QString certIdentityTableName() const
Returns the name of the table used to store the certificate identities.
bool authDbOpen() const
Opens the connection to the database.
virtual QString quotedQualifiedIdentifier(const QString &identifier, bool isIndex=false) const
Returns the quoted identifier, prefixed with the schema (if not null), ready for the insertion into a...
bool methodConfigExists(const QString &id) const override
Check if an authentication configuration exists in the storage.
virtual QString methodConfigTableName() const
Returns the name of the table used to store the method configurations.
QSqlDatabase authDatabaseConnection() const
Returns the database connection used by this storage.
QList< QgsAuthConfigurationStorage::SettingParameter > settingsParameters() const override
Returns a list of the settings accepted by the storage.
QStringList certIdentityIds() const override
certIdentityIds get list of certificate identity ids from database
bool storeMasterPassword(const QgsAuthConfigurationStorage::MasterPasswordConfig &config) override
Store a master password in the database.
bool isReady() const override
Returns true is the storage is ready to be used.
bool initialize() override
Initializes the storage.
bool storeMethodConfig(const QgsAuthMethodConfig &mconfig, const QString &payload) override
Store an authentication config in the database.
bool removeCertAuthority(const QSslCertificate &cert) override
Remove a certificate authority.
const QSslCertificate loadCertIdentity(const QString &id) const override
certIdentity get a certificate identity by id (sha hash)
const QList< QgsAuthConfigSslServer > sslCertCustomConfigs() const override
sslCertCustomConfigs get SSL certificate custom configs
QgsAuthMethodConfigsMap authMethodConfigs(const QStringList &allowedMethods=QStringList()) const override
Returns a mapping of authentication configurations available from this storage.
const QList< QSslCertificate > caCerts() const override
Returns the list of CA certificates in the storage.
bool certTrustPolicyExists(const QSslCertificate &cert) const override
Check if certificate trust policy exists.
bool createConfigTables()
Creates the configuration tables in the database.
virtual QString authSettingsTableName() const
Returns the name of the table used to store the auth settings.
const QSslCertificate loadCertAuthority(const QString &id) const override
certAuthority get a certificate authority by id (sha hash)
virtual QString certTrustPolicyTableName() const
Returns the name of the table used to store the certificate trust policies.
bool removeMethodConfig(const QString &id) override
Removes the authentication configuration with the specified id.
QgsAuthMethodConfigsMap authMethodConfigsWithPayload() const override
Returns a mapping of authentication configurations available from this storage.
virtual QString sslCertCustomConfigTableName() const
Returns the name of the table used to store the SSL custom configurations.
QString id() const override
Returns the unique identifier of the storage object.
bool certIdentityExists(const QString &id) const override
Check if the certificate identity exists.
QString type() const override
Returns the type of the storage implementation.
bool certAuthorityExists(const QSslCertificate &cert) const override
Check if a certificate authority exists.
QgsAuthMethodConfig loadMethodConfig(const QString &id, QString &payload, bool full=false) const override
Load an authentication configuration from the database.
bool storeCertIdentity(const QSslCertificate &cert, const QString &keyPem) override
Store a certificate identity in the storage.
bool erase() override
Completely erase the storage removing all configurations/certs/settings etc.
virtual QString certAuthorityTableName() const
Returns the name of the table used to store the certificate authorities.
bool removeSslCertCustomConfig(const QString &id, const QString &hostport) override
Remove an SSL certificate custom config.
const QList< QSslCertificate > certIdentities() const override
certIdentities get certificate identities
bool clearMasterPasswords() override
Remove all master passwords from the database.
QString description() const override
Returns a human readable localized description of the storage implementation (e.g.
QString name() const override
Returns a human readable localized short name of the storage implementation (e.g "SQLite").
virtual QString masterPasswordTableName() const
Returns the name of the table used to store the master passwords.
bool authSettingExists(const QString &key) const override
Check if an authentication setting exists in the storage.
bool storeCertAuthority(const QSslCertificate &cert) override
Store a certificate authority.
const QgsAuthConfigSslServer loadSslCertCustomConfig(const QString &id, const QString &hostport) const override
Loads an SSL certificate custom config by id (sha hash) and hostport (host:port).
QStringList sslCertCustomConfigIds() const override
Returns the list of SSL certificate custom config ids.
QMap< QString, QVariant > mConfiguration
Store the implementation-specific configuration.
void readOnlyChanged(bool readOnly)
Emitted when the storage read-only status was changed.
void certIdentityChanged()
Emitted when the storage cert identity table was changed.
void messageLog(const QString &message, const QString &tag=u"Authentication"_s, Qgis::MessageLevel level=Qgis::MessageLevel::Info)
Custom logging signal to relay to console output and QgsMessageLog.
void methodConfigChanged()
Emitted when the storage method config table was changed.
void setError(const QString &error, Qgis::MessageLevel level=Qgis::MessageLevel::Critical)
Set the last error message to error with message level level.
Qgis::AuthConfigurationStorageCapabilities capabilities() const
Returns the capabilities of the storage.
virtual QString loggerTag() const
Returns the logger tag for the storage.
bool isEnabled() const
Returns true if the storage is enabled.
void sslCertTrustPolicyChanged()
Emitted when the storage ssl cert trust policy table was changed.
void masterPasswordChanged()
Emitted when the storage master password table was changed.
QgsAuthConfigurationStorage(const QMap< QString, QVariant > &settings)
Creates a new authentication configuration storage.
void certAuthorityChanged()
Emitted when the storage cert authority table was changed.
void sslCertCustomConfigChanged()
Emitted when the storage ssl cert custom config table was changed.
void authSettingsChanged()
Emitted when the storage auth settings table was changed.
void storageChanged(const QString &id)
Emitted when the storage was updated.
virtual QString lastError() const
Returns the last error message.
void checkCapability(Qgis::AuthConfigurationStorageCapability capability) const
Utility to check capability and throw QgsNotSupportedException if not supported.
virtual bool isReadOnly() const
Returns true if the storage is read-only, false otherwise.
QMap< QString, QVariant > settings() const
Returns the settings of the storage.
Qgis::AuthConfigurationStorageCapabilities mCapabilities
Store the capabilities of the storage.
Configuration storage class for authentication method configurations.
bool isValid(bool validateid=false) const
Whether the configuration is valid.
QString method() const
Textual key of the associated authentication method.
const QString uri() const
A URI to auto-select a config when connecting to a resource.
void setName(const QString &name)
Sets name of configuration.
void setVersion(int version)
Sets version of the configuration.
const QString name() const
Gets name of configuration.
const QString id() const
Gets 'authcfg' 7-character alphanumeric ID of the config.
void setConfig(const QString &key, const QString &value)
Set a single config value per key in the map.
int version() const
Gets version of the configuration.
void setMethod(const QString &method)
void setUri(const QString &uri)
void setId(const QString &id)
Sets auth config ID.
QHash< QString, QgsAuthMethodConfig > QgsAuthMethodConfigsMap
#define QgsDebugMsgLevel(str, level)
#define QgsDebugError(str)
Structure that holds the (encrypted) master password elements.