QGIS API Documentation  3.18.1-Zürich (202f1bf7e5)
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 #include <QMutex>
27 
28 #include "qgis_core.h"
29 
31 
36 class CORE_EXPORT QgsAuthMethod : public QObject
37 {
38  Q_OBJECT
39 
40  public:
41 
50  enum Expansion
51  {
52  // TODO: Figure out all different authentication expansions current layer providers use
53  NetworkRequest = 0x1,
54  NetworkReply = 0x2,
55  DataSourceUri = 0x4,
56  GenericDataSourceUri = 0x8,
57  NetworkProxy = 0x16,
58  All = NetworkRequest | NetworkReply | DataSourceUri | GenericDataSourceUri | NetworkProxy
59  };
60  Q_DECLARE_FLAGS( Expansions, Expansion )
61 
62 
63  virtual QString key() const = 0;
64 
66  virtual QString description() const = 0;
67 
69  virtual QString displayDescription() const = 0;
70 
72  int version() const { return mVersion; }
73 
79  QgsAuthMethod::Expansions supportedExpansions() const { return mExpansions; }
80 
85  QStringList supportedDataProviders() const { return mDataProviders; }
86 
95  virtual bool updateNetworkRequest( QNetworkRequest &request, const QString &authcfg,
96  const QString &dataprovider = QString() )
97  {
98  Q_UNUSED( request )
99  Q_UNUSED( authcfg )
100  Q_UNUSED( dataprovider )
101  return true; // noop
102  }
103 
112  virtual bool updateNetworkReply( QNetworkReply *reply, const QString &authcfg,
113  const QString &dataprovider = QString() )
114  {
115  Q_UNUSED( reply )
116  Q_UNUSED( authcfg )
117  Q_UNUSED( dataprovider )
118  return true; // noop
119  }
120 
129  virtual bool updateDataSourceUriItems( QStringList &connectionItems, const QString &authcfg,
130  const QString &dataprovider = QString() )
131  {
132  Q_UNUSED( connectionItems )
133  Q_UNUSED( authcfg )
134  Q_UNUSED( dataprovider )
135  return true; // noop
136  }
137 
146  virtual bool updateNetworkProxy( QNetworkProxy &proxy, const QString &authcfg,
147  const QString &dataprovider = QString() )
148  {
149  Q_UNUSED( proxy )
150  Q_UNUSED( authcfg )
151  Q_UNUSED( dataprovider )
152  return true; // noop
153  }
154 
161  virtual void clearCachedConfig( const QString &authcfg ) = 0;
162 
167  virtual void updateMethodConfig( QgsAuthMethodConfig &mconfig ) = 0;
168 
169  protected:
170 
175  explicit QgsAuthMethod()
176  : mMutex( QMutex::RecursionMode::Recursive )
177  {}
178 
179 
181  static QString authMethodTag() { return QObject::tr( "Authentication method" ); }
182 
184  void setVersion( int version ) { mVersion = version; }
185 
187  void setExpansions( QgsAuthMethod::Expansions expansions ) { mExpansions = expansions; }
189  void setDataProviders( const QStringList &dataproviders ) { mDataProviders = dataproviders; }
190 
191  QgsAuthMethod::Expansions mExpansions = QgsAuthMethod::Expansions();
192  QStringList mDataProviders;
193  int mVersion = 0;
194  QMutex mMutex;
195 
196 };
197 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsAuthMethod::Expansions )
198 
199 typedef QHash<QString, QgsAuthMethod *> QgsAuthMethodsMap;
200 
201 #endif // QGSAUTHMETHOD_H
Configuration storage class for authentication method configurations.
Definition: qgsauthconfig.h:39
Abstract base class for authentication method plugins.
Definition: qgsauthmethod.h:37
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.
Definition: qgsauthmethod.h:95
QStringList mDataProviders
QgsAuthMethod::Expansions supportedExpansions() const
Flags that represent the update points (where authentication configurations are expanded) supported b...
Definition: qgsauthmethod.h:79
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:85
virtual void clearCachedConfig(const QString &authcfg)=0
Clear any cached configuration.
virtual void updateMethodConfig(QgsAuthMethodConfig &mconfig)=0
Update an authentication configuration in place.
QgsAuthMethod()
Construct a default authentication method.
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:51
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.