QGIS API Documentation 3.41.0-Master (fda2aa46e9a)
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
22#include <QHash>
23#include <QString>
24#include <QDomElement>
25#include <QDomDocument>
26
27#ifndef QT_NO_SSL
28#include <QSslCertificate>
29#include <QSslKey>
30#include <QSslError>
31#include <QSslSocket>
32#endif
33
34#include "qgis.h"
35
36
41class CORE_EXPORT QgsAuthMethodConfig
42{
43 public:
44
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:
210
217 QgsPkiBundle( const QSslCertificate &clientCert = QSslCertificate(),
218 const QSslKey &clientKey = QSslKey(),
219 const QList<QSslCertificate> &caChain = QList<QSslCertificate>() );
220
228 static const QgsPkiBundle fromPemPaths( const QString &certPath,
229 const QString &keyPath,
230 const QString &keyPass = QString(),
231 const QList<QSslCertificate> &caChain = QList<QSslCertificate>() );
232
238 static const QgsPkiBundle fromPkcs12Paths( const QString &bundlepath,
239 const QString &bundlepass = QString() );
240
242 bool isNull() const;
243
245 bool isValid() const;
246
248 const QString certId() const;
249
251 const QSslCertificate clientCert() const { return mCert; }
253 void setClientCert( const QSslCertificate &cert );
254
256 const QSslKey clientKey() const { return mCertKey; }
258 void setClientKey( const QSslKey &certkey );
259
261 const QList<QSslCertificate> caChain() const { return mCaChain; }
263 void setCaChain( const QList<QSslCertificate> &cachain ) { mCaChain = cachain; }
264
265 private:
266 QSslCertificate mCert;
267 QSslKey mCertKey;
268 QList<QSslCertificate> mCaChain;
269};
270
271
276class CORE_EXPORT QgsPkiConfigBundle
277{
278 public:
279
288 const QSslCertificate &cert,
289 const QSslKey &certkey,
290 const QList<QSslCertificate> &cachain = QList<QSslCertificate>( ) );
291
293 bool isValid();
294
296 const QgsAuthMethodConfig config() const { return mConfig; }
297
299 void setConfig( const QgsAuthMethodConfig &config ) { mConfig = config; }
300
302 const QSslCertificate clientCert() const { return mCert; }
303
305 void setClientCert( const QSslCertificate &cert ) { mCert = cert; }
306
308 const QSslKey clientCertKey() const { return mCertKey; }
309
311 void setClientCertKey( const QSslKey &certkey ) { mCertKey = certkey; }
312
317 QList<QSslCertificate> caChain() const { return mCaChain; }
318
323 void setCaChain( const QList<QSslCertificate> &caChain ) { mCaChain = caChain; }
324
325 private:
326 QgsAuthMethodConfig mConfig;
327 QSslCertificate mCert;
328 QSslKey mCertKey;
329 QList<QSslCertificate> mCaChain;
330};
331
332
333
334#ifdef SIP_RUN
335% MappedType QList<QSslError::SslError>
336{
337 % TypeHeaderCode
338#include <QList>
339 % End
340
341 % ConvertFromTypeCode
342 // Create the list.
343 PyObject *l;
344
345 if ( ( l = PyList_New( sipCpp->size() ) ) == NULL )
346 return NULL;
347
348 // Set the list elements.
349 QList<QSslError::SslError>::iterator it = sipCpp->begin();
350 for ( int i = 0; it != sipCpp->end(); ++it, ++i )
351 {
352 PyObject *tobj;
353
354 if ( ( tobj = sipConvertFromEnum( *it, sipType_QSslError_SslError ) ) == NULL )
355 {
356 Py_DECREF( l );
357 return NULL;
358 }
359 PyList_SET_ITEM( l, i, tobj );
360 }
361
362 return l;
363 % End
364
365 % ConvertToTypeCode
366 // Check the type if that is all that is required.
367 if ( sipIsErr == NULL )
368 return PyList_Check( sipPy );
369
370 QList<QSslError::SslError> *qlist = new QList<QSslError::SslError>;
371
372 for ( int i = 0; i < PyList_GET_SIZE( sipPy ); ++i )
373 {
374 *qlist << ( QSslError::SslError )SIPLong_AsLong( PyList_GET_ITEM( sipPy, i ) );
375 }
376
377 *sipCppPtr = qlist;
378 return sipGetState( sipTransferObj );
379 % End
380};
381#endif
382
383
384
389class CORE_EXPORT QgsAuthConfigSslServer
390{
391 public:
394
396 const QSslCertificate sslCertificate() const { return mSslCert; }
398 void setSslCertificate( const QSslCertificate &cert ) { mSslCert = cert; }
399
401 const QString sslHostPort() const { return mSslHostPort; }
403 void setSslHostPort( const QString &hostport ) { mSslHostPort = hostport; }
404
406 QSsl::SslProtocol sslProtocol() const { return mSslProtocol; }
408 void setSslProtocol( QSsl::SslProtocol protocol ) { mSslProtocol = protocol; }
409
411 const QList<QSslError> sslIgnoredErrors() const;
413 const QList<QSslError::SslError> sslIgnoredErrorEnums() const { return mSslIgnoredErrors; }
415 void setSslIgnoredErrorEnums( const QList<QSslError::SslError> &errors ) { mSslIgnoredErrors = errors; }
416
418 QSslSocket::PeerVerifyMode sslPeerVerifyMode() const { return mSslPeerVerifyMode; }
420 void setSslPeerVerifyMode( QSslSocket::PeerVerifyMode mode ) { mSslPeerVerifyMode = mode; }
421
426 int sslPeerVerifyDepth() const { return mSslPeerVerifyDepth; }
427
432 void setSslPeerVerifyDepth( int depth ) { mSslPeerVerifyDepth = depth; }
433
435 int version() const { return mVersion; }
437 void setVersion( int version ) { mVersion = version; }
438
440 int qtVersion() const { return mQtVersion; }
442 void setQtVersion( int version ) { mQtVersion = version; }
443
445 const QString configString() const;
447 void loadConfigString( const QString &config = QString() );
448
450 bool isNull() const;
451
452 private:
453
454 QString mSslHostPort;
455 QSslCertificate mSslCert;
456
457 static QSsl::SslProtocol decodeSslProtocol( const QString &protocol );
458 static QString encodeSslProtocol( QSsl::SslProtocol protocol );
459
460 QSsl::SslProtocol mSslProtocol;
461 int mQtVersion;
462 QList<QSslError::SslError> mSslIgnoredErrors;
463 QSslSocket::PeerVerifyMode mSslPeerVerifyMode = QSslSocket::VerifyPeer;
464 int mSslPeerVerifyDepth = 0;
465 int mVersion = 1;
466
467 static const QString CONF_SEP;
468};
469#endif
470
471#endif // QGSAUTHCONFIG_H
Configuration container for SSL server connection exceptions or overrides.
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)
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.
void setMethod(const QString &method)
void setUri(const QString &uri)
void setId(const QString &id)
Sets auth config ID.
Storage set for PKI bundle: SSL certificate, key, optional CA cert chain.
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.
const QSslCertificate clientCert() const
Client certificate object.
Storage set for constructed SSL certificate, key, associated with an authentication config.
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
QMap< QString, QString > QgsStringMap
Definition qgis.h:6455
QHash< QString, QgsAuthMethodConfig > QgsAuthMethodConfigsMap
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
bool operator!=(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)