QGIS API Documentation 3.99.0-Master (26c88405ac0)
Loading...
Searching...
No Matches
qgsauthconfig.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsauthconfig.h
3 ---------------------
4 begin : October 5, 2014
5 copyright : (C) 2014 by Boundless Spatial, Inc. USA
6 author : Larry Shaffer
7 email : lshaffer at boundlessgeo dot com
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
17#ifndef QGSAUTHCONFIG_H
18#define QGSAUTHCONFIG_H
19
20#include "qgis_core.h"
21#include "qgis_sip.h"
22
23#include <QDomDocument>
24#include <QDomElement>
25#include <QHash>
26#include <QString>
27
28#ifndef QT_NO_SSL
29#include <QSslCertificate>
30#include <QSslKey>
31#include <QSslError>
32#include <QSslSocket>
33#endif
34
35#include "qgis.h"
36
37
42class CORE_EXPORT QgsAuthMethodConfig
43{
44 public:
45
51 QgsAuthMethodConfig( const QString &method = QString(), int version = 0 );
52
53 // TODO c++20 - replace with = default
54
55 bool operator==( const QgsAuthMethodConfig &other ) const;
56 bool operator!=( const QgsAuthMethodConfig &other ) const;
57
62 const QString id() const { return mId; }
64 void setId( const QString &id ) { mId = id; }
65
67 const QString name() const { return mName; }
69 void setName( const QString &name ) { mName = name; }
70
72 const QString uri() const { return mUri; }
73 void setUri( const QString &uri ) { mUri = uri; }
74
76 QString method() const { return mMethod; }
77 void setMethod( const QString &method ) { mMethod = method; }
78
80 int version() const { return mVersion; }
82 void setVersion( int version ) { mVersion = version; }
83
88 bool isValid( bool validateid = false ) const;
89
94 const QString configString() const;
95
100 void loadConfigString( const QString &configstr );
101
103 QgsStringMap configMap() const { return mConfigMap; }
104
109 void setConfigMap( const QgsStringMap &map ) { mConfigMap = map; }
110
117 void setConfig( const QString &key, const QString &value );
118
125 void setConfigList( const QString &key, const QStringList &value );
126
132 int removeConfig( const QString &key );
133
139 QString config( const QString &key, const QString &defaultvalue = QString() ) const;
140
145 QStringList configList( const QString &key ) const;
146
151 bool hasConfig( const QString &key ) const;
152
154 void clearConfigMap() { mConfigMap.clear(); }
155
164 static bool uriToResource( const QString &accessurl, QString *resource, bool withpath = false );
165
173 bool writeXml( QDomElement &parentElement, QDomDocument &document );
174
180 bool readXml( const QDomElement &element );
181
182 private:
183 QString mId;
184 QString mName;
185 QString mUri;
186 QString mMethod;
187 int mVersion;
188
189 QgsStringMap mConfigMap;
190
191 static const QString CONFIG_SEP;
192 static const QString CONFIG_KEY_SEP;
193 static const QString CONFIG_LIST_SEP;
194
195 static const int CONFIG_VERSION;
196};
197
198typedef QHash<QString, QgsAuthMethodConfig> QgsAuthMethodConfigsMap;
199
200
201#ifndef QT_NO_SSL
202
208class CORE_EXPORT QgsPkiBundle
209{
210 public:
211
218 QgsPkiBundle( const QSslCertificate &clientCert = QSslCertificate(),
219 const QSslKey &clientKey = QSslKey(),
220 const QList<QSslCertificate> &caChain = QList<QSslCertificate>() );
221
229 static const QgsPkiBundle fromPemPaths( const QString &certPath,
230 const QString &keyPath,
231 const QString &keyPass = QString(),
232 const QList<QSslCertificate> &caChain = QList<QSslCertificate>() );
233
239 static const QgsPkiBundle fromPkcs12Paths( const QString &bundlepath,
240 const QString &bundlepass = QString() );
241
243 bool isNull() const;
244
246 bool isValid() const;
247
249 const QString certId() const;
250
252 const QSslCertificate clientCert() const { return mCert; }
254 void setClientCert( const QSslCertificate &cert );
255
257 const QSslKey clientKey() const { return mCertKey; }
259 void setClientKey( const QSslKey &certkey );
260
262 const QList<QSslCertificate> caChain() const { return mCaChain; }
264 void setCaChain( const QList<QSslCertificate> &cachain ) { mCaChain = cachain; }
265
266 private:
267 QSslCertificate mCert;
268 QSslKey mCertKey;
269 QList<QSslCertificate> mCaChain;
270};
271
272
277class CORE_EXPORT QgsPkiConfigBundle
278{
279 public:
280
289 const QSslCertificate &cert,
290 const QSslKey &certkey,
291 const QList<QSslCertificate> &cachain = QList<QSslCertificate>( ) );
292
294 bool isValid();
295
297 const QgsAuthMethodConfig config() const { return mConfig; }
298
300 void setConfig( const QgsAuthMethodConfig &config ) { mConfig = config; }
301
303 const QSslCertificate clientCert() const { return mCert; }
304
306 void setClientCert( const QSslCertificate &cert ) { mCert = cert; }
307
309 const QSslKey clientCertKey() const { return mCertKey; }
310
312 void setClientCertKey( const QSslKey &certkey ) { mCertKey = certkey; }
313
318 QList<QSslCertificate> caChain() const { return mCaChain; }
319
324 void setCaChain( const QList<QSslCertificate> &caChain ) { mCaChain = caChain; }
325
326 private:
327 QgsAuthMethodConfig mConfig;
328 QSslCertificate mCert;
329 QSslKey mCertKey;
330 QList<QSslCertificate> mCaChain;
331};
332
333#ifdef SIP_RUN // should not be required, but mingw workflow needs it..
334SIP_INSERT_QLIST_ENUM_CONVERSION_CODE( QSslError::SslError, "<QSslError>" );
335#endif
336
341class CORE_EXPORT QgsAuthConfigSslServer
342{
343 public:
346
348 const QSslCertificate sslCertificate() const { return mSslCert; }
350 void setSslCertificate( const QSslCertificate &cert ) { mSslCert = cert; }
351
353 const QString sslHostPort() const { return mSslHostPort; }
355 void setSslHostPort( const QString &hostport ) { mSslHostPort = hostport; }
356
358 QSsl::SslProtocol sslProtocol() const { return mSslProtocol; }
360 void setSslProtocol( QSsl::SslProtocol protocol ) { mSslProtocol = protocol; }
361
363 const QList<QSslError> sslIgnoredErrors() const;
365 const QList<QSslError::SslError> sslIgnoredErrorEnums() const { return mSslIgnoredErrors; }
367 void setSslIgnoredErrorEnums( const QList<QSslError::SslError> &errors ) { mSslIgnoredErrors = errors; }
368
370 QSslSocket::PeerVerifyMode sslPeerVerifyMode() const { return mSslPeerVerifyMode; }
372 void setSslPeerVerifyMode( QSslSocket::PeerVerifyMode mode ) { mSslPeerVerifyMode = mode; }
373
378 int sslPeerVerifyDepth() const { return mSslPeerVerifyDepth; }
379
384 void setSslPeerVerifyDepth( int depth ) { mSslPeerVerifyDepth = depth; }
385
387 int version() const { return mVersion; }
389 void setVersion( int version ) { mVersion = version; }
390
392 int qtVersion() const { return mQtVersion; }
394 void setQtVersion( int version ) { mQtVersion = version; }
395
397 const QString configString() const;
399 void loadConfigString( const QString &config = QString() );
400
402 bool isNull() const;
403
404 private:
405
406 QString mSslHostPort;
407 QSslCertificate mSslCert;
408
409 static QSsl::SslProtocol decodeSslProtocol( const QString &protocol );
410 static QString encodeSslProtocol( QSsl::SslProtocol protocol );
411
412 QSsl::SslProtocol mSslProtocol;
413 int mQtVersion;
414 QList<QSslError::SslError> mSslIgnoredErrors;
415 QSslSocket::PeerVerifyMode mSslPeerVerifyMode = QSslSocket::VerifyPeer;
416 int mSslPeerVerifyDepth = 0;
417 int mVersion = 1;
418
419 static const QString CONF_SEP;
420};
421#endif
422
423#endif // QGSAUTHCONFIG_H
void setSslProtocol(QSsl::SslProtocol protocol)
Sets SSL server protocol to use in connections.
void setSslCertificate(const QSslCertificate &cert)
Sets server certificate object.
void setSslHostPort(const QString &hostport)
Sets server host:port string.
int version() const
Version of the configuration (used for future upgrading).
QSsl::SslProtocol sslProtocol() const
SSL server protocol to use in connections.
void setSslPeerVerifyMode(QSslSocket::PeerVerifyMode mode)
Sets SSL client's peer verify mode to use in connections.
void setVersion(int version)
Sets version of the configuration (used for future upgrading).
void setSslPeerVerifyDepth(int depth)
Set number or SSL client's peer to verify in connections.
int sslPeerVerifyDepth() const
Number or SSL client's peer to verify in connections.
void setSslIgnoredErrorEnums(const QList< QSslError::SslError > &errors)
Sets SSL server errors (as enum list) to ignore in connections.
int qtVersion() const
Qt version when the configuration was made (SSL protocols may differ).
const QList< QSslError::SslError > sslIgnoredErrorEnums() const
SSL server errors (as enum list) to ignore in connections.
QSslSocket::PeerVerifyMode sslPeerVerifyMode() const
SSL client's peer verify mode to use in connections.
const QSslCertificate sslCertificate() const
Server certificate object.
const QString sslHostPort() const
Server host:port string.
void setQtVersion(int version)
Sets Qt version when the configuration was made (SSL protocols may differ).
QgsAuthConfigSslServer()
Construct a default SSL server configuration.
Configuration storage class for authentication method configurations.
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 setConfigMap(const QgsStringMap &map)
Set extended configuration map.
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 clearConfigMap()
Clear all configs.
int version() const
Gets version of the configuration.
QgsStringMap configMap() const
Gets extended configuration, mapped to key/value pairs of QStrings.
QgsAuthMethodConfig(const QString &method=QString(), int version=0)
Construct a configuration for an authentication method.
void setMethod(const QString &method)
void setUri(const QString &uri)
void setId(const QString &id)
Sets auth config ID.
const QString certId() const
The sha hash of the client certificate.
bool isNull() const
Whether the bundle, either its certificate or private key, is null.
QgsPkiBundle(const QSslCertificate &clientCert=QSslCertificate(), const QSslKey &clientKey=QSslKey(), const QList< QSslCertificate > &caChain=QList< QSslCertificate >())
Construct a bundle from existing PKI components.
static const QgsPkiBundle fromPkcs12Paths(const QString &bundlepath, const QString &bundlepass=QString())
Construct a bundle of PKI components from a PKCS#12 file path.
const QSslKey clientKey() const
Private key object.
void setCaChain(const QList< QSslCertificate > &cachain)
Sets chain of Certificate Authorities for client certificate.
const QList< QSslCertificate > caChain() const
Chain of Certificate Authorities for client certificate.
static const QgsPkiBundle fromPemPaths(const QString &certPath, const QString &keyPath, const QString &keyPass=QString(), const QList< QSslCertificate > &caChain=QList< QSslCertificate >())
Construct a bundle of PKI components from PEM-formatted file paths.
const QSslCertificate clientCert() const
Client certificate object.
bool isValid() const
Whether the bundle is valid.
QList< QSslCertificate > caChain() const
caChain return the CA chain
void setClientCertKey(const QSslKey &certkey)
Sets private key object.
const QSslCertificate clientCert() const
Client certificate object.
const QgsAuthMethodConfig config() const
Authentication method configuration.
void setConfig(const QgsAuthMethodConfig &config)
Sets authentication method configuration.
const QSslKey clientCertKey() const
Private key object.
void setClientCert(const QSslCertificate &cert)
Sets client certificate object.
void setCaChain(const QList< QSslCertificate > &caChain)
setCaChain set the CA chain
QgsPkiConfigBundle(const QgsAuthMethodConfig &config, const QSslCertificate &cert, const QSslKey &certkey, const QList< QSslCertificate > &cachain=QList< QSslCertificate >())
Construct a bundle from existing PKI components and authentication method configuration.
bool isValid()
Whether the bundle is valid.
QMap< QString, QString > QgsStringMap
Definition qgis.h:7132
#define SIP_INSERT_QLIST_ENUM_CONVERSION_CODE(class_name,...)
Definition qgis_sip.h:297
QHash< QString, QgsAuthMethodConfig > QgsAuthMethodConfigsMap
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
bool operator!=(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)