QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
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 
27 #include "qgsauthconfig.h"
28 
29 
33 class CORE_EXPORT QgsAuthMethod : public QObject
34 {
35  Q_OBJECT
36 
37  public:
38 
46  enum Expansion
47  {
48  // TODO: Figure out all different authentication expansions current layer providers use
49  NetworkRequest = 0x1,
50  NetworkReply = 0x2,
51  DataSourceURI = 0x4,
52  GenericDataSourceURI = 0x8,
53  All = NetworkRequest | NetworkReply | DataSourceURI | GenericDataSourceURI
54  };
55  Q_DECLARE_FLAGS( Expansions, Expansion )
56 
57  virtual ~QgsAuthMethod() {}
58 
60  virtual QString key() const = 0;
61 
63  virtual QString description() const = 0;
64 
66  virtual QString displayDescription() const = 0;
67 
69  int version() const { return mVersion; }
70 
75  QgsAuthMethod::Expansions supportedExpansions() const { return mExpansions; }
76 
80  QStringList supportedDataProviders() const { return mDataProviders; }
81 
89  virtual bool updateNetworkRequest( QNetworkRequest &request, const QString &authcfg,
90  const QString &dataprovider = QString() )
91  {
92  Q_UNUSED( request )
93  Q_UNUSED( authcfg )
94  Q_UNUSED( dataprovider )
95  return true; // noop
96  }
97 
105  virtual bool updateNetworkReply( QNetworkReply *reply, const QString &authcfg,
106  const QString &dataprovider = QString() )
107  {
108  Q_UNUSED( reply )
109  Q_UNUSED( authcfg )
110  Q_UNUSED( dataprovider )
111  return true; // noop
112  }
113 
121  virtual bool updateDataSourceUriItems( QStringList &connectionItems, const QString &authcfg,
122  const QString &dataprovider = QString() )
123  {
124  Q_UNUSED( connectionItems )
125  Q_UNUSED( authcfg )
126  Q_UNUSED( dataprovider )
127  return true; // noop
128  }
129 
135  virtual void clearCachedConfig( const QString &authcfg ) = 0;
136 
140  virtual void updateMethodConfig( QgsAuthMethodConfig &mconfig ) = 0;
141 
142  protected:
147  explicit QgsAuthMethod()
148  : mExpansions( QgsAuthMethod::Expansions( nullptr ) )
149  , mDataProviders( QStringList() )
150  , mVersion( 0 )
151  {}
152 
154  static QString authMethodTag() { return QObject::tr( "Authentication method" ); }
155 
157  void setVersion( int version ) { mVersion = version; }
158 
160  void setExpansions( const QgsAuthMethod::Expansions& expansions ) { mExpansions = expansions; }
162  void setDataProviders( const QStringList& dataproviders ) { mDataProviders = dataproviders; }
163 
164  QgsAuthMethod::Expansions mExpansions;
166  int mVersion;
167 };
168 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsAuthMethod::Expansions )
169 
171 
172 #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:69
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.
QString tr(const char *sourceText, const char *disambiguation, int n)
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:89
Expansion
Flags that represent the update points (where authentication configurations are expanded) supported b...
Definition: qgsauthmethod.h:46
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:36
QStringList supportedDataProviders() const
The data providers that the method supports, allowing for filtering out authcfgs that are not applica...
Definition: qgsauthmethod.h:80
Abstract base class for authentication method plugins.
Definition: qgsauthmethod.h:33
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.
void setExpansions(const QgsAuthMethod::Expansions &expansions)
Set the support expansions (points in providers where the authentication is injected) of the auth met...
QgsAuthMethod::Expansions supportedExpansions() const
Flags that represent the update points (where authentication configurations are expanded) supported b...
Definition: qgsauthmethod.h:75