LCOV - code coverage report
Current view: top level - core/auth - qgsauthmethod.h (source / functions) Hit Total Coverage
Test: coverage.info.cleaned Lines: 0 2 0.0 %
Date: 2021-04-10 08:29:14 Functions: 0 0 -
Branches: 0 0 -

           Branch data     Line data    Source code
       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                 :            : 
      35                 :            : class QgsAuthMethodConfig;
      36                 :            : 
      37                 :            : /**
      38                 :            :  * \ingroup core
      39                 :            :  * \brief Abstract base class for authentication method plugins
      40                 :            :  */
      41                 :            : class CORE_EXPORT QgsAuthMethod : public QObject
      42                 :            : {
      43                 :            :     Q_OBJECT
      44                 :            : 
      45                 :            :   public:
      46                 :            : 
      47                 :            :     /**
      48                 :            :      * Flags that represent the update points (where authentication configurations are expanded)
      49                 :            :      * supported by an authentication method. These equate to the 'update*()' virtual functions
      50                 :            :      * below, and allow for update point code to skip calling an unused update by a method, because
      51                 :            :      * the base virtual function will always return TRUE, giving a false impression an update occurred.
      52                 :            :      * \note When adding an 'update' member function, also add the corresponding Expansion flag.
      53                 :            :      * \note These flags will be added to as new update points are added
      54                 :            :      */
      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                 :            :     //! A non-translated short name representing the auth method
      68                 :            :     virtual QString key() const = 0;
      69                 :            : 
      70                 :            :     //! A non-translated short description representing the auth method for use in debug output and About dialog
      71                 :            :     virtual QString description() const = 0;
      72                 :            : 
      73                 :            :     //! Translatable display version of the 'description()'
      74                 :            :     virtual QString displayDescription() const = 0;
      75                 :            : 
      76                 :            :     //! Increment this if method is significantly updated, allow updater code to be written for previously stored authcfg
      77                 :            :     int version() const { return mVersion; }
      78                 :            : 
      79                 :            :     /**
      80                 :            :      * Flags that represent the update points (where authentication configurations are expanded)
      81                 :            :      * supported by an authentication method.
      82                 :            :      * \note These should directly correlate to existing 'update*()' member functions
      83                 :            :      */
      84                 :          0 :     QgsAuthMethod::Expansions supportedExpansions() const { return mExpansions; }
      85                 :            : 
      86                 :            :     /**
      87                 :            :      * The data providers that the method supports, allowing for filtering out authcfgs that are not
      88                 :            :      * applicable to a given provider, or where the updating code is not currently implemented.
      89                 :            :      */
      90                 :          0 :     QStringList supportedDataProviders() const { return mDataProviders; }
      91                 :            : 
      92                 :            :     /**
      93                 :            :      * Update a network request with authentication components
      94                 :            :      * \param request The network request to update
      95                 :            :      * \param authcfg Authentication configuration ID
      96                 :            :      * \param dataprovider Textual key for a data provider, e.g. 'postgres', that allows
      97                 :            :      * for custom updater code specific to the provider
      98                 :            :      * \returns Whether the update succeeded
      99                 :            :      */
     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                 :            : 
     109                 :            :     /**
     110                 :            :      * Update a network reply with authentication components
     111                 :            :      * \param reply The network reply object to update
     112                 :            :      * \param authcfg Authentication configuration ID
     113                 :            :      * \param dataprovider Textual key for a data provider, e.g. 'postgres', that allows
     114                 :            :      * for custom updater code specific to the provider
     115                 :            :      * \returns Whether the update succeeded
     116                 :            :      */
     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                 :            : 
     126                 :            :     /**
     127                 :            :      * Update data source connection items with authentication components
     128                 :            :      * \param connectionItems QStringlist of 'key=value' pairs, as utilized in QgsDataSourceUri::connectionInfo()
     129                 :            :      * \param authcfg Authentication configuration ID
     130                 :            :      * \param dataprovider Textual key for a data provider, e.g. 'postgres', that allows
     131                 :            :      * for custom updater code specific to the provider
     132                 :            :      * \returns Whether the update succeeded
     133                 :            :      */
     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                 :            : 
     143                 :            :     /**
     144                 :            :      * Update proxy settings with authentication components
     145                 :            :      * \param proxy
     146                 :            :      * \param authcfg Authentication configuration ID
     147                 :            :      * \param dataprovider Textual key for a data provider, e.g. 'proxy', that allows
     148                 :            :      * for custom updater code specific to the provider
     149                 :            :      * \returns Whether the update succeeded
     150                 :            :      */
     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                 :            : 
     160                 :            :     /**
     161                 :            :      * Clear any cached configuration. Called when the QgsAuthManager deletes an authentication configuration (authcfg).
     162                 :            :      * \note It is highly recommended that a cache of authentication components (per requested authcfg)
     163                 :            :      * be implemented, to avoid excessive queries on the auth database. Such a cache could be as
     164                 :            :      * simple as a QHash or QMap of authcfg -> QgsAuthMethodConfig. See 'Basic' auth method plugin for example.
     165                 :            :      */
     166                 :            :     virtual void clearCachedConfig( const QString &authcfg ) = 0;
     167                 :            : 
     168                 :            :     /**
     169                 :            :      * Update an authentication configuration in place
     170                 :            :      * \note Useful for updating previously stored authcfgs, when an authentication method has been significantly updated
     171                 :            :      */
     172                 :            :     virtual void updateMethodConfig( QgsAuthMethodConfig &mconfig ) = 0;
     173                 :            : 
     174                 :            :   protected:
     175                 :            : 
     176                 :            :     /**
     177                 :            :      * Construct a default authentication method
     178                 :            :      * \note Non-public since this is an abstract base class
     179                 :            :      */
     180                 :            :     explicit QgsAuthMethod();
     181                 :            : 
     182                 :            :     //! Tag signifying that this is an authentcation method (e.g. for use as title in message log panel output)
     183                 :            :     static QString authMethodTag() { return QObject::tr( "Authentication method" ); }
     184                 :            : 
     185                 :            :     //! Sets the version of the auth method (useful for future upgrading)
     186                 :            :     void setVersion( int version ) { mVersion = version; }
     187                 :            : 
     188                 :            :     //! Sets the support expansions (points in providers where the authentication is injected) of the auth method
     189                 :            :     void setExpansions( QgsAuthMethod::Expansions expansions ) { mExpansions = expansions; }
     190                 :            :     //! Sets list of data providers this auth method supports
     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

Generated by: LCOV version 1.14