17#include "moc_qgsauthconfigurationstoragesqlite.cpp"
26#include <QCoreApplication>
30QgsAuthConfigurationStorageSqlite::QgsAuthConfigurationStorageSqlite(
const QString &databasePath )
31 :
QgsAuthConfigurationStorageDb( {{ QStringLiteral(
"driver" ), QStringLiteral(
"QSQLITE" ) }, { QStringLiteral(
"database" ), databasePath }} )
35bool QgsAuthConfigurationStorageSqlite::initialize()
37 QMutexLocker locker( &mMutex );
39 if ( !QFileInfo::exists( mDatabase ) )
42 QFileInfo parentInfo( QFileInfo( mDatabase ).path() );
43 if ( ! parentInfo.exists() )
47 if ( !dir.mkpath( parentInfo.absolutePath() ) )
49 setError( tr(
"Auth db directory path '%1' could not be created" ).arg( mDatabase ) );
55 QSqlDatabase db = authDatabaseConnection();
58 setError( tr(
"Auth db file '%1' could not be created" ).arg( mDatabase ) );
64 const QFileInfo fileInfo( mDatabase );
65 if ( !fileInfo.permission( QFile::ReadOwner ) )
67 setError( tr(
"Auth db file '%1' is not readable" ).arg( mDatabase ) );
72 if ( !fileInfo.permission( QFile::WriteOwner ) )
77 const bool ok { createConfigTables() &&createCertTables() };
98QList<QgsAuthConfigurationStorage::SettingParameter> QgsAuthConfigurationStorageSqlite::settingsParameters()
const
100 return {{ QStringLiteral(
"database" ), tr(
"Path to the SQLite database file" ), QVariant::String }};
103QString QgsAuthConfigurationStorageSqlite::description()
const
105 return tr(
"Store credentials in a local SQLite database" );
108QString QgsAuthConfigurationStorageSqlite::type()
const
110 return QStringLiteral(
"SQLITE" );
113bool QgsAuthConfigurationStorageSqlite::tableExists(
const QString &table )
const
115 QMutexLocker locker( &mMutex );
119 const_cast< QgsAuthConfigurationStorageSqlite *
>( this )->setError( tr(
"Auth db could not be opened" ) );
123 QSqlQuery query( authDatabaseConnection() );
124 query.prepare( QStringLiteral(
"SELECT name FROM sqlite_master WHERE type='table' AND name=:name" ) );
125 query.bindValue( QStringLiteral(
":name" ), table );
127 if ( !authDbQuery( &query ) )
129 const_cast< QgsAuthConfigurationStorageSqlite *
>( this )->setError( tr(
"Failed to check if table '%1' exists" ).arg( table ) );
133 if ( ! query.next() )
141void QgsAuthConfigurationStorageSqlite::checkCapabilities()
144 QMutexLocker locker( &mMutex );
145 QFileInfo fileInfo( mDatabase );
146 if ( ! fileInfo.exists() )
152 const bool readOnly { isReadOnly() };
154 mIsReadOnly = mIsReadOnly && fileInfo.isWritable();
157 if ( ! fileInfo.isReadable() )
168 if ( mIsReadOnly != readOnly )
170 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.