QGIS API Documentation  3.20.0-Odense (decaadbb31)
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 
33 #include "qgis_core.h"
34 
36 
41 class CORE_EXPORT QgsAuthMethod : public QObject
42 {
43  Q_OBJECT
44 
45  public:
46 
55  enum Expansion
56  {
57  // TODO: Figure out all different authentication expansions current layer providers use
58  NetworkRequest = 0x1,
59  NetworkReply = 0x2,
60  DataSourceUri = 0x4,
61  GenericDataSourceUri = 0x8,
62  NetworkProxy = 0x16,
63  All = NetworkRequest | NetworkReply | DataSourceUri | GenericDataSourceUri | NetworkProxy
64  };
65  Q_DECLARE_FLAGS( Expansions, Expansion )
66 
67 
68  virtual QString key() const = 0;
69 
71  virtual QString description() const = 0;
72 
74  virtual QString displayDescription() const = 0;
75 
77  int version() const { return mVersion; }
78 
84  QgsAuthMethod::Expansions supportedExpansions() const { return mExpansions; }
85 
90  QStringList supportedDataProviders() const { return mDataProviders; }
91 
100  virtual bool updateNetworkRequest( QNetworkRequest &request, const QString &authcfg,
101  const QString &dataprovider = QString() )
102  {
103  Q_UNUSED( request )
104  Q_UNUSED( authcfg )
105  Q_UNUSED( dataprovider )
106  return true; // noop
107  }
108 
117  virtual bool updateNetworkReply( QNetworkReply *reply, const QString &authcfg,
118  const QString &dataprovider = QString() )
119  {
120  Q_UNUSED( reply )
121  Q_UNUSED( authcfg )
122  Q_UNUSED( dataprovider )
123  return true; // noop
124  }
125 
134  virtual bool updateDataSourceUriItems( QStringList &connectionItems, const QString &authcfg,
135  const QString &dataprovider = QString() )
136  {
137  Q_UNUSED( connectionItems )
138  Q_UNUSED( authcfg )
139  Q_UNUSED( dataprovider )
140  return true; // noop
141  }
142 
151  virtual bool updateNetworkProxy( QNetworkProxy &proxy, const QString &authcfg,
152  const QString &dataprovider = QString() )
153  {
154  Q_UNUSED( proxy )
155  Q_UNUSED( authcfg )
156  Q_UNUSED( dataprovider )
157  return true; // noop
158  }
159 
166  virtual void clearCachedConfig( const QString &authcfg ) = 0;
167 
172  virtual void updateMethodConfig( QgsAuthMethodConfig &mconfig ) = 0;
173 
174  protected:
175 
180  explicit QgsAuthMethod();
181 
183  static QString authMethodTag() { return QObject::tr( "Authentication method" ); }
184 
186  void setVersion( int version ) { mVersion = version; }
187 
189  void setExpansions( QgsAuthMethod::Expansions expansions ) { mExpansions = expansions; }
191  void setDataProviders( const QStringList &dataproviders ) { mDataProviders = dataproviders; }
192 
193  QgsAuthMethod::Expansions mExpansions = QgsAuthMethod::Expansions();
194  QStringList mDataProviders;
195  int mVersion = 0;
196 #if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
197  QMutex mMutex;
198 #else
199  QRecursiveMutex mMutex;
200 #endif
201 };
202 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsAuthMethod::Expansions )
203 
204 typedef QHash<QString, QgsAuthMethod *> QgsAuthMethodsMap;
205 
206 #endif // QGSAUTHMETHOD_H
Configuration storage class for authentication method configurations.
Definition: qgsauthconfig.h:42
Abstract base class for authentication method plugins.
Definition: qgsauthmethod.h:42
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:84
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...
Definition: qgsauthmethod.h:90
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:56
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.