QGIS API Documentation 4.0.0-Norrköping (1ddcee3d0e4)
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:
50 QgsAuthMethodConfig( const QString &method = QString(), int version = 0 );
51
52 // TODO c++20 - replace with = default
53
54 bool operator==( const QgsAuthMethodConfig &other ) const;
55 bool operator!=( const QgsAuthMethodConfig &other ) const;
56
61 const QString id() const { return mId; }
63 void setId( const QString &id ) { mId = id; }
64
66 const QString name() const { return mName; }
68 void setName( const QString &name ) { mName = name; }
69
71 const QString uri() const { return mUri; }
72 void setUri( const QString &uri ) { mUri = uri; }
73
75 QString method() const { return mMethod; }
76 void setMethod( const QString &method ) { mMethod = method; }
77
79 int version() const { return mVersion; }
81 void setVersion( int version ) { mVersion = version; }
82
87 bool isValid( bool validateid = false ) const;
88
93 const QString configString() const;
94
99 void loadConfigString( const QString &configstr );
100
102 QgsStringMap configMap() const { return mConfigMap; }
103
108 void setConfigMap( const QgsStringMap &map ) { mConfigMap = map; }
109
116 void setConfig( const QString &key, const QString &value );
117
124 void setConfigList( const QString &key, const QStringList &value );
125
131 int removeConfig( const QString &key );
132
138 QString config( const QString &key, const QString &defaultvalue = QString() ) const;
139
144 QStringList configList( const QString &key ) const;
145
150 bool hasConfig( const QString &key ) const;
151
153 void clearConfigMap() { mConfigMap.clear(); }
154
163 static bool uriToResource( const QString &accessurl, QString *resource, bool withpath = false );
164
172 bool writeXml( QDomElement &parentElement, QDomDocument &document );
173
179 bool readXml( const QDomElement &element );
180
181 private:
182 QString mId;
183 QString mName;
184 QString mUri;
185 QString mMethod;
186 int mVersion;
187
188 QgsStringMap mConfigMap;
189
190 static const QString CONFIG_SEP;
191 static const QString CONFIG_KEY_SEP;
192 static const QString CONFIG_LIST_SEP;
193
194 static const int CONFIG_VERSION;
195};
196
197typedef QHash<QString, QgsAuthMethodConfig> QgsAuthMethodConfigsMap;
198
199
200#ifndef QT_NO_SSL
201
207class CORE_EXPORT QgsPkiBundle
208{
209 public:
216 QgsPkiBundle( const QSslCertificate &clientCert = QSslCertificate(), const QSslKey &clientKey = QSslKey(), const QList<QSslCertificate> &caChain = QList<QSslCertificate>() );
217
225 static const QgsPkiBundle fromPemPaths( const QString &certPath, const QString &keyPath, const QString &keyPass = QString(), const QList<QSslCertificate> &caChain = QList<QSslCertificate>() );
226
232 static const QgsPkiBundle fromPkcs12Paths( const QString &bundlepath, const QString &bundlepass = QString() );
233
235 bool isNull() const;
236
238 bool isValid() const;
239
241 const QString certId() const;
242
244 const QSslCertificate clientCert() const { return mCert; }
246 void setClientCert( const QSslCertificate &cert );
247
249 const QSslKey clientKey() const { return mCertKey; }
251 void setClientKey( const QSslKey &certkey );
252
254 const QList<QSslCertificate> caChain() const { return mCaChain; }
256 void setCaChain( const QList<QSslCertificate> &cachain ) { mCaChain = cachain; }
257
258 private:
259 QSslCertificate mCert;
260 QSslKey mCertKey;
261 QList<QSslCertificate> mCaChain;
262};
263
264
269class CORE_EXPORT QgsPkiConfigBundle
270{
271 public:
279 QgsPkiConfigBundle( const QgsAuthMethodConfig &config, const QSslCertificate &cert, const QSslKey &certkey, const QList<QSslCertificate> &cachain = QList<QSslCertificate>() );
280
282 bool isValid();
283
285 const QgsAuthMethodConfig config() const { return mConfig; }
286
288 void setConfig( const QgsAuthMethodConfig &config ) { mConfig = config; }
289
291 const QSslCertificate clientCert() const { return mCert; }
292
294 void setClientCert( const QSslCertificate &cert ) { mCert = cert; }
295
297 const QSslKey clientCertKey() const { return mCertKey; }
298
300 void setClientCertKey( const QSslKey &certkey ) { mCertKey = certkey; }
301
306 QList<QSslCertificate> caChain() const { return mCaChain; }
307
312 void setCaChain( const QList<QSslCertificate> &caChain ) { mCaChain = caChain; }
313
314 private:
315 QgsAuthMethodConfig mConfig;
316 QSslCertificate mCert;
317 QSslKey mCertKey;
318 QList<QSslCertificate> mCaChain;
319};
320
321#ifdef SIP_RUN // should not be required, but mingw workflow needs it..
322SIP_INSERT_QLIST_ENUM_CONVERSION_CODE( QSslError::SslError, "<QSslError>" );
323#endif
324
329class CORE_EXPORT QgsAuthConfigSslServer
330{
331 public:
334
336 const QSslCertificate sslCertificate() const { return mSslCert; }
338 void setSslCertificate( const QSslCertificate &cert ) { mSslCert = cert; }
339
341 const QString sslHostPort() const { return mSslHostPort; }
343 void setSslHostPort( const QString &hostport ) { mSslHostPort = hostport; }
344
346 QSsl::SslProtocol sslProtocol() const { return mSslProtocol; }
348 void setSslProtocol( QSsl::SslProtocol protocol ) { mSslProtocol = protocol; }
349
351 const QList<QSslError> sslIgnoredErrors() const;
353 const QList<QSslError::SslError> sslIgnoredErrorEnums() const { return mSslIgnoredErrors; }
355 void setSslIgnoredErrorEnums( const QList<QSslError::SslError> &errors ) { mSslIgnoredErrors = errors; }
356
358 QSslSocket::PeerVerifyMode sslPeerVerifyMode() const { return mSslPeerVerifyMode; }
360 void setSslPeerVerifyMode( QSslSocket::PeerVerifyMode mode ) { mSslPeerVerifyMode = mode; }
361
366 int sslPeerVerifyDepth() const { return mSslPeerVerifyDepth; }
367
372 void setSslPeerVerifyDepth( int depth ) { mSslPeerVerifyDepth = depth; }
373
375 int version() const { return mVersion; }
377 void setVersion( int version ) { mVersion = version; }
378
380 int qtVersion() const { return mQtVersion; }
382 void setQtVersion( int version ) { mQtVersion = version; }
383
385 const QString configString() const;
387 void loadConfigString( const QString &config = QString() );
388
390 bool isNull() const;
391
392 private:
393 QString mSslHostPort;
394 QSslCertificate mSslCert;
395
396 static QSsl::SslProtocol decodeSslProtocol( const QString &protocol );
397 static QString encodeSslProtocol( QSsl::SslProtocol protocol );
398
399 QSsl::SslProtocol mSslProtocol;
400 int mQtVersion;
401 QList<QSslError::SslError> mSslIgnoredErrors;
402 QSslSocket::PeerVerifyMode mSslPeerVerifyMode = QSslSocket::VerifyPeer;
403 int mSslPeerVerifyDepth = 0;
404 int mVersion = 1;
405
406 static const QString CONF_SEP;
407};
408#endif
409
410#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:7475
#define SIP_INSERT_QLIST_ENUM_CONVERSION_CODE(class_name,...)
Definition qgis_sip.h:296
QHash< QString, QgsAuthMethodConfig > QgsAuthMethodConfigsMap
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
bool operator!=(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)