25#include <QCoreApplication>
29QgsAuthConfigurationStorageSqlite::QgsAuthConfigurationStorageSqlite(
const QString &databasePath )
30 :
QgsAuthConfigurationStorageDb( {{ QStringLiteral(
"driver" ), QStringLiteral(
"QSQLITE" ) }, { QStringLiteral(
"database" ), databasePath }} )
34bool QgsAuthConfigurationStorageSqlite::initialize()
36 QMutexLocker locker( &mMutex );
38 if ( !QFileInfo::exists( mDatabase ) )
41 QFileInfo parentInfo( QFileInfo( mDatabase ).path() );
42 if ( ! parentInfo.exists() )
46 if ( !dir.mkpath( parentInfo.absolutePath() ) )
48 setError( tr(
"Auth db directory path '%1' could not be created" ).arg( mDatabase ) );
54 QSqlDatabase db = authDatabaseConnection();
57 setError( tr(
"Auth db file '%1' could not be created" ).arg( mDatabase ) );
63 const QFileInfo fileInfo( mDatabase );
64 if ( !fileInfo.permission( QFile::ReadOwner ) )
66 setError( tr(
"Auth db file '%1' is not readable" ).arg( mDatabase ) );
71 if ( !fileInfo.permission( QFile::WriteOwner ) )
76 const bool ok { createConfigTables() &&createCertTables() };
97QList<QgsAuthConfigurationStorage::SettingParameter> QgsAuthConfigurationStorageSqlite::settingsParameters()
const
99 return {{ QStringLiteral(
"database" ), tr(
"Path to the SQLite database file" ), QVariant::String }};
102QString QgsAuthConfigurationStorageSqlite::description()
const
104 return tr(
"Store credentials in a local SQLite database" );
107QString QgsAuthConfigurationStorageSqlite::type()
const
109 return QStringLiteral(
"SQLITE" );
112bool QgsAuthConfigurationStorageSqlite::tableExists(
const QString &table )
const
114 QMutexLocker locker( &mMutex );
118 const_cast< QgsAuthConfigurationStorageSqlite *
>( this )->setError( tr(
"Auth db could not be opened" ) );
122 QSqlQuery query( authDatabaseConnection() );
123 query.prepare( QStringLiteral(
"SELECT name FROM sqlite_master WHERE type='table' AND name=:name" ) );
124 query.bindValue( QStringLiteral(
":name" ), table );
126 if ( !authDbQuery( &query ) )
128 const_cast< QgsAuthConfigurationStorageSqlite *
>( this )->setError( tr(
"Failed to check if table '%1' exists" ).arg( table ) );
132 if ( ! query.next() )
140void QgsAuthConfigurationStorageSqlite::checkCapabilities()
143 QMutexLocker locker( &mMutex );
144 QFileInfo fileInfo( mDatabase );
145 if ( ! fileInfo.exists() )
151 const bool readOnly { isReadOnly() };
153 mIsReadOnly = mIsReadOnly && fileInfo.isWritable();
156 if ( ! fileInfo.isReadable() )
167 if ( mIsReadOnly != readOnly )
169 mIsReadOnly = readOnly;
QFlags< AuthConfigurationStorageCapability > AuthConfigurationStorageCapabilities
Authentication configuration storage capabilities.
@ Warning
Warning message.
@ Critical
Critical/error message.
@ ReadSslCertificateCustomConfig
Can read a SSL certificate custom config.
@ ReadCertificateTrustPolicy
Can read a certificate trust policy.
@ ReadConfiguration
Can read an authentication configuration.
@ ReadCertificateAuthority
Can read a certificate authority.
@ ReadCertificateIdentity
Can read a certificate identity.
@ ReadMasterPassword
Can read the master password.
QSqlDatabase based implementation of QgsAuthConfigurationStorage.
virtual void checkCapabilities()
Checks the capabilities of the storage.
void readOnlyChanged(bool readOnly)
Emitted when the storage read-only status was changed.
QgsSignalBlocker< Object > whileBlocking(Object *object)
Temporarily blocks signals from a QObject while calling a single method from the object.