QGIS API Documentation  3.24.2-Tisler (13c1a02865)
qgsauthmethod.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsauthmethod.h
3  ---------------------
4  begin : September 1, 2015
5  copyright : (C) 2015 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 QGSAUTHMETHOD_H
18 #define QGSAUTHMETHOD_H
19 
20 #include <QObject>
21 #include <QFlags>
22 #include <QNetworkReply>
23 #include <QNetworkRequest>
24 #include <QStringList>
25 #include <QUrl>
26 #if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
27 #include <QMutex>
28 #else
29 #include <QRecursiveMutex>
30 #endif
31 
32 #include "qgsconfig.h"
33 #include "qgis_core.h"
34 #include "qgis_sip.h"
35 
37 
42 class CORE_EXPORT QgsAuthMethod : public QObject
43 {
44  Q_OBJECT
45 
46  public:
47 
56  enum Expansion
57  {
58  // TODO: Figure out all different authentication expansions current layer providers use
59  NetworkRequest = 0x1,
60  NetworkReply = 0x2,
61  DataSourceUri = 0x4,
62  GenericDataSourceUri = 0x8,
63  NetworkProxy = 0x16,
64  All = NetworkRequest | NetworkReply | DataSourceUri | GenericDataSourceUri | NetworkProxy
65  };
66  Q_DECLARE_FLAGS( Expansions, Expansion )
67 
68 
69  virtual QString key() const = 0;
70 
72  virtual QString description() const = 0;
73 
75  virtual QString displayDescription() const = 0;
76 
78  int version() const { return mVersion; }
79 
80 
81 #ifdef HAVE_GUI
82  SIP_IF_FEATURE( HAVE_GUI )
83 
84 
88  virtual QWidget *editWidget( QWidget *parent ) const;
89  SIP_END
90 #endif
91 
97  QgsAuthMethod::Expansions supportedExpansions() const { return mExpansions; }
98 
103  QStringList supportedDataProviders() const { return mDataProviders; }
104 
113  virtual bool updateNetworkRequest( QNetworkRequest &request, const QString &authcfg,
114  const QString &dataprovider = QString() )
115  {
116  Q_UNUSED( request )
117  Q_UNUSED( authcfg )
118  Q_UNUSED( dataprovider )
119  return true; // noop
120  }
121 
130  virtual bool updateNetworkReply( QNetworkReply *reply, const QString &authcfg,
131  const QString &dataprovider = QString() )
132  {
133  Q_UNUSED( reply )
134  Q_UNUSED( authcfg )
135  Q_UNUSED( dataprovider )
136  return true; // noop
137  }
138 
147  virtual bool updateDataSourceUriItems( QStringList &connectionItems, const QString &authcfg,
148  const QString &dataprovider = QString() )
149  {
150  Q_UNUSED( connectionItems )
151  Q_UNUSED( authcfg )
152  Q_UNUSED( dataprovider )
153  return true; // noop
154  }
155 
164  virtual bool updateNetworkProxy( QNetworkProxy &proxy, const QString &authcfg,
165  const QString &dataprovider = QString() )
166  {
167  Q_UNUSED( proxy )
168  Q_UNUSED( authcfg )
169  Q_UNUSED( dataprovider )
170  return true; // noop
171  }
172 
179  virtual void clearCachedConfig( const QString &authcfg ) = 0;
180 
185  virtual void updateMethodConfig( QgsAuthMethodConfig &mconfig ) = 0;
186 
187  protected:
188 
193  explicit QgsAuthMethod();
194 
196  static QString authMethodTag() { return QObject::tr( "Authentication method" ); }
197 
199  void setVersion( int version ) { mVersion = version; }
200 
202  void setExpansions( QgsAuthMethod::Expansions expansions ) { mExpansions = expansions; }
204  void setDataProviders( const QStringList &dataproviders ) { mDataProviders = dataproviders; }
205 
206  QgsAuthMethod::Expansions mExpansions = QgsAuthMethod::Expansions();
207  QStringList mDataProviders;
208  int mVersion = 0;
209 #if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
210  QMutex mMutex;
211 #else
212  QRecursiveMutex mMutex;
213 #endif
214 };
215 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsAuthMethod::Expansions )
216 
217 typedef QHash<QString, QgsAuthMethod *> QgsAuthMethodsMap;
218 
219 #endif // QGSAUTHMETHOD_H
Configuration storage class for authentication method configurations.
Definition: qgsauthconfig.h:42
Abstract base class for authentication method plugins.
Definition: qgsauthmethod.h:43
QRecursiveMutex mMutex
virtual bool updateNetworkProxy(QNetworkProxy &proxy, const QString &authcfg, const QString &dataprovider=QString())
Update proxy settings with authentication components.
virtual bool updateNetworkRequest(QNetworkRequest &request, const QString &authcfg, const QString &dataprovider=QString())
Update a network request with authentication components.
QStringList mDataProviders
QgsAuthMethod::Expansions supportedExpansions() const
Flags that represent the update points (where authentication configurations are expanded) supported b...
Definition: qgsauthmethod.h:97
void setExpansions(QgsAuthMethod::Expansions expansions)
Sets the support expansions (points in providers where the authentication is injected) of the auth me...
QStringList supportedDataProviders() const
The data providers that the method supports, allowing for filtering out authcfgs that are not applica...
virtual void clearCachedConfig(const QString &authcfg)=0
Clear any cached configuration.
virtual void updateMethodConfig(QgsAuthMethodConfig &mconfig)=0
Update an authentication configuration in place.
void setVersion(int version)
Sets the version of the auth method (useful for future upgrading)
virtual bool updateNetworkReply(QNetworkReply *reply, const QString &authcfg, const QString &dataprovider=QString())
Update a network reply with authentication components.
virtual bool updateDataSourceUriItems(QStringList &connectionItems, const QString &authcfg, const QString &dataprovider=QString())
Update data source connection items with authentication components.
static QString authMethodTag()
Tag signifying that this is an authentcation method (e.g. for use as title in message log panel outpu...
void setDataProviders(const QStringList &dataproviders)
Sets list of data providers this auth method supports.
Expansion
Flags that represent the update points (where authentication configurations are expanded) supported b...
Definition: qgsauthmethod.h:57
#define SIP_IF_FEATURE(feature)
Definition: qgis_sip.h:167
#define SIP_END
Definition: qgis_sip.h:194
QHash< QString, QgsAuthMethod * > QgsAuthMethodsMap
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsField::ConfigurationFlags) CORE_EXPORT QDataStream &operator<<(QDataStream &out
Writes the field to stream out. QGIS version compatibility is not guaranteed.