QGIS API Documentation 3.99.0-Master (d270888f95f)
Loading...
Searching...
No Matches
qgsauthconfigurationstorage.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsauthconfigurationstorage.h - QgsAuthConfigurationStorage
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 QGSAUTHCONFIGURATIONSTORAGE_H
17#define QGSAUTHCONFIGURATIONSTORAGE_H
18
19
20#include "qgis.h"
21#include "qgis_core.h"
22#include "qgis_sip.h"
23#include "qgsauthcertutils.h"
24#include "qgsauthconfig.h"
25#include "qgsexception.h"
26
27#include <QObject>
28#include <QString>
29
30using namespace Qt::StringLiterals;
31
37class CORE_EXPORT QgsAuthConfigurationStorage: public QObject
38{
39 Q_OBJECT
40
41 public:
42
46 struct CORE_EXPORT MasterPasswordConfig
47 {
48 QString salt;
49 QString civ;
50 QString hash;
51 };
52
56 struct CORE_EXPORT SettingParameter
57 {
58 QString name;
59 QString description;
60 QVariant::Type type;
61 };
62
67 QgsAuthConfigurationStorage( const QMap<QString, QVariant> &settings );
68
70
75 virtual QString name() const = 0;
76
82 virtual QString type() const = 0;
83
88 virtual QString description() const = 0;
89
94 virtual QString id() const = 0;
95
104 virtual bool initialize() { return true; }
105
109 virtual QString lastError() const;
110
115 virtual bool isReady() const = 0;
116
121
125 QMap<QString, QVariant> settings() const;
126
130 virtual QList<QgsAuthConfigurationStorage::SettingParameter> settingsParameters() const = 0;
131
135 bool isEncrypted() const;
136
140 bool isEnabled() const;
141
146 void setEnabled( bool enabled );
147
148
153 virtual void setReadOnly( bool readOnly );
154
159 virtual bool isReadOnly() const;
160
166 virtual QgsAuthMethodConfigsMap authMethodConfigs( const QStringList &allowedMethods = QStringList() ) const SIP_THROW( QgsNotSupportedException ) = 0;
167
177
186 virtual QgsAuthMethodConfig loadMethodConfig( const QString &id, QString &payload SIP_OUT, bool full = false ) const SIP_THROW( QgsNotSupportedException ) = 0;
187
195 virtual bool storeMethodConfig( const QgsAuthMethodConfig &config, const QString &payload ) SIP_THROW( QgsNotSupportedException ) = 0;
196
202 virtual bool removeMethodConfig( const QString &id ) SIP_THROW( QgsNotSupportedException ) = 0;
203
210 virtual bool methodConfigExists( const QString &id ) const SIP_THROW( QgsNotSupportedException ) = 0;
211
219 virtual bool storeAuthSetting( const QString &key, const QString &value ) SIP_THROW( QgsNotSupportedException ) = 0;
220
227 virtual QString loadAuthSetting( const QString &key ) const SIP_THROW( QgsNotSupportedException ) = 0;
228
235 virtual bool removeAuthSetting( const QString &key ) SIP_THROW( QgsNotSupportedException ) = 0;
236
243 virtual bool authSettingExists( const QString &key ) const SIP_THROW( QgsNotSupportedException ) = 0;
244
245#ifndef QT_NO_SSL
246
254 virtual bool storeCertIdentity( const QSslCertificate &cert, const QString &keyPem ) SIP_THROW( QgsNotSupportedException ) = 0;
255
262 virtual bool removeCertIdentity( const QSslCertificate &cert ) SIP_THROW( QgsNotSupportedException ) = 0;
263
270 virtual const QSslCertificate loadCertIdentity( const QString &id ) const SIP_THROW( QgsNotSupportedException ) = 0;
271
278 virtual const QPair<QSslCertificate, QString> loadCertIdentityBundle( const QString &id ) const SIP_THROW( QgsNotSupportedException ) = 0;
279
285 virtual const QList<QSslCertificate> certIdentities() const SIP_THROW( QgsNotSupportedException ) = 0;
286
292 virtual QStringList certIdentityIds() const SIP_THROW( QgsNotSupportedException ) = 0;
293
300 virtual bool certIdentityExists( const QString &id ) const SIP_THROW( QgsNotSupportedException ) = 0;
301
308 virtual bool removeCertIdentity( const QString &id ) SIP_THROW( QgsNotSupportedException ) = 0;
309
317
325 virtual const QgsAuthConfigSslServer loadSslCertCustomConfig( const QString &id, const QString &hostport ) const SIP_THROW( QgsNotSupportedException ) = 0;
326
333 virtual const QgsAuthConfigSslServer loadSslCertCustomConfigByHost( const QString &hostport ) const SIP_THROW( QgsNotSupportedException ) = 0;
334
341
348
356 virtual bool sslCertCustomConfigExists( const QString &id, const QString &hostport ) SIP_THROW( QgsNotSupportedException ) = 0;
357
365 virtual bool removeSslCertCustomConfig( const QString &id, const QString &hostport ) SIP_THROW( QgsNotSupportedException ) = 0;
366
373 virtual bool storeCertAuthority( const QSslCertificate &cert ) SIP_THROW( QgsNotSupportedException ) = 0;
374
380 virtual QStringList certAuthorityIds() const SIP_THROW( QgsNotSupportedException ) = 0;
381
388 virtual const QSslCertificate loadCertAuthority( const QString &id ) const SIP_THROW( QgsNotSupportedException ) = 0;
389
396 virtual bool certAuthorityExists( const QSslCertificate &cert ) const SIP_THROW( QgsNotSupportedException ) = 0;
397
404 virtual bool removeCertAuthority( const QSslCertificate &cert ) SIP_THROW( QgsNotSupportedException ) = 0;
405
411 virtual const QMap<QString, QgsAuthCertUtils::CertTrustPolicy> caCertsPolicy() const SIP_THROW( QgsNotSupportedException ) = 0;
412
418 virtual const QList<QSslCertificate> caCerts() const SIP_THROW( QgsNotSupportedException ) = 0;
419
427 virtual bool storeCertTrustPolicy( const QSslCertificate &cert, QgsAuthCertUtils::CertTrustPolicy policy ) SIP_THROW( QgsNotSupportedException ) = 0;
428
435 virtual QgsAuthCertUtils::CertTrustPolicy loadCertTrustPolicy( const QSslCertificate &cert ) const SIP_THROW( QgsNotSupportedException ) = 0;
436
443 virtual bool removeCertTrustPolicy( const QSslCertificate &cert ) SIP_THROW( QgsNotSupportedException ) = 0;
444
451 virtual bool certTrustPolicyExists( const QSslCertificate &cert ) const SIP_THROW( QgsNotSupportedException ) = 0;
452
453#endif
454
460 virtual const QList<QgsAuthConfigurationStorage::MasterPasswordConfig> masterPasswords( ) const SIP_THROW( QgsNotSupportedException ) = 0;
461
469
476
483
491
492
493 signals:
494
502 void messageLog( const QString &message, const QString &tag = u"Authentication"_s, Qgis::MessageLevel level = Qgis::MessageLevel::Info );
503
511 void storageChanged( const QString &id );
512
517
522
527
531 void readOnlyChanged( bool readOnly );
532
533
534#ifndef QT_NO_SSL
535
540
545
550
555
556#endif
557
558 protected:
559
564
568 void setError( const QString &error, Qgis::MessageLevel level = Qgis::MessageLevel::Critical );
569
575
580 virtual QString loggerTag() const;
581
585 QMap<QString, QVariant> mConfiguration;
586
591
595 mutable QString mLastError;
596
600 bool mIsEncrypted = true;
601
605 bool mIsEnabled = true;
606
610 bool mIsReadOnly = false;
611
612};
613
614#endif // QGSAUTHCONFIGURATIONSTORAGE_H
Provides global constants and enumerations for use throughout the application.
Definition qgis.h:59
QFlags< AuthConfigurationStorageCapability > AuthConfigurationStorageCapabilities
Authentication configuration storage capabilities.
Definition qgis.h:150
MessageLevel
Level for messages This will be used both for message log and message bar in application.
Definition qgis.h:159
@ Critical
Critical/error message.
Definition qgis.h:162
AuthConfigurationStorageCapability
Authentication configuration storage capabilities.
Definition qgis.h:105
Utilities for working with certificates and keys.
Configuration container for SSL server connection exceptions or overrides.
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.
QMap< QString, QVariant > mConfiguration
Store the implementation-specific configuration.
void readOnlyChanged(bool readOnly)
Emitted when the storage read-only status was changed.
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.
QString mLastError
Store the last error message.
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)
void certIdentityChanged()
Emitted when the storage cert identity table was changed.
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.
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 setCapabilities(Qgis::AuthConfigurationStorageCapabilities capabilities)
Set the capabilities of the storage to capabilities.
virtual void setReadOnly(bool readOnly)
Utility method to unset all editing capabilities.
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.
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.
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.
Qgis::AuthConfigurationStorageCapabilities capabilities() const
Returns the capabilities of 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 QString loggerTag() const
Returns the logger tag for the storage.
bool isEnabled() const
Returns true if the storage is enabled.
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.
void setEnabled(bool enabled)
Set the storage enabled status to enabled.
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").
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.
virtual bool clearMethodConfigs()=0
Remove all authentications configurations from the storage.
bool isEncrypted() const
Returns true if the storage is encrypted.
virtual bool storeMethodConfig(const QgsAuthMethodConfig &config, const QString &payload)=0
Store an authentication config in the database.
bool mIsEnabled
Store whether the storage is enabled.
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.
void sslCertCustomConfigChanged()
Emitted when the storage ssl cert custom config table was changed.
bool mIsReadOnly
Store whether the storage is read-only.
void authSettingsChanged()
Emitted when the storage auth settings table was changed.
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).
void storageChanged(const QString &id)
Emitted when the storage was updated.
bool mIsEncrypted
Store whether the storage is encrypted.
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.
void checkCapability(Qgis::AuthConfigurationStorageCapability capability) const
Utility to check capability and throw QgsNotSupportedException if not supported.
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 isReadOnly() const
Returns true if the storage is read-only, false otherwise.
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.
Qgis::AuthConfigurationStorageCapabilities mCapabilities
Store the capabilities of the storage.
Configuration storage class for authentication method configurations.
Custom exception class which is raised when an operation is not supported.
#define SIP_SKIP
Definition qgis_sip.h:134
#define SIP_OUT
Definition qgis_sip.h:58
#define SIP_THROW(name,...)
Definition qgis_sip.h:211
QHash< QString, QgsAuthMethodConfig > QgsAuthMethodConfigsMap
Structure that holds the (encrypted) master password elements.