21#include <QCoreApplication>
31#include "moc_qgsauthconfigurationstoragedb.cpp"
33using namespace Qt::StringLiterals;
48 u
"Auth db connection settings: driver=%1, database='%2', host=%3, port=%4, user='%5', schema=%6, options=%7"_s
60 QMutexLocker locker( &
mMutex );
62 QMapIterator<QThread *, QMetaObject::Connection> iterator( mConnectedThreads );
63 while ( iterator.hasNext() )
66 QThread::disconnect( iterator.value() );
74 QMutexLocker locker( &
mMutex );
76 const QString connectionName = u
"authentication.configs:0x%1"_s.arg(
reinterpret_cast<quintptr
>( QThread::currentThread() ), 2 * QT_POINTER_SIZE, 16,
'0'_L1 );
77 QgsDebugMsgLevel( u
"Using auth db connection name: %1 "_s.arg( connectionName ), 3 );
78 if ( !QSqlDatabase::contains( connectionName ) )
81 authdb = QSqlDatabase::addDatabase(
mDriver, connectionName );
85 if ( !QSqlDatabase::isDriverAvailable(
mDriver ) )
92 authdb.setHostName(
mHost );
93 authdb.setPort(
mPort );
94 authdb.setUserName(
mUser );
99 if ( !authdb.isValid() )
106 if ( QCoreApplication::instance() && QThread::currentThread() != QCoreApplication::instance()->thread() )
119 QMetaObject::Connection connection = connect(
120 QThread::currentThread(),
123 [connectionName,
this] {
124 QMutexLocker locker( &
mMutex );
125 QSqlDatabase::removeDatabase( connectionName );
126 mConnectedThreads.remove( QThread::currentThread() );
131 mConnectedThreads.insert( QThread::currentThread(), connection );
137 authdb = QSqlDatabase::database( connectionName,
false );
142 if ( !authdb.isOpen() )
144 if ( !authdb.open() )
155 QMutexLocker locker( &
mMutex );
158 if ( !authdb.isOpen() )
160 if ( !authdb.open() )
163 = tr(
"Unable to establish database connection\nDatabase: %1\nDriver error: %2\nDatabase error: %3" ).arg(
mDatabase, authdb.lastError().driverText(), authdb.lastError().databaseText() );
175 QMutexLocker locker( &
mMutex );
176 query->setForwardOnly(
true );
177 const bool result { sql.isEmpty() ? query->exec() : query->exec( sql ) };
179 auto boundQuery = [](
const QSqlQuery *query ) -> QString {
180 QString str = query->lastQuery();
181#if QT_VERSION >= QT_VERSION_CHECK( 6, 6, 0 )
182 const QStringList keys = query->boundValueNames();
184 const QVariantList values = query->boundValues();
185 QMap<QString, QVariant> boundValues;
186 for (
int i = 0; i < values.count(); i++ )
188#if QT_VERSION >= QT_VERSION_CHECK( 6, 6, 0 )
189 boundValues.insert( keys.at( i ), values.at( i ).toString() );
191 boundValues.insert( query->record().fieldName( i ), values.at( i ).toString() );
194 QMapIterator<QString, QVariant> it = QMapIterator<QString, QVariant>( boundValues );
195 while ( it.hasNext() )
198 str.replace( it.key(), it.value().toString() );
205 if ( query->lastError().isValid() )
209 QgsDebugMsgLevel( u
"Auth db query FAILED: %1"_s.arg( sql.isEmpty() ? boundQuery( query ) : sql ), 2 );
215 QgsDebugMsgLevel( u
"Auth db query FAILED: %1"_s.arg( sql.isEmpty() ? boundQuery( query ) : sql ), 2 );
225 QMutexLocker locker( &
mMutex );
246 QMutexLocker locker( &
mMutex );
248 if ( !authdb.isValid() || !authdb.isOpen() )
250 setError( tr(
"Auth db could not be opened" ) );
275 { u
"driver"_s, tr(
"SQL Driver (see https://doc.qt.io/qt/sql-driver.html)" ), QVariant::String },
276 { u
"database"_s, tr(
"Database" ), QVariant::String },
277 { u
"schema"_s, tr(
"Schema for all tables" ), QVariant::String },
278 { u
"host"_s, tr(
"Host" ), QVariant::String },
279 { u
"port"_s, tr(
"Port" ), QVariant::Int },
280 { u
"user"_s, tr(
"User" ), QVariant::String },
281 { u
"password"_s, tr(
"Password" ), QVariant::String },
282 { u
"options"_s, tr(
"Connection options" ), QVariant::String },
290 QMutexLocker locker( &
mMutex );
292 const QString
id { QgsAuthCertUtils::shaHexForCert( cert ) };
306 setError( tr(
"Auth db could not be opened" ) );
312 setError( tr(
"Certificate is NULL" ) );
317 const QString certPem { cert.toPem() };
320 query.bindValue( u
":id"_s,
id );
321 query.bindValue( u
":key"_s, keyPem );
322 query.bindValue( u
":cert"_s, certPem );
334 QMutexLocker locker( &
mMutex );
340 setError( tr(
"Auth db could not be opened" ) );
347 query.bindValue( u
":id"_s, cert.digest().toHex() );
362 QMutexLocker locker( &
mMutex );
366 QSslCertificate emptycert;
380 query.bindValue( u
":id"_s,
id );
385 QSslCertificate cert;
387 if ( query.isActive() && query.isSelect() )
391 cert = QSslCertificate( query.value( 0 ).toByteArray(), QSsl::Pem );
392 QgsDebugMsgLevel( u
"Certificate identity retrieved for id: %1"_s.arg(
id ), 2 );
410 QMutexLocker locker( &
mMutex );
414 QPair<QSslCertificate, QString> bundle;
429 query.bindValue( u
":id"_s,
id );
434 if ( query.isActive() && query.isSelect() )
436 QSslCertificate cert;
440 key = query.value( 0 ).toString();
446 cert = QSslCertificate( query.value( 1 ).toByteArray(), QSsl::Pem );
452 QgsDebugMsgLevel( u
"Certificate identity bundle retrieved for id: %1"_s.arg(
id ), 2 );
459 bundle = qMakePair( cert, key );
466 QMutexLocker locker( &
mMutex );
470 QList<QSslCertificate> certs;
485 if ( query.isActive() && query.isSelect() )
487 while ( query.next() )
489 QSslCertificate cert( query.value( 0 ).toByteArray(), QSsl::Pem );
490 if ( !cert.isNull() )
492 certs.append( cert );
501 QMutexLocker locker( &
mMutex );
519 if ( query.isActive() && query.isSelect() )
521 while ( query.next() )
523 ids.append( query.value( 0 ).toString() );
531 QMutexLocker locker( &
mMutex );
547 query.bindValue( u
":id"_s,
id );
554 if ( query.isActive() && query.isSelect() )
571 QMutexLocker locker( &
mMutex );
577 setError( tr(
"Auth db could not be opened" ) );
584 query.bindValue( u
":id"_s,
id );
592 if ( query.numRowsAffected() == 0 )
605 QMutexLocker locker( &
mMutex );
608 QString
id( QgsAuthCertUtils::shaHexForCert( cert ) );
628 setError( tr(
"Auth db could not be opened" ) );
632 QString certpem( cert.toPem() );
637 query.bindValue( u
":id"_s,
id );
638 query.bindValue( u
":host"_s, config.
sslHostPort().trimmed() );
639 query.bindValue( u
":cert"_s, certpem );
645 QgsDebugMsgLevel( u
"Store SSL cert custom config SUCCESS for host:port, id: %1, %2"_s.arg( config.
sslHostPort().trimmed(),
id ), 2 );
654 QMutexLocker locker( &
mMutex );
672 if ( query.isActive() && query.isSelect() )
674 while ( query.next() )
676 ids.append( query.value( 0 ).toString() );
684 QMutexLocker locker( &
mMutex );
690 if (
id.isEmpty() || hostport.isEmpty() )
692 QgsDebugError( u
"Passed config ID or host:port is empty"_s );
704 query.bindValue( u
":id"_s,
id );
705 query.bindValue( u
":host"_s, hostport.trimmed() );
710 if ( query.isActive() && query.isSelect() )
714 config.
setSslCertificate( QSslCertificate( query.value( 1 ).toByteArray(), QSsl::Pem ) );
717 QgsDebugMsgLevel( u
"SSL cert custom config retrieved for host:port, id: %1, %2"_s.arg( hostport,
id ), 2 );
732 QMutexLocker locker( &
mMutex );
748 query.bindValue( u
":host"_s, hostport.trimmed() );
753 if ( query.isActive() && query.isSelect() )
757 config.
setSslCertificate( QSslCertificate( query.value( 1 ).toByteArray(), QSsl::Pem ) );
760 QgsDebugMsgLevel( u
"SSL cert custom config retrieved for host:port %1"_s.arg( hostport ), 2 );
774 QMutexLocker locker( &
mMutex );
778 QList<QgsAuthConfigSslServer> configs;
793 if ( query.isActive() && query.isSelect() )
795 while ( query.next() )
798 config.
setSslCertificate( QSslCertificate( query.value( 2 ).toByteArray(), QSsl::Pem ) );
801 configs.append( config );
809 QMutexLocker locker( &
mMutex );
813 if (
id.isEmpty() || hostport.isEmpty() )
815 QgsDebugError( u
"Passed config ID or host:port is empty"_s );
821 setError( tr(
"Auth db could not be opened" ) );
828 query.bindValue( u
":id"_s,
id );
829 query.bindValue( u
":host"_s, hostport.trimmed() );
835 if ( query.isActive() && query.isSelect() )
839 QgsDebugMsgLevel( u
"SSL cert custom config exists for host:port, id: %1, %2"_s.arg( hostport,
id ), 2 );
844 QgsDebugError( u
"Retrieved more than one SSL cert custom config for host:port, id: %1, %2"_s.arg( hostport,
id ) );
854 QMutexLocker locker( &
mMutex );
858 if (
id.isEmpty() || hostport.isEmpty() )
860 QgsDebugError( u
"Passed config ID or host:port is empty"_s );
875 query.bindValue( u
":id"_s,
id );
876 query.bindValue( u
":host"_s, hostport.trimmed() );
884 if ( query.numRowsAffected() == 0 )
897 QMutexLocker locker( &
mMutex );
915 if ( query.isActive() && query.isSelect() )
917 while ( query.next() )
919 ids.append( query.value( 0 ).toString() );
927 QMutexLocker locker( &
mMutex );
953 const QString
id( QgsAuthCertUtils::shaHexForCert( cert ) );
954 const QString pem( cert.toPem() );
960 query.bindValue( u
":id"_s,
id );
961 query.bindValue( u
":cert"_s, pem );
966 QgsDebugMsgLevel( u
"Store certificate authority SUCCESS for id: %1"_s.arg(
id ), 2 );
974 QMutexLocker locker( &
mMutex );
978 QSslCertificate emptycert;
992 query.bindValue( u
":id"_s,
id );
997 QSslCertificate cert;
999 if ( query.isActive() && query.isSelect() )
1001 if ( query.first() )
1003 cert = QSslCertificate( query.value( 0 ).toByteArray(), QSsl::Pem );
1004 QgsDebugMsgLevel( u
"Certificate authority retrieved for id: %1"_s.arg(
id ), 2 );
1017 QMutexLocker locker( &
mMutex );
1021 if ( cert.isNull() )
1033 const QString
id( QgsAuthCertUtils::shaHexForCert( cert ) );
1038 query.bindValue( u
":id"_s,
id );
1044 if ( query.isActive() && query.isSelect() )
1046 if ( query.first() )
1048 QgsDebugMsgLevel( u
"Certificate authority exists for id: %1"_s.arg(
id ), 2 );
1063 QMutexLocker locker( &
mMutex );
1067 if ( cert.isNull() )
1075 setError( tr(
"Auth db could not be opened" ) );
1079 const QString
id( QgsAuthCertUtils::shaHexForCert( cert ) );
1085 query.bindValue( u
":id"_s,
id );
1093 if ( query.numRowsAffected() == 0 )
1106 QMutexLocker locker( &
mMutex );
1110 QMap<QString, QgsAuthCertUtils::CertTrustPolicy> trustedCerts;
1115 return trustedCerts;
1123 return trustedCerts;
1125 if ( query.isActive() && query.isSelect() )
1127 while ( query.next() )
1129 QString
id( query.value( 0 ).toString() );
1130 int policy = query.value( 1 ).toInt();
1132 trustedCerts[
id] = trustPolicy;
1136 return trustedCerts;
1141 QMutexLocker locker( &
mMutex );
1145 QList<QSslCertificate> authorities;
1160 if ( query.isActive() && query.isSelect() )
1162 while ( query.next() )
1164 const QSslCertificate cert( query.value( 1 ).toByteArray(), QSsl::Pem );
1165 if ( !cert.isNull() )
1167 authorities.append( cert );
1171 const QString
id { query.value( 0 ).toString() };
1181 QMutexLocker locker( &
mMutex );
1185 if ( policyExisted )
1194 if ( cert.isNull() )
1202 setError( tr(
"Auth db could not be opened" ) );
1206 const QString
id( QgsAuthCertUtils::shaHexForCert( cert ) );
1211 if ( !policyExisted )
1213 QgsDebugMsgLevel( u
"Passed policy was default, no cert records in database for id: %1"_s.arg(
id ), 2 );
1219 setError( tr(
"Failed to remove certificate trust policy for id: %1" ).arg(
id ) );
1223 QgsDebugMsgLevel( u
"Passed policy was default, all cert records in database were removed for id: %1"_s.arg(
id ), 2 );
1233 setError( tr(
"Failed to remove certificate trust policy for id: %1" ).arg(
id ) );
1241 query.bindValue( u
":id"_s,
id );
1242 query.bindValue( u
":policy"_s,
static_cast< int >( policy ) );
1247 QgsDebugMsgLevel( u
"Store certificate trust policy SUCCESS for id: %1"_s.arg(
id ), 2 );
1255 QMutexLocker locker( &
mMutex );
1259 if ( cert.isNull() )
1265 QString
id( QgsAuthCertUtils::shaHexForCert( cert ) );
1276 query.bindValue( u
":id"_s,
id );
1281 if ( query.isActive() && query.isSelect() )
1283 if ( query.first() )
1285 int policy = query.value( 0 ).toInt();
1286 QgsDebugMsgLevel( u
"Certificate trust policy retrieved for id: %1"_s.arg(
id ), 2 );
1300 QMutexLocker locker( &
mMutex );
1304 if ( cert.isNull() )
1310 QString
id( QgsAuthCertUtils::shaHexForCert( cert ) );
1314 setError( tr(
"Auth db could not be opened" ) );
1321 query.bindValue( u
":id"_s,
id );
1325 setError( tr(
"Failed to remove certificate trust policy '%1'" ).arg(
id ) );
1329 if ( query.numRowsAffected() == 0 )
1331 setError( tr(
"No certificate trust policy found for id: %1" ).arg(
id ) );
1342 QMutexLocker locker( &
mMutex );
1346 if ( cert.isNull() )
1352 QString
id( QgsAuthCertUtils::shaHexForCert( cert ) );
1363 query.bindValue( u
":id"_s,
id );
1368 if ( query.isActive() && query.isSelect() )
1370 if ( query.first() )
1372 return query.value( 0 ).toInt() > 0;
1382 QMutexLocker locker( &
mMutex );
1386 QList<QgsAuthConfigurationStorage::MasterPasswordConfig> passwords;
1400 if ( query.isActive() && query.isSelect() )
1402 while ( query.next() )
1404 const QString salt = query.value( 0 ).toString();
1405 const QString civ = query.value( 1 ).toString();
1406 const QString hash = query.value( 2 ).toString();
1407 passwords.append( { salt, civ, hash } );
1415 QMutexLocker locker( &
mMutex );
1421 setError( tr(
"Auth db could not be opened" ) );
1428 query.bindValue( u
":salt"_s, config.
salt );
1429 query.bindValue( u
":civ"_s, config.
civ );
1430 query.bindValue( u
":hash"_s, config.
hash );
1442 QMutexLocker locker( &
mMutex );
1458 return u
"auth_configs"_s;
1463 return u
"auth_settings"_s;
1468 return u
"auth_identities"_s;
1473 return u
"auth_servers"_s;
1478 return u
"auth_authorities"_s;
1483 return u
"auth_trust"_s;
1488 return u
"auth_pass"_s;
1493 const QString schema {
mConfiguration.value( u
"schema"_s ).toString() };
1494 if ( schema.isEmpty() )
1518 return u
"DB-%2"_s.arg(
mDriver );
1523 return tr(
"Store credentials in a %1 database" ).arg(
name() );
1528 QMutexLocker locker( &
mMutex );
1530 if (
mId.isEmpty() )
1533 QCryptographicHash hash( QCryptographicHash::Sha256 );
1534 hash.addData(
mDriver.toUtf8() );
1536 hash.addData( QString::number(
mPort ).toUtf8() );
1537 hash.addData(
mHost.toUtf8() );
1538 hash.addData(
mUser.toUtf8() );
1539 mId = QString( hash.result().toHex() );
1546 QMutexLocker locker( &
mMutex );
1550 setError( tr(
"Auth db could not be opened" ) );
1559 qstr = QStringLiteral(
1560 "CREATE TABLE IF NOT EXISTS %1 (\n"
1561 " salt TEXT NOT NULL,\n"
1562 " civ TEXT NOT NULL\n"
1563 ", hash TEXT NOT NULL);"
1572 qstr = QStringLiteral(
1573 "CREATE TABLE IF NOT EXISTS %1 (\n"
1574 " id TEXT NOT NULL,\n"
1575 " name TEXT NOT NULL,\n"
1577 " type TEXT NOT NULL,\n"
1578 " version INTEGER NOT NULL\n"
1579 ", config TEXT NOT NULL);"
1604 QMutexLocker locker( &
mMutex );
1608 setError( tr(
"Auth db could not be opened" ) );
1619 qstr = QStringLiteral(
1620 "CREATE TABLE IF NOT EXISTS %1 (\n"
1621 " setting TEXT NOT NULL\n"
1631 qstr = QStringLiteral(
1632 "CREATE TABLE IF NOT EXISTS %1 (\n"
1633 " id TEXT NOT NULL,\n"
1634 " key TEXT NOT NULL\n"
1635 ", cert TEXT NOT NULL);"
1653 qstr = QStringLiteral(
1654 "CREATE TABLE IF NOT EXISTS %1 (\n"
1655 " id TEXT NOT NULL,\n"
1656 " host TEXT NOT NULL,\n"
1658 ", config TEXT NOT NULL);"
1676 qstr = QStringLiteral(
1677 "CREATE TABLE IF NOT EXISTS %1 (\n"
1678 " id TEXT NOT NULL\n"
1679 ", cert TEXT NOT NULL);"
1697 qstr = QStringLiteral(
1698 "CREATE TABLE IF NOT EXISTS %1 (\n"
1699 " id TEXT NOT NULL\n"
1700 ", policy TEXT NOT NULL);"
1722 QMutexLocker locker( &
mMutex );
1745 if ( query.isActive() && query.isSelect() )
1747 while ( query.next() )
1749 QString authcfg = query.value( 0 ).toString();
1751 config.
setId( authcfg );
1752 config.
setName( query.value( 1 ).toString() );
1753 config.
setUri( query.value( 2 ).toString() );
1754 config.
setMethod( query.value( 3 ).toString() );
1755 config.
setVersion( query.value( 4 ).toInt() );
1757 if ( !allowedMethods.isEmpty() && !allowedMethods.contains( config.
method() ) )
1762 baseConfigs.insert( authcfg, config );
1770 QMutexLocker locker( &
mMutex );
1793 if ( query.isActive() && query.isSelect() )
1795 while ( query.next() )
1797 QString authcfg = query.value( 0 ).toString();
1799 config.
setId( authcfg );
1800 config.
setName( query.value( 1 ).toString() );
1801 config.
setUri( query.value( 2 ).toString() );
1802 config.
setMethod( query.value( 3 ).toString() );
1803 config.
setVersion( query.value( 4 ).toInt() );
1804 config.
setConfig( u
"encrypted_payload"_s, query.value( 5 ).toString() );
1805 baseConfigs.insert( authcfg, config );
1813 QMutexLocker locker( &
mMutex );
1822 setError( tr(
"Auth db could not be opened" ) );
1829 QString schema {
mConfiguration.value( u
"schema"_s ).toString() };
1830 if ( !schema.isEmpty() )
1927 QMutexLocker locker( &
mMutex );
1950 query.bindValue( u
":id"_s,
id );
1957 if ( query.isActive() && query.isSelect() )
1959 if ( query.first() )
1962 config.
setName( query.value( 0 ).toString() );
1963 config.
setUri( query.value( 1 ).toString() );
1964 config.
setMethod( query.value( 2 ).toString() );
1965 config.
setVersion( query.value( 3 ).toInt() );
1968 payload = query.value( 4 ).toString();
1982 QMutexLocker locker( &
mMutex );
1995 setError( tr(
"Auth db could not be opened" ) );
1999 if ( payload.isEmpty() )
2005 if ( !config.
isValid(
true ) )
2017 query.prepare( u
"INSERT INTO %1 (id, name, uri, type, version, config) VALUES (:id, :name, :uri, :type, :version, :config)"_s.arg(
quotedQualifiedIdentifier(
methodConfigTableName() ) ) );
2018 query.bindValue( u
":id"_s, config.
id() );
2019 query.bindValue( u
":name"_s, config.
name() );
2020 query.bindValue( u
":uri"_s, config.
uri() );
2021 query.bindValue( u
":type"_s, config.
method() );
2022 query.bindValue( u
":version"_s, config.
version() );
2023 query.bindValue( u
":config"_s, payload );
2038 QMutexLocker locker( &
mMutex );
2044 setError( tr(
"Auth db could not be opened" ) );
2051 query.bindValue( u
":id"_s,
id );
2059 if ( query.numRowsAffected() == 0 )
2072 QMutexLocker locker( &
mMutex );
2085 query.bindValue( u
":id"_s,
id );
2095 return query.value( 0 ).toInt() > 0;
2103 QMutexLocker locker( &
mMutex );
2117 setError( tr(
"Auth db could not be opened" ) );
2124 query.bindValue( u
":setting"_s, key );
2125 query.bindValue( u
":value"_s, value );
2141 QMutexLocker locker( &
mMutex );
2154 query.bindValue( u
":setting"_s, key );
2164 return query.value( 0 ).toString();
2177 QMutexLocker locker( &
mMutex );
2190 query.bindValue( u
":setting"_s, key );
2198 if ( query.numRowsAffected() == 0 )
2211 QMutexLocker locker( &
mMutex );
2224 query.bindValue( u
":setting"_s, key );
2234 return query.value( 0 ).toInt() > 0;
2241bool QgsAuthConfigurationStorageDb::clearTables(
const QStringList &tables )
2243 QMutexLocker locker( &
mMutex );
2247 setError( tr(
"Auth db could not be opened" ) );
2253 for (
const auto &table : std::as_const( tables ) )
2294 throw QgsNotSupportedException( tr(
"Failed to empty table '%1': unsupported table" ).arg( table ) );
2310 QString schema {
mConfiguration.value( u
"schema"_s ).toString() };
2311 if ( !schema.isEmpty() )
2318const QMap<QString, QVariant> QgsAuthConfigurationStorageDb::uriToSettings(
const QString &uri )
2323 if ( url.isValid() )
2325 settings.insert( u
"driver"_s, url.scheme().toUpper() );
2326 settings.insert( u
"host"_s, url.host() );
2327 settings.insert( u
"port"_s, QString::number( url.port() ) );
2328 QString path { url.path() };
2330 if ( path.startsWith(
'/'_L1 ) && !(
settings.value( u
"driver"_s ) ==
"QSQLITE"_L1 ||
settings.value( u
"driver"_s ) ==
"QSPATIALITE"_L1 ) )
2332 path = path.mid( 1 );
2334 settings.insert( u
"database"_s, path );
2335 settings.insert( u
"user"_s, url.userName() );
2336 settings.insert( u
"password"_s, url.password() );
2337 QUrlQuery query { url };
2340 QString schemaName { query.queryItemValue( u
"schema"_s ) };
2341 if ( schemaName.isEmpty() )
2343 schemaName = query.queryItemValue( u
"SCHEMA"_s );
2346 if ( !schemaName.isEmpty() )
2348 settings.insert( u
"schema"_s, schemaName );
2349 query.removeAllQueryItems( u
"schema"_s );
2350 query.removeAllQueryItems( u
"SCHEMA"_s );
2353 settings.insert( u
"options"_s, query.toString() );
2390 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.