QGIS API Documentation 3.27.0-Master (1c05421486)
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 <QRecursiveMutex>
27
28#include "qgsconfig.h"
29#include "qgis_core.h"
30#include "qgis_sip.h"
31
33
38class CORE_EXPORT QgsAuthMethod : public QObject
39{
40 Q_OBJECT
41
42 public:
43
53 {
54 // TODO: Figure out all different authentication expansions current layer providers use
55 NetworkRequest = 0x1,
56 NetworkReply = 0x2,
57 DataSourceUri = 0x4,
58 GenericDataSourceUri = 0x8,
59 NetworkProxy = 0x16,
60 All = NetworkRequest | NetworkReply | DataSourceUri | GenericDataSourceUri | NetworkProxy
61 };
62 Q_DECLARE_FLAGS( Expansions, Expansion )
63
64
65 virtual QString key() const = 0;
66
68 virtual QString description() const = 0;
69
71 virtual QString displayDescription() const = 0;
72
74 int version() const { return mVersion; }
75
76
77#ifdef HAVE_GUI
78 SIP_IF_FEATURE( HAVE_GUI )
79
80
84 virtual QWidget *editWidget( QWidget *parent ) const;
86#endif
87
93 QgsAuthMethod::Expansions supportedExpansions() const { return mExpansions; }
94
99 QStringList supportedDataProviders() const { return mDataProviders; }
100
109 virtual bool updateNetworkRequest( QNetworkRequest &request, const QString &authcfg,
110 const QString &dataprovider = QString() )
111 {
112 Q_UNUSED( request )
113 Q_UNUSED( authcfg )
114 Q_UNUSED( dataprovider )
115 return true; // noop
116 }
117
126 virtual bool updateNetworkReply( QNetworkReply *reply, const QString &authcfg,
127 const QString &dataprovider = QString() )
128 {
129 Q_UNUSED( reply )
130 Q_UNUSED( authcfg )
131 Q_UNUSED( dataprovider )
132 return true; // noop
133 }
134
143 virtual bool updateDataSourceUriItems( QStringList &connectionItems, const QString &authcfg,
144 const QString &dataprovider = QString() )
145 {
146 Q_UNUSED( connectionItems )
147 Q_UNUSED( authcfg )
148 Q_UNUSED( dataprovider )
149 return true; // noop
150 }
151
160 virtual bool updateNetworkProxy( QNetworkProxy &proxy, const QString &authcfg,
161 const QString &dataprovider = QString() )
162 {
163 Q_UNUSED( proxy )
164 Q_UNUSED( authcfg )
165 Q_UNUSED( dataprovider )
166 return true; // noop
167 }
168
175 virtual void clearCachedConfig( const QString &authcfg ) = 0;
176
181 virtual void updateMethodConfig( QgsAuthMethodConfig &mconfig ) = 0;
182
183 protected:
184
189 explicit QgsAuthMethod();
190
192 static QString authMethodTag() { return QObject::tr( "Authentication method" ); }
193
195 void setVersion( int version ) { mVersion = version; }
196
198 void setExpansions( QgsAuthMethod::Expansions expansions ) { mExpansions = expansions; }
200 void setDataProviders( const QStringList &dataproviders ) { mDataProviders = dataproviders; }
201
202 QgsAuthMethod::Expansions mExpansions = QgsAuthMethod::Expansions();
203 QStringList mDataProviders;
204 int mVersion = 0;
205 QRecursiveMutex mMutex;
206};
207Q_DECLARE_OPERATORS_FOR_FLAGS( QgsAuthMethod::Expansions )
208
209typedef QHash<QString, QgsAuthMethod *> QgsAuthMethodsMap;
210
211#endif // QGSAUTHMETHOD_H
Configuration storage class for authentication method configurations.
Definition: qgsauthconfig.h:42
Abstract base class for authentication method plugins.
Definition: qgsauthmethod.h:39
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:93
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:99
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:53
#define SIP_IF_FEATURE(feature)
Definition: qgis_sip.h:176
#define SIP_END
Definition: qgis_sip.h:203
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.