QGIS API Documentation 3.99.0-Master (2fe06baccd8)
Loading...
Searching...
No Matches
qgsauthconfigurationstoragedb.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsauthconfigurationstoragedb.h - QgsAuthConfigurationStorageDb
3
4 ---------------------
5 begin : 20.6.2024
6 copyright : (C) 2024 by Alessandro Pasotti
7 email : elpaso at itopen dot it
8 ***************************************************************************
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 ***************************************************************************/
16#ifndef QGSAUTHCONFIGURATIONSTORAGEDB_H
17#define QGSAUTHCONFIGURATIONSTORAGEDB_H
18
19#include "qgis_core.h"
21
22#include <QObject>
23#include <QRecursiveMutex>
24#include <QSqlDatabase>
25
32{
33 Q_OBJECT
34 public:
35
58 QgsAuthConfigurationStorageDb( const QMap<QString, QVariant> &settings );
59
65 QgsAuthConfigurationStorageDb( const QString &uri );
66
67
69
70
74 QSqlDatabase authDatabaseConnection() const;
75
76 // QgsAuthConfigurationStorage interface
77 public:
78 QString name() const override;
79 QString type() const override;
80 QString description() const override;
81 QString id() const override;
82
83 QgsAuthMethodConfigsMap authMethodConfigs( const QStringList &allowedMethods = QStringList() ) const override;
85 QgsAuthMethodConfig loadMethodConfig( const QString &id, QString &payload SIP_OUT, bool full = false ) const override;
86 bool storeMethodConfig( const QgsAuthMethodConfig &mconfig, const QString &payload ) override;
87 bool removeMethodConfig( const QString &id ) override;
88 bool methodConfigExists( const QString &id ) const override;
89 bool storeAuthSetting( const QString &key, const QString &value ) override;
90 QString loadAuthSetting( const QString &key ) const override;
91 bool removeAuthSetting( const QString &key ) override;
92 bool authSettingExists( const QString &key ) const override;
93 bool clearMethodConfigs() override;
94 bool erase() override;
95 bool isReady() const override;
96 bool initialize() override;
97 QList<QgsAuthConfigurationStorage::SettingParameter> settingsParameters() const override;
98
99 bool storeCertIdentity( const QSslCertificate &cert, const QString &keyPem ) override;
100 bool removeCertIdentity( const QSslCertificate &cert ) override;
101 const QSslCertificate loadCertIdentity( const QString &id ) const override;
102 const QPair<QSslCertificate, QString> loadCertIdentityBundle( const QString &id ) const override;
103 const QList<QSslCertificate> certIdentities() const override;
104 QStringList certIdentityIds() const override;
105 bool certIdentityExists( const QString &id ) const override;
106 bool removeCertIdentity( const QString &id ) override;
107 bool storeSslCertCustomConfig( const QgsAuthConfigSslServer &config ) override;
108 QStringList sslCertCustomConfigIds() const override;
109 const QgsAuthConfigSslServer loadSslCertCustomConfig( const QString &id, const QString &hostport ) const override;
110 const QgsAuthConfigSslServer loadSslCertCustomConfigByHost( const QString &hostport ) const override;
111 const QList<QgsAuthConfigSslServer> sslCertCustomConfigs() const override;
112 bool sslCertCustomConfigExists( const QString &id, const QString &hostport ) override;
113 bool removeSslCertCustomConfig( const QString &id, const QString &hostport ) override;
114
115 bool storeCertAuthority( const QSslCertificate &cert ) override;
116 QStringList certAuthorityIds() const override;
117 const QSslCertificate loadCertAuthority( const QString &id ) const override;
118 bool certAuthorityExists( const QSslCertificate &cert ) const override;
119 bool removeCertAuthority( const QSslCertificate &cert ) override;
120 const QMap<QString, QgsAuthCertUtils::CertTrustPolicy> caCertsPolicy() const override;
121 const QList<QSslCertificate> caCerts() const override;
122
123 bool storeCertTrustPolicy( const QSslCertificate &cert, QgsAuthCertUtils::CertTrustPolicy policy ) override;
124 QgsAuthCertUtils::CertTrustPolicy loadCertTrustPolicy( const QSslCertificate &cert ) const override;
125 bool removeCertTrustPolicy( const QSslCertificate &cert ) override;
126 bool certTrustPolicyExists( const QSslCertificate &cert ) const override;
127
128 const QList<QgsAuthConfigurationStorage::MasterPasswordConfig> masterPasswords( ) const override;
130 bool clearMasterPasswords() override;
131
132 // DB specific methods
133
137 virtual QString methodConfigTableName() const;
138
142 virtual QString authSettingsTableName() const;
143
147 virtual QString certIdentityTableName() const;
148
152 virtual QString certAuthorityTableName() const;
153
157 virtual QString sslCertCustomConfigTableName() const;
158
162 virtual QString certTrustPolicyTableName() const;
163
167 virtual QString masterPasswordTableName() const;
168
173 virtual bool tableExists( const QString &table ) const;
174
181 virtual QString quotedQualifiedIdentifier( const QString &identifier, bool isIndex = false ) const;
182
183 private:
184
185 bool clearTables( const QStringList &tables );
186
187 static const QMap<QString, QVariant> uriToSettings( const QString &uri );
188 mutable QMap<QThread *, QMetaObject::Connection> mConnectedThreads;
189
190 protected:
191
196 bool authDbOpen() const;
197
202 bool authDbQuery( QSqlQuery *query, const QString &sql = QString() ) const;
203
208 bool authDbTransactionQuery( QSqlQuery *query );
209
214 bool createConfigTables();
215
220 bool createCertTables();
221
225 virtual void checkCapabilities();
226
227 // Storage ID
228 mutable QString mId;
229
230 // From https://doc.qt.io/qt-6/sql-driver.html
231 QString mDriver;
232 QString mDatabase;
233 QString mHost;
234 QString mUser;
235 QString mPassword;
236 int mPort;
237 // Driver specific options
239
240 bool mIsReady = false;
241
242 mutable QRecursiveMutex mMutex;
243
244};
245
246#endif // QGSAUTHCONFIGURATIONSTORAGEDB_H
CertTrustPolicy
Type of certificate trust policy.
Configuration container for SSL server connection exceptions or overrides.
QgsAuthConfigurationStorageDb(const QMap< QString, QVariant > &settings)
Creates a new QgsAuthConfigurationStorageDb instance from the specified settings.
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.
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 createCertTables()
Creates the certificate tables in the database.
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...
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.
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.
virtual QString certTrustPolicyTableName() const
Returns the name of the table used to store the certificate trust policies.
virtual QString sslCertCustomConfigTableName() const
Returns the name of the table used to store the SSL custom configurations.
virtual QString certAuthorityTableName() const
Returns the name of the table used to store the certificate authorities.
virtual QString masterPasswordTableName() const
Returns the name of the table used to store the master passwords.
virtual bool storeAuthSetting(const QString &key, const QString &value)=0
Store an authentication setting in the storage.
virtual QgsAuthMethodConfig loadMethodConfig(const QString &id, QString &payload, bool full=false) const =0
Load an authentication configuration from the database.
virtual const QgsAuthConfigSslServer loadSslCertCustomConfigByHost(const QString &hostport) const =0
Loads an SSL certificate custom config by hostport (host:port).
virtual bool storeCertTrustPolicy(const QSslCertificate &cert, QgsAuthCertUtils::CertTrustPolicy policy)=0
Store certificate trust policy.
virtual QString loadAuthSetting(const QString &key) const =0
Load an authentication setting from the storage.
virtual bool removeSslCertCustomConfig(const QString &id, const QString &hostport)=0
Remove an SSL certificate custom config.
virtual bool removeCertTrustPolicy(const QSslCertificate &cert)=0
Remove certificate trust policy.
virtual bool sslCertCustomConfigExists(const QString &id, const QString &hostport)=0
Check if SSL certificate custom config exists.
virtual QString description() const =0
Returns a human readable localized description of the storage implementation (e.g.
virtual bool certTrustPolicyExists(const QSslCertificate &cert) const =0
Check if certificate trust policy exists.
virtual bool erase()=0
Completely erase the storage removing all configurations/certs/settings etc.
virtual const QSslCertificate loadCertAuthority(const QString &id) const =0
certAuthority get a certificate authority by id (sha hash)
virtual bool storeCertAuthority(const QSslCertificate &cert)=0
Store a certificate authority.
virtual bool removeMethodConfig(const QString &id)=0
Removes the authentication configuration with the specified id.
virtual QgsAuthMethodConfigsMap authMethodConfigsWithPayload() const =0
Returns a mapping of authentication configurations available from this storage.
virtual const QMap< QString, QgsAuthCertUtils::CertTrustPolicy > caCertsPolicy() const =0
Returns the map of CA certificates hashes in the storages and their trust policy.
virtual QStringList sslCertCustomConfigIds() const =0
Returns the list of SSL certificate custom config ids.
virtual QgsAuthMethodConfigsMap authMethodConfigs(const QStringList &allowedMethods=QStringList()) const =0
Returns a mapping of authentication configurations available from this storage.
virtual bool removeCertIdentity(const QSslCertificate &cert)=0
Remove a certificate identity from the storage.
virtual bool isReady() const =0
Returns true is the storage is ready to be used.
virtual QString type() const =0
Returns the type of the storage implementation.
virtual QStringList certAuthorityIds() const =0
Returns the list of certificate authority IDs in the storage.
virtual bool initialize()
Initializes the storage.
virtual bool methodConfigExists(const QString &id) const =0
Check if an authentication configuration exists in the storage.
virtual bool storeSslCertCustomConfig(const QgsAuthConfigSslServer &config)=0
Store an SSL certificate custom config.
virtual bool removeCertAuthority(const QSslCertificate &cert)=0
Remove a certificate authority.
virtual const QList< QSslCertificate > certIdentities() const =0
certIdentities get certificate identities
virtual QList< QgsAuthConfigurationStorage::SettingParameter > settingsParameters() const =0
Returns a list of the settings accepted by the storage.
virtual bool certIdentityExists(const QString &id) const =0
Check if the certificate identity exists.
virtual QgsAuthCertUtils::CertTrustPolicy loadCertTrustPolicy(const QSslCertificate &cert) const =0
Load certificate trust policy.
virtual QStringList certIdentityIds() const =0
certIdentityIds get list of certificate identity ids from database
virtual const QSslCertificate loadCertIdentity(const QString &id) const =0
certIdentity get a certificate identity by id (sha hash)
virtual bool storeCertIdentity(const QSslCertificate &cert, const QString &keyPem)=0
Store a certificate identity in the storage.
virtual QString name() const =0
Returns a human readable localized short name of the storage implementation (e.g "SQLite").
QgsAuthConfigurationStorage(const QMap< QString, QVariant > &settings)
Creates a new authentication configuration storage.
virtual bool clearMethodConfigs()=0
Remove all authentications configurations from the storage.
virtual bool storeMethodConfig(const QgsAuthMethodConfig &config, const QString &payload)=0
Store an authentication config in the database.
virtual bool clearMasterPasswords()=0
Remove all master passwords from the database.
virtual const QList< QgsAuthConfigSslServer > sslCertCustomConfigs() const =0
sslCertCustomConfigs get SSL certificate custom configs
virtual bool authSettingExists(const QString &key) const =0
Check if an authentication setting exists in the storage.
virtual const QList< QSslCertificate > caCerts() const =0
Returns the list of CA certificates in the storage.
virtual bool certAuthorityExists(const QSslCertificate &cert) const =0
Check if a certificate authority exists.
virtual const QPair< QSslCertificate, QString > loadCertIdentityBundle(const QString &id) const =0
Returns a certificate identity bundle by id (sha hash).
virtual bool storeMasterPassword(const QgsAuthConfigurationStorage::MasterPasswordConfig &config)=0
Store a master password in the database.
virtual QString id() const =0
Returns the unique identifier of the storage object.
virtual const QList< QgsAuthConfigurationStorage::MasterPasswordConfig > masterPasswords() const =0
Returns the list of (encrypted) master passwords stored in the database.
virtual const QgsAuthConfigSslServer loadSslCertCustomConfig(const QString &id, const QString &hostport) const =0
Loads an SSL certificate custom config by id (sha hash) and hostport (host:port).
virtual bool removeAuthSetting(const QString &key)=0
Remove an authentication setting from the storage.
QMap< QString, QVariant > settings() const
Returns the settings of the storage.
Configuration storage class for authentication method configurations.
#define SIP_OUT
Definition qgis_sip.h:58
QHash< QString, QgsAuthMethodConfig > QgsAuthMethodConfigsMap
Structure that holds the (encrypted) master password elements.