QGIS API Documentation  3.0.2-Girona (307d082)
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  : mExpansions( QgsAuthMethod::Expansions( nullptr ) )
177  , mDataProviders( QStringList() )
178  , mMutex( QMutex::RecursionMode::Recursive )
179  {}
180 
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;
194  QStringList mDataProviders;
195  int mVersion = 0;
196  QMutex mMutex;
197 
198 };
199 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsAuthMethod::Expansions )
200 
201 typedef QHash<QString, QgsAuthMethod *> QgsAuthMethodsMap;
202 
203 #endif // QGSAUTHMETHOD_H
int version() const
Increment this if method is significantly updated, allow updater code to be written for previously st...
Definition: qgsauthmethod.h:72
QStringList mDataProviders
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...
QgsAuthMethod()
Construct a default authentication method.
virtual bool updateNetworkRequest(QNetworkRequest &request, const QString &authcfg, const QString &dataprovider=QString())
Update a network request with authentication components.
Definition: qgsauthmethod.h:95
Expansion
Flags that represent the update points (where authentication configurations are expanded) supported b...
Definition: qgsauthmethod.h:50
void setDataProviders(const QStringList &dataproviders)
Set list of data providers this auth method supports.
QgsAuthMethod::Expansions mExpansions
Configuration storage class for authentication method configurations.
Definition: qgsauthconfig.h:38
QStringList supportedDataProviders() const
The data providers that the method supports, allowing for filtering out authcfgs that are not applica...
Definition: qgsauthmethod.h:85
virtual bool updateNetworkProxy(QNetworkProxy &proxy, const QString &authcfg, const QString &dataprovider=QString())
Update proxy settings with authentication components.
Abstract base class for authentication method plugins.
Definition: qgsauthmethod.h:36
void setVersion(int version)
Set 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.
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)
Set the support expansions (points in providers where the authentication is injected) of the auth met...
QHash< QString, QgsAuthMethod * > QgsAuthMethodsMap