mirror of
				https://github.com/qgis/QGIS.git
				synced 2025-11-04 00:04:25 -05:00 
			
		
		
		
	allow to build auth methods statically
This commit is contained in:
		
							parent
							
								
									6995cfd037
								
							
						
					
					
						commit
						a42df3b856
					
				@ -217,6 +217,16 @@ Gets authentication method from the config/provider cache via its key
 | 
			
		||||
:param authMethodKey: Authentication method key
 | 
			
		||||
%End
 | 
			
		||||
 | 
			
		||||
    const QgsAuthMethodMetadata *authMethodMetadata( const QString &authMethodKey );
 | 
			
		||||
%Docstring
 | 
			
		||||
Gets authentication method metadata via its key
 | 
			
		||||
 | 
			
		||||
:param authMethodKey: Authentication method key
 | 
			
		||||
 | 
			
		||||
.. versionadded:: 3.22
 | 
			
		||||
%End
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    QWidget *authMethodEditWidget( const QString &authMethodKey, QWidget *parent );
 | 
			
		||||
%Docstring
 | 
			
		||||
 | 
			
		||||
@ -11,6 +11,7 @@
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class QgsAuthMethod : QObject
 | 
			
		||||
{
 | 
			
		||||
%Docstring(signature="appended")
 | 
			
		||||
@ -35,26 +36,14 @@ Abstract base class for authentication method plugins
 | 
			
		||||
    typedef QFlags<QgsAuthMethod::Expansion> Expansions;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    virtual QString key() const = 0;
 | 
			
		||||
%Docstring
 | 
			
		||||
A non-translated short name representing the auth method
 | 
			
		||||
%End
 | 
			
		||||
 | 
			
		||||
    virtual QString description() const = 0;
 | 
			
		||||
%Docstring
 | 
			
		||||
A non-translated short description representing the auth method for use in debug output and About dialog
 | 
			
		||||
%End
 | 
			
		||||
 | 
			
		||||
    virtual QString displayDescription() const = 0;
 | 
			
		||||
%Docstring
 | 
			
		||||
Translatable display version of the ':py:func:`~QgsAuthMethod.description`'
 | 
			
		||||
%End
 | 
			
		||||
 | 
			
		||||
    int version() const;
 | 
			
		||||
%Docstring
 | 
			
		||||
Increment this if method is significantly updated, allow updater code to be written for previously stored authcfg
 | 
			
		||||
%End
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    virtual QWidget *editWidget( QWidget *parent )const {Q_UNUSED( parent ) return 0;}
 | 
			
		||||
 | 
			
		||||
    QgsAuthMethod::Expansions supportedExpansions() const;
 | 
			
		||||
%Docstring
 | 
			
		||||
Flags that represent the update points (where authentication configurations are expanded)
 | 
			
		||||
 | 
			
		||||
@ -2032,6 +2032,19 @@ if (FORCE_STATIC_LIBS)
 | 
			
		||||
    provider_wms_a
 | 
			
		||||
    provider_postgres_a
 | 
			
		||||
  )
 | 
			
		||||
 | 
			
		||||
  if (WITH_AUTH)
 | 
			
		||||
    target_link_libraries(qgis_core
 | 
			
		||||
      authmethod_basic_a
 | 
			
		||||
      authmethod_esritoken_a
 | 
			
		||||
      authmethod_identcert_a
 | 
			
		||||
      authmethod_pkipaths_a
 | 
			
		||||
      authmethod_pkcs12_a
 | 
			
		||||
    )
 | 
			
		||||
    if(WITH_OAUTH2_PLUGIN)
 | 
			
		||||
      target_link_libraries(qgis_core authmethod_oauth2_a)
 | 
			
		||||
    endif()
 | 
			
		||||
  endif()
 | 
			
		||||
endif()
 | 
			
		||||
 | 
			
		||||
if (MSVC)
 | 
			
		||||
 | 
			
		||||
@ -842,7 +842,7 @@ bool QgsAuthManager::registerCoreAuthMethods()
 | 
			
		||||
  const QStringList methods = QgsAuthMethodRegistry::instance()->authMethodList();
 | 
			
		||||
  for ( const auto &authMethodKey : methods )
 | 
			
		||||
  {
 | 
			
		||||
    mAuthMethods.insert( authMethodKey, QgsAuthMethodRegistry::instance()->authMethod( authMethodKey ).release() );
 | 
			
		||||
    mAuthMethods.insert( authMethodKey, QgsAuthMethodRegistry::instance()->createAuthMethod( authMethodKey ) );
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  return !mAuthMethods.isEmpty();
 | 
			
		||||
@ -1036,6 +1036,18 @@ QgsAuthMethod *QgsAuthManager::authMethod( const QString &authMethodKey )
 | 
			
		||||
  return mAuthMethods.value( authMethodKey );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const QgsAuthMethodMetadata *QgsAuthManager::authMethodMetadata( const QString &authMethodKey )
 | 
			
		||||
{
 | 
			
		||||
  if ( !mAuthMethods.contains( authMethodKey ) )
 | 
			
		||||
  {
 | 
			
		||||
    QgsDebugMsg( QStringLiteral( "No auth method registered for auth method key: %1" ).arg( authMethodKey ) );
 | 
			
		||||
    return nullptr;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  return QgsAuthMethodRegistry::instance()->authMethodMetadata( authMethodKey );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
QgsAuthMethodsMap QgsAuthManager::authMethodsMap( const QString &dataprovider )
 | 
			
		||||
{
 | 
			
		||||
  if ( dataprovider.isEmpty() )
 | 
			
		||||
@ -1058,10 +1070,16 @@ QgsAuthMethodsMap QgsAuthManager::authMethodsMap( const QString &dataprovider )
 | 
			
		||||
  return filteredmap;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#ifdef HAVE_GUI
 | 
			
		||||
QWidget *QgsAuthManager::authMethodEditWidget( const QString &authMethodKey, QWidget *parent )
 | 
			
		||||
{
 | 
			
		||||
  return QgsAuthMethodRegistry::instance()->editWidget( authMethodKey, parent );
 | 
			
		||||
  QgsAuthMethod *method = authMethod( authMethodKey );
 | 
			
		||||
  if ( method )
 | 
			
		||||
    return method->editWidget( parent );
 | 
			
		||||
  else
 | 
			
		||||
    return nullptr;
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
QgsAuthMethod::Expansions QgsAuthManager::supportedAuthMethodExpansions( const QString &authcfg )
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
@ -54,6 +54,7 @@ namespace QCA
 | 
			
		||||
class QgsAuthMethod;
 | 
			
		||||
class QgsAuthMethodEdit;
 | 
			
		||||
class QgsAuthProvider;
 | 
			
		||||
class QgsAuthMethodMetadata;
 | 
			
		||||
class QTimer;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -229,6 +230,13 @@ class CORE_EXPORT QgsAuthManager : public QObject
 | 
			
		||||
     */
 | 
			
		||||
    QgsAuthMethod *authMethod( const QString &authMethodKey );
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Gets authentication method metadata via its key
 | 
			
		||||
     * \param authMethodKey Authentication method key
 | 
			
		||||
     * \since QGIS 3.22
 | 
			
		||||
     */
 | 
			
		||||
    const QgsAuthMethodMetadata *authMethodMetadata( const QString &authMethodKey );
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Gets available authentication methods mapped to their key
 | 
			
		||||
     * \param dataprovider Provider key filter, returning only methods that support a particular provider
 | 
			
		||||
@ -236,12 +244,15 @@ class CORE_EXPORT QgsAuthManager : public QObject
 | 
			
		||||
     */
 | 
			
		||||
    QgsAuthMethodsMap authMethodsMap( const QString &dataprovider = QString() ) SIP_SKIP;
 | 
			
		||||
 | 
			
		||||
#ifdef HAVE_GUI
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Gets authentication method edit widget via its key
 | 
			
		||||
     * \param authMethodKey Authentication method key
 | 
			
		||||
     * \param parent Parent widget
 | 
			
		||||
     */
 | 
			
		||||
    QWidget *authMethodEditWidget( const QString &authMethodKey, QWidget *parent );
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Gets supported authentication method expansion(s), e.g. NetworkRequest | DataSourceURI, as flags
 | 
			
		||||
 | 
			
		||||
@ -29,6 +29,8 @@
 | 
			
		||||
#include <QRecursiveMutex>
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#include "qgsconfig.h"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#include "qgis_core.h"
 | 
			
		||||
 | 
			
		||||
@ -64,18 +66,14 @@ class CORE_EXPORT QgsAuthMethod : public QObject
 | 
			
		||||
    };
 | 
			
		||||
    Q_DECLARE_FLAGS( Expansions, Expansion )
 | 
			
		||||
 | 
			
		||||
    //! A non-translated short name representing the auth method
 | 
			
		||||
    virtual QString key() const = 0;
 | 
			
		||||
 | 
			
		||||
    //! A non-translated short description representing the auth method for use in debug output and About dialog
 | 
			
		||||
    virtual QString description() const = 0;
 | 
			
		||||
 | 
			
		||||
    //! Translatable display version of the 'description()'
 | 
			
		||||
    virtual QString displayDescription() const = 0;
 | 
			
		||||
 | 
			
		||||
    //! Increment this if method is significantly updated, allow updater code to be written for previously stored authcfg
 | 
			
		||||
    int version() const { return mVersion; }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#ifdef HAVE_GUI
 | 
			
		||||
    virtual QWidget *editWidget( QWidget *parent ) const {Q_UNUSED( parent ) return nullptr;}
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Flags that represent the update points (where authentication configurations are expanded)
 | 
			
		||||
     * supported by an authentication method.
 | 
			
		||||
 | 
			
		||||
@ -14,30 +14,31 @@
 | 
			
		||||
 *                                                                         *
 | 
			
		||||
 ***************************************************************************/
 | 
			
		||||
 | 
			
		||||
#include <QStringList>
 | 
			
		||||
 | 
			
		||||
#include "qgsauthmethodmetadata.h"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
QgsAuthMethodMetadata::QgsAuthMethodMetadata( QString const &_key,
 | 
			
		||||
    QString const &_description,
 | 
			
		||||
    QString const &_library )
 | 
			
		||||
  : key_( _key )
 | 
			
		||||
  , description_( _description )
 | 
			
		||||
  , library_( _library )
 | 
			
		||||
{}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
QString QgsAuthMethodMetadata::key() const
 | 
			
		||||
{
 | 
			
		||||
  return key_;
 | 
			
		||||
  return mKey;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QString QgsAuthMethodMetadata::description() const
 | 
			
		||||
{
 | 
			
		||||
  return description_;
 | 
			
		||||
  return mDescription;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QString QgsAuthMethodMetadata::library() const
 | 
			
		||||
{
 | 
			
		||||
  return library_;
 | 
			
		||||
  return mLibrary;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QgsAuthMethod *QgsAuthMethodMetadata::createAuthMethod() const
 | 
			
		||||
{
 | 
			
		||||
  return nullptr;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -22,6 +22,9 @@
 | 
			
		||||
#include <QString>
 | 
			
		||||
 | 
			
		||||
#include "qgis_core.h"
 | 
			
		||||
#include "qgis_sip.h"
 | 
			
		||||
 | 
			
		||||
class QgsAuthMethod;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * \ingroup core
 | 
			
		||||
@ -45,9 +48,16 @@ class CORE_EXPORT QgsAuthMethodMetadata
 | 
			
		||||
     * Construct an authentication method metadata container
 | 
			
		||||
     * \param _key Textual key of the library plugin
 | 
			
		||||
     * \param _description Description of the library plugin
 | 
			
		||||
     * \param _library File name of library plugin
 | 
			
		||||
     * \param _library File name of library plugin (empty if the provider is not loaded from a library)
 | 
			
		||||
 | 
			
		||||
     */
 | 
			
		||||
    QgsAuthMethodMetadata( const QString &_key, const QString &_description, const QString &_library );
 | 
			
		||||
    QgsAuthMethodMetadata( const QString &key, const QString &description, const QString &library = QString() )
 | 
			
		||||
      : mKey( key )
 | 
			
		||||
      , mDescription( description )
 | 
			
		||||
      , mLibrary( library )
 | 
			
		||||
    {}
 | 
			
		||||
 | 
			
		||||
    virtual ~QgsAuthMethodMetadata() = default;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Returns the unique key associated with the method
 | 
			
		||||
@ -70,16 +80,24 @@ class CORE_EXPORT QgsAuthMethodMetadata
 | 
			
		||||
     */
 | 
			
		||||
    QString library() const;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Class factory to return a pointer to a newly created QgsDataProvider object
 | 
			
		||||
     * \since QGIS 3.22
 | 
			
		||||
     */
 | 
			
		||||
    virtual QgsAuthMethod *createAuthMethod() const SIP_FACTORY; // TODO QGIS 4 = 0
 | 
			
		||||
 | 
			
		||||
    //virtual QStringList supportedDataProviders() const; // TODO QGIS 4 = 0;
 | 
			
		||||
 | 
			
		||||
  private:
 | 
			
		||||
 | 
			
		||||
    /// unique key for method
 | 
			
		||||
    QString key_;
 | 
			
		||||
    QString mKey;
 | 
			
		||||
 | 
			
		||||
    /// associated terse description
 | 
			
		||||
    QString description_;
 | 
			
		||||
    QString mDescription;
 | 
			
		||||
 | 
			
		||||
    /// file path
 | 
			
		||||
    QString library_;
 | 
			
		||||
    QString mLibrary;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif // QGSAUTHMETHODMETADATA_H
 | 
			
		||||
 | 
			
		||||
@ -28,16 +28,32 @@
 | 
			
		||||
#include "qgsmessagelog.h"
 | 
			
		||||
#include "qgsauthmethodmetadata.h"
 | 
			
		||||
 | 
			
		||||
#ifdef HAVE_STATIC_PROVIDERS
 | 
			
		||||
#include "qgsauthbasicmethod.h"
 | 
			
		||||
#include "qgsauthesritokenmethod.h"
 | 
			
		||||
#include "qgsauthidentcertmethod.h"
 | 
			
		||||
#ifdef HAVE_OAUTH2_PLUGIN
 | 
			
		||||
#include "qgsauthoauth2method.h"
 | 
			
		||||
#endif
 | 
			
		||||
#include "qgsauthpkipathsmethod.h"
 | 
			
		||||
#include "qgsauthpkcs12method.h"
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
// typedefs for auth method plugin functions of interest
 | 
			
		||||
typedef QString methodkey_t();
 | 
			
		||||
typedef QString description_t();
 | 
			
		||||
typedef bool    isauthmethod_t();
 | 
			
		||||
 | 
			
		||||
static QgsAuthMethodRegistry *sInstance = nullptr;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
QgsAuthMethodRegistry *QgsAuthMethodRegistry::instance( const QString &pluginPath )
 | 
			
		||||
{
 | 
			
		||||
  static QgsAuthMethodRegistry *sInstance( new QgsAuthMethodRegistry( pluginPath ) );
 | 
			
		||||
  if ( !sInstance )
 | 
			
		||||
  {
 | 
			
		||||
    static QMutex sMutex;
 | 
			
		||||
    QMutexLocker locker( &sMutex );
 | 
			
		||||
    if ( !sInstance )
 | 
			
		||||
    {
 | 
			
		||||
      sInstance = new QgsAuthMethodRegistry( pluginPath );
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  return sInstance;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -57,6 +73,23 @@ QgsAuthMethodRegistry::QgsAuthMethodRegistry( const QString &pluginPath )
 | 
			
		||||
  mLibraryDirectory.setSorting( QDir::Name | QDir::IgnoreCase );
 | 
			
		||||
  mLibraryDirectory.setFilter( QDir::Files | QDir::NoSymLinks );
 | 
			
		||||
 | 
			
		||||
  init();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void QgsAuthMethodRegistry::init()
 | 
			
		||||
{
 | 
			
		||||
#ifdef HAVE_STATIC_PROVIDERS
 | 
			
		||||
  mAuthMethods[ QgsAuthBasicMethod::AUTH_METHOD_KEY] = new QgsAuthBasicMethodMetadata();
 | 
			
		||||
  mAuthMethods[ QgsAuthEsriTokenMethod::AUTH_METHOD_KEY] = new QgsAuthBasicMethodMetadata();
 | 
			
		||||
  mAuthMethods[ QgsAuthIdentCertMethod::AUTH_METHOD_KEY] = new QgsAuthBasicMethodMetadata();
 | 
			
		||||
#ifdef HAVE_OAUTH2_PLUGIN
 | 
			
		||||
  mAuthMethods[ QgsAuthOAuth2Method::AUTH_METHOD_KEY] = new QgsAuthBasicMethodMetadata();
 | 
			
		||||
#endif
 | 
			
		||||
  mAuthMethods[ QgsAuthPkiPathsMethod::AUTH_METHOD_KEY] = new QgsAuthBasicMethodMetadata();
 | 
			
		||||
  mAuthMethods[ QgsAuthPkcs12Method::AUTH_METHOD_KEY] = new QgsAuthBasicMethodMetadata();
 | 
			
		||||
#else
 | 
			
		||||
  typedef QgsAuthMethodMetadata *factory_function( );
 | 
			
		||||
 | 
			
		||||
#if defined(Q_OS_WIN) || defined(__CYGWIN__)
 | 
			
		||||
  mLibraryDirectory.setNameFilters( QStringList( "authmethod_*.dll" ) );
 | 
			
		||||
#else
 | 
			
		||||
@ -105,46 +138,44 @@ QgsAuthMethodRegistry::QgsAuthMethodRegistry( const QString &pluginPath )
 | 
			
		||||
      continue;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // get the description and the key for the auth method plugin
 | 
			
		||||
    isauthmethod_t *isAuthMethod = reinterpret_cast< isauthmethod_t * >( cast_to_fptr( myLib.resolve( "isAuthMethod" ) ) );
 | 
			
		||||
    if ( !isAuthMethod )
 | 
			
		||||
    bool libraryLoaded { false };
 | 
			
		||||
    QFunctionPointer func = myLib.resolve( QStringLiteral( "authMethodMetadataFactory" ).toLatin1().data() );
 | 
			
		||||
    factory_function *function = reinterpret_cast< factory_function * >( cast_to_fptr( func ) );
 | 
			
		||||
    if ( function )
 | 
			
		||||
    {
 | 
			
		||||
      QgsDebugMsg( QStringLiteral( "Checking %1: ...invalid (no isAuthMethod method)" ).arg( myLib.fileName() ) );
 | 
			
		||||
      continue;
 | 
			
		||||
      QgsAuthMethodMetadata *meta = function();
 | 
			
		||||
      if ( meta )
 | 
			
		||||
      {
 | 
			
		||||
        if ( findMetadata_( mAuthMethods, meta->key() ) )
 | 
			
		||||
        {
 | 
			
		||||
          QgsDebugMsg( QStringLiteral( "Checking %1: ...invalid (key %2 already registered)" ).arg( myLib.fileName() ).arg( meta->key() ) );
 | 
			
		||||
          delete meta;
 | 
			
		||||
          continue;
 | 
			
		||||
        }
 | 
			
		||||
        // add this method to the map
 | 
			
		||||
        mAuthMethods[meta->key()] = meta;
 | 
			
		||||
        libraryLoaded = true;
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // check to see if this is an auth method plugin
 | 
			
		||||
    if ( !isAuthMethod() )
 | 
			
		||||
    if ( ! libraryLoaded )
 | 
			
		||||
    {
 | 
			
		||||
      QgsDebugMsg( QStringLiteral( "Checking %1: ...invalid (not an auth method)" ).arg( myLib.fileName() ) );
 | 
			
		||||
      continue;
 | 
			
		||||
      QgsDebugMsgLevel( QStringLiteral( "Checking %1: ...invalid (no authMethodMetadataFactory method)" ).arg( myLib.fileName() ), 2 );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // looks like an auth method plugin. get the key and description
 | 
			
		||||
    description_t *pDesc = reinterpret_cast< description_t * >( cast_to_fptr( myLib.resolve( "description" ) ) );
 | 
			
		||||
    if ( !pDesc )
 | 
			
		||||
    {
 | 
			
		||||
      QgsDebugMsg( QStringLiteral( "Checking %1: ...invalid (no description method)" ).arg( myLib.fileName() ) );
 | 
			
		||||
      continue;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    methodkey_t *pKey = reinterpret_cast< methodkey_t * >( cast_to_fptr( myLib.resolve( "authMethodKey" ) ) );
 | 
			
		||||
    if ( !pKey )
 | 
			
		||||
    {
 | 
			
		||||
      QgsDebugMsg( QStringLiteral( "Checking %1: ...invalid (no authMethodKey method)" ).arg( myLib.fileName() ) );
 | 
			
		||||
      continue;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // add this auth method to the method map
 | 
			
		||||
    mAuthMethods[pKey()] = new QgsAuthMethodMetadata( pKey(), pDesc(), myLib.fileName() );
 | 
			
		||||
 | 
			
		||||
  }
 | 
			
		||||
#endif
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// typedef for the unload auth method function
 | 
			
		||||
typedef void cleanupAuthMethod_t();
 | 
			
		||||
 | 
			
		||||
QgsAuthMethodRegistry::~QgsAuthMethodRegistry()
 | 
			
		||||
{
 | 
			
		||||
  clean();
 | 
			
		||||
  if ( sInstance == this )
 | 
			
		||||
    sInstance = nullptr;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
void QgsAuthMethodRegistry::clean()
 | 
			
		||||
{
 | 
			
		||||
  AuthMethods::const_iterator it = mAuthMethods.begin();
 | 
			
		||||
 | 
			
		||||
@ -195,7 +226,9 @@ QString QgsAuthMethodRegistry::library( const QString &authMethodKey ) const
 | 
			
		||||
 | 
			
		||||
  if ( md )
 | 
			
		||||
  {
 | 
			
		||||
    Q_NOWARN_DEPRECATED_PUSH
 | 
			
		||||
    return md->library();
 | 
			
		||||
    Q_NOWARN_DEPRECATED_POP
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  return QString();
 | 
			
		||||
@ -257,103 +290,69 @@ void QgsAuthMethodRegistry::setLibraryDirectory( const QDir &path )
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
// typedef for the QgsDataProvider class factory
 | 
			
		||||
// typedef for the QgsAuthMethod class factory
 | 
			
		||||
typedef QgsAuthMethod *classFactoryFunction_t();
 | 
			
		||||
 | 
			
		||||
std::unique_ptr<QgsAuthMethod> QgsAuthMethodRegistry::authMethod( const QString &authMethodKey )
 | 
			
		||||
const QgsAuthMethodMetadata *QgsAuthMethodRegistry::authMethodMetadata( const QString &authMethodKey ) const
 | 
			
		||||
{
 | 
			
		||||
  // load the plugin
 | 
			
		||||
  QString lib = library( authMethodKey );
 | 
			
		||||
 | 
			
		||||
#ifdef TESTAUTHMETHODLIB
 | 
			
		||||
  const char *cLib = lib.toUtf8();
 | 
			
		||||
 | 
			
		||||
  // test code to help debug auth method plugin loading problems
 | 
			
		||||
  //  void *handle = dlopen(cLib, RTLD_LAZY);
 | 
			
		||||
  void *handle = dlopen( cOgrLib, RTLD_LAZY | RTLD_GLOBAL );
 | 
			
		||||
  if ( !handle )
 | 
			
		||||
  {
 | 
			
		||||
    QgsLogger::warning( "Error in dlopen" );
 | 
			
		||||
  }
 | 
			
		||||
  else
 | 
			
		||||
  {
 | 
			
		||||
    QgsDebugMsg( QStringLiteral( "dlopen succeeded" ) );
 | 
			
		||||
    dlclose( handle );
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
  // load the auth method
 | 
			
		||||
  QLibrary myLib( lib );
 | 
			
		||||
 | 
			
		||||
  QgsDebugMsgLevel( "Auth method library name is " + myLib.fileName(), 2 );
 | 
			
		||||
  if ( !myLib.load() )
 | 
			
		||||
  {
 | 
			
		||||
    QgsMessageLog::logMessage( QObject::tr( "Failed to load %1: %2" ).arg( lib, myLib.errorString() ) );
 | 
			
		||||
    return nullptr;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  classFactoryFunction_t *classFactory = reinterpret_cast< classFactoryFunction_t * >( cast_to_fptr( myLib.resolve( "classFactory" ) ) );
 | 
			
		||||
  if ( !classFactory )
 | 
			
		||||
  {
 | 
			
		||||
    QgsDebugMsg( QStringLiteral( "Failed to load %1: no classFactory method" ).arg( lib ) );
 | 
			
		||||
    return nullptr;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  std::unique_ptr< QgsAuthMethod > authMethod( classFactory() );
 | 
			
		||||
  if ( !authMethod )
 | 
			
		||||
  {
 | 
			
		||||
    QgsMessageLog::logMessage( QObject::tr( "Unable to instantiate the auth method plugin %1" ).arg( lib ) );
 | 
			
		||||
    myLib.unload();
 | 
			
		||||
    return nullptr;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  QgsDebugMsgLevel( QStringLiteral( "Instantiated the auth method plugin: %1" ).arg( authMethod->key() ), 2 );
 | 
			
		||||
  return authMethod;
 | 
			
		||||
  return findMetadata_( mAuthMethods, authMethodKey );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
typedef QWidget *editFactoryFunction_t( QWidget *parent );
 | 
			
		||||
 | 
			
		||||
QWidget *QgsAuthMethodRegistry::editWidget( const QString &authMethodKey, QWidget *parent )
 | 
			
		||||
QgsAuthMethod *QgsAuthMethodRegistry::createAuthMethod( const QString &authMethodKey )
 | 
			
		||||
{
 | 
			
		||||
  editFactoryFunction_t *editFactory =
 | 
			
		||||
    reinterpret_cast< editFactoryFunction_t * >( cast_to_fptr( function( authMethodKey, QStringLiteral( "editWidget" ) ) ) );
 | 
			
		||||
 | 
			
		||||
  if ( !editFactory )
 | 
			
		||||
    return nullptr;
 | 
			
		||||
 | 
			
		||||
  return editFactory( parent );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QFunctionPointer QgsAuthMethodRegistry::function( QString const &authMethodKey,
 | 
			
		||||
    QString const &functionName )
 | 
			
		||||
{
 | 
			
		||||
  QLibrary myLib( library( authMethodKey ) );
 | 
			
		||||
 | 
			
		||||
  QgsDebugMsgLevel( "Library name is " + myLib.fileName(), 2 );
 | 
			
		||||
 | 
			
		||||
  if ( myLib.load() )
 | 
			
		||||
  QgsAuthMethodMetadata *metadata = findMetadata_( mAuthMethods, authMethodKey );
 | 
			
		||||
  if ( !metadata )
 | 
			
		||||
  {
 | 
			
		||||
    return myLib.resolve( functionName.toLatin1().data() );
 | 
			
		||||
  }
 | 
			
		||||
  else
 | 
			
		||||
  {
 | 
			
		||||
    QgsDebugMsg( "Cannot load library: " + myLib.errorString() );
 | 
			
		||||
    QgsMessageLog::logMessage( QObject::tr( "Invalid auth method %1" ).arg( authMethodKey ) );
 | 
			
		||||
    return nullptr;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  return metadata->createAuthMethod();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
std::unique_ptr<QLibrary> QgsAuthMethodRegistry::authMethodLibrary( const QString &authMethodKey ) const
 | 
			
		||||
{
 | 
			
		||||
  std::unique_ptr< QLibrary > myLib( new QLibrary( library( authMethodKey ) ) );
 | 
			
		||||
//typedef QWidget *editFactoryFunction_t( QWidget *parent );
 | 
			
		||||
 | 
			
		||||
  QgsDebugMsgLevel( "Library name is " + myLib->fileName(), 2 );
 | 
			
		||||
//QWidget *QgsAuthMethodRegistry::editWidget( const QString &authMethodKey, QWidget *parent )
 | 
			
		||||
//{
 | 
			
		||||
//  editFactoryFunction_t *editFactory =
 | 
			
		||||
//    reinterpret_cast< editFactoryFunction_t * >( cast_to_fptr( function( authMethodKey, QStringLiteral( "editWidget" ) ) ) );
 | 
			
		||||
 | 
			
		||||
  if ( myLib->load() )
 | 
			
		||||
    return myLib;
 | 
			
		||||
//  if ( !editFactory )
 | 
			
		||||
//    return nullptr;
 | 
			
		||||
 | 
			
		||||
  QgsDebugMsg( "Cannot load library: " + myLib->errorString() );
 | 
			
		||||
  return nullptr;
 | 
			
		||||
}
 | 
			
		||||
//  return editFactory( parent );
 | 
			
		||||
//}
 | 
			
		||||
 | 
			
		||||
//QFunctionPointer QgsAuthMethodRegistry::function( QString const &authMethodKey,
 | 
			
		||||
//    QString const &functionName )
 | 
			
		||||
//{
 | 
			
		||||
//  QLibrary myLib( library( authMethodKey ) );
 | 
			
		||||
 | 
			
		||||
//  QgsDebugMsgLevel( "Library name is " + myLib.fileName(), 2 );
 | 
			
		||||
 | 
			
		||||
//  if ( myLib.load() )
 | 
			
		||||
//  {
 | 
			
		||||
//    return myLib.resolve( functionName.toLatin1().data() );
 | 
			
		||||
//  }
 | 
			
		||||
//  else
 | 
			
		||||
//  {
 | 
			
		||||
//    QgsDebugMsg( "Cannot load library: " + myLib.errorString() );
 | 
			
		||||
//    return nullptr;
 | 
			
		||||
//  }
 | 
			
		||||
//}
 | 
			
		||||
 | 
			
		||||
//std::unique_ptr<QLibrary> QgsAuthMethodRegistry::authMethodLibrary( const QString &authMethodKey ) const
 | 
			
		||||
//{
 | 
			
		||||
//  std::unique_ptr< QLibrary > myLib( new QLibrary( library( authMethodKey ) ) );
 | 
			
		||||
 | 
			
		||||
//  QgsDebugMsgLevel( "Library name is " + myLib->fileName(), 2 );
 | 
			
		||||
 | 
			
		||||
//  if ( myLib->load() )
 | 
			
		||||
//    return myLib;
 | 
			
		||||
 | 
			
		||||
//  QgsDebugMsg( "Cannot load library: " + myLib->errorString() );
 | 
			
		||||
//  return nullptr;
 | 
			
		||||
//}
 | 
			
		||||
 | 
			
		||||
QStringList QgsAuthMethodRegistry::authMethodList() const
 | 
			
		||||
{
 | 
			
		||||
@ -365,7 +364,4 @@ QStringList QgsAuthMethodRegistry::authMethodList() const
 | 
			
		||||
  return lst;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const QgsAuthMethodMetadata *QgsAuthMethodRegistry::authMethodMetadata( const QString &authMethodKey ) const
 | 
			
		||||
{
 | 
			
		||||
  return findMetadata_( mAuthMethods, authMethodKey );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -26,6 +26,7 @@
 | 
			
		||||
#include <memory>
 | 
			
		||||
 | 
			
		||||
#include "qgis_core.h"
 | 
			
		||||
#include "qgis_sip.h"
 | 
			
		||||
 | 
			
		||||
class QgsAuthMethod;
 | 
			
		||||
class QgsAuthMethodMetadata;
 | 
			
		||||
@ -53,8 +54,11 @@ class CORE_EXPORT QgsAuthMethodRegistry
 | 
			
		||||
    //! Virtual dectructor
 | 
			
		||||
    virtual ~QgsAuthMethodRegistry();
 | 
			
		||||
 | 
			
		||||
    //! Returns path for the library of the auth method
 | 
			
		||||
    QString library( const QString &authMethodKey ) const;
 | 
			
		||||
    /*
 | 
			
		||||
     * Returns path for the library of the auth method
 | 
			
		||||
    * \deprecated since QGIS 3.22 - methods may not need to be loaded from a library (empty string returned)
 | 
			
		||||
    */
 | 
			
		||||
    Q_DECL_DEPRECATED QString library( const QString &authMethodKey ) const SIP_DEPRECATED;
 | 
			
		||||
 | 
			
		||||
    //! Returns list of auth method plugins found
 | 
			
		||||
    QString pluginList( bool asHtml = false ) const;
 | 
			
		||||
@ -70,7 +74,7 @@ class CORE_EXPORT QgsAuthMethodRegistry
 | 
			
		||||
     * \param authMethodKey identificator of the auth method
 | 
			
		||||
     * \returns instance of auth method or nullptr on error
 | 
			
		||||
     */
 | 
			
		||||
    std::unique_ptr< QgsAuthMethod > authMethod( const QString &authMethodKey );
 | 
			
		||||
    QgsAuthMethod *createAuthMethod( const QString &authMethodKey );
 | 
			
		||||
 | 
			
		||||
#if 0
 | 
			
		||||
 | 
			
		||||
@ -88,17 +92,17 @@ class CORE_EXPORT QgsAuthMethodRegistry
 | 
			
		||||
     */
 | 
			
		||||
    QWidget *editWidget( const QString &authMethodKey, QWidget *parent = nullptr );
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Gets pointer to auth method function
 | 
			
		||||
     * \param authMethodKey identificator of the auth method
 | 
			
		||||
     * \param functionName name of function
 | 
			
		||||
     * \returns pointer to function or nullptr on error
 | 
			
		||||
     */
 | 
			
		||||
    QFunctionPointer function( const QString &authMethodKey,
 | 
			
		||||
                               const QString &functionName );
 | 
			
		||||
//    /**
 | 
			
		||||
//     * Gets pointer to auth method function
 | 
			
		||||
//     * \param authMethodKey identificator of the auth method
 | 
			
		||||
//     * \param functionName name of function
 | 
			
		||||
//     * \returns pointer to function or nullptr on error
 | 
			
		||||
//     */
 | 
			
		||||
//    QFunctionPointer function( const QString &authMethodKey,
 | 
			
		||||
//                               const QString &functionName );
 | 
			
		||||
 | 
			
		||||
    //! Returns the library object associated with an auth method key
 | 
			
		||||
    std::unique_ptr< QLibrary > authMethodLibrary( const QString &authMethodKey ) const;
 | 
			
		||||
//    //! Returns the library object associated with an auth method key
 | 
			
		||||
//    std::unique_ptr< QLibrary > authMethodLibrary( const QString &authMethodKey ) const;
 | 
			
		||||
 | 
			
		||||
    //! Returns list of available auth methods by their keys
 | 
			
		||||
    QStringList authMethodList() const;
 | 
			
		||||
@ -112,9 +116,13 @@ class CORE_EXPORT QgsAuthMethodRegistry
 | 
			
		||||
    typedef std::map<QString, QgsAuthMethodMetadata *> AuthMethods;
 | 
			
		||||
 | 
			
		||||
  private:
 | 
			
		||||
 | 
			
		||||
    //! Ctor private since instance() creates it
 | 
			
		||||
    QgsAuthMethodRegistry( const QString &pluginPath );
 | 
			
		||||
 | 
			
		||||
    void init();
 | 
			
		||||
    void clean();
 | 
			
		||||
 | 
			
		||||
    //! Associative container of auth method metadata handles
 | 
			
		||||
    AuthMethods mAuthMethods;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -1496,6 +1496,11 @@ target_link_libraries(qgis_gui
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
if (FORCE_STATIC_LIBS)
 | 
			
		||||
  include_directories(
 | 
			
		||||
    ${CMAKE_SOURCE_DIR}/src/providers/wms
 | 
			
		||||
    ${CMAKE_SOURCE_DIR}/src/providers/postgres
 | 
			
		||||
  )
 | 
			
		||||
 | 
			
		||||
  target_link_libraries(qgis_gui
 | 
			
		||||
    provider_wms_gui_a
 | 
			
		||||
    provider_postgres_gui_a
 | 
			
		||||
 | 
			
		||||
@ -18,6 +18,7 @@
 | 
			
		||||
 | 
			
		||||
#include <QPushButton>
 | 
			
		||||
 | 
			
		||||
#include "qgsauthmethodmetadata.h"
 | 
			
		||||
#include "qgsauthconfig.h"
 | 
			
		||||
#include "qgsauthconfigidedit.h"
 | 
			
		||||
#include "qgsauthmanager.h"
 | 
			
		||||
@ -101,20 +102,20 @@ void QgsAuthConfigEdit::populateAuthMethods()
 | 
			
		||||
  QStringList authMethodKeys = QgsApplication::authManager()->authMethodsKeys( mDataProvider );
 | 
			
		||||
 | 
			
		||||
  // sort by auth method description attribute, then populate
 | 
			
		||||
  QMap<QString, QgsAuthMethod *> descmap;
 | 
			
		||||
  QMap<QString, const QgsAuthMethodMetadata *> descmap;
 | 
			
		||||
  const auto constAuthMethodKeys = authMethodKeys;
 | 
			
		||||
  for ( const QString &authMethodKey : constAuthMethodKeys )
 | 
			
		||||
  {
 | 
			
		||||
    QgsAuthMethod *authmethod = QgsApplication::authManager()->authMethod( authMethodKey );
 | 
			
		||||
    if ( !authmethod )
 | 
			
		||||
    const QgsAuthMethodMetadata *meta = QgsApplication::authManager()->authMethodMetadata( authMethodKey );
 | 
			
		||||
    if ( !meta )
 | 
			
		||||
    {
 | 
			
		||||
      QgsDebugMsg( QStringLiteral( "Load auth method instance FAILED for auth method key (%1)" ).arg( authMethodKey ) );
 | 
			
		||||
      continue;
 | 
			
		||||
    }
 | 
			
		||||
    descmap.insert( authmethod->displayDescription(), authmethod );
 | 
			
		||||
    descmap.insert( meta->description(), meta );
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  QMap<QString, QgsAuthMethod *>::iterator it = descmap.begin();
 | 
			
		||||
  QMap<QString, const QgsAuthMethodMetadata *>::iterator it = descmap.begin();
 | 
			
		||||
  for ( it = descmap.begin(); it != descmap.end(); ++it )
 | 
			
		||||
  {
 | 
			
		||||
    QgsAuthMethodEdit *editWidget = qobject_cast<QgsAuthMethodEdit *>(
 | 
			
		||||
 | 
			
		||||
@ -27,6 +27,7 @@
 | 
			
		||||
#include "qgsauthconfigedit.h"
 | 
			
		||||
#include "qgslogger.h"
 | 
			
		||||
#include "qgsapplication.h"
 | 
			
		||||
#include "qgsauthmethodmetadata.h"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
QgsAuthConfigSelect::QgsAuthConfigSelect( QWidget *parent, const QString &dataprovider )
 | 
			
		||||
@ -109,11 +110,12 @@ void QgsAuthConfigSelect::loadConfig()
 | 
			
		||||
  if ( !mAuthCfg.isEmpty() && mConfigs.contains( mAuthCfg ) )
 | 
			
		||||
  {
 | 
			
		||||
    QgsAuthMethodConfig config = mConfigs.value( mAuthCfg );
 | 
			
		||||
    QgsAuthMethod *authmethod = QgsApplication::authManager()->configAuthMethod( mAuthCfg );
 | 
			
		||||
    QString authMethodKey = QgsApplication::authManager()->configAuthMethodKey( mAuthCfg );
 | 
			
		||||
    QString methoddesc = tr( "Missing authentication method description" );
 | 
			
		||||
    if ( authmethod )
 | 
			
		||||
    const QgsAuthMethodMetadata *meta = QgsApplication::authManager()->authMethodMetadata( authMethodKey );
 | 
			
		||||
    if ( meta )
 | 
			
		||||
    {
 | 
			
		||||
      methoddesc = authmethod->description();
 | 
			
		||||
      methoddesc = meta->description();
 | 
			
		||||
    }
 | 
			
		||||
    cmbConfigSelect->setToolTip( tr( "<ul><li><b>Method type:</b> %1</li>"
 | 
			
		||||
                                     "<li><b>Configuration ID:</b> %2</li></ul>" ).arg( methoddesc, config.id( ) ) );
 | 
			
		||||
 | 
			
		||||
@ -28,6 +28,7 @@
 | 
			
		||||
#include "qgsauthmanager.h"
 | 
			
		||||
#include "qgsapplication.h"
 | 
			
		||||
#include "qgsnetworkaccessmanager.h"
 | 
			
		||||
#include "qgsauthmethodmetadata.h"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
QgsAuthMethodPlugins::QgsAuthMethodPlugins( QWidget *parent )
 | 
			
		||||
@ -71,28 +72,33 @@ void QgsAuthMethodPlugins::setupTable()
 | 
			
		||||
 | 
			
		||||
void QgsAuthMethodPlugins::populateTable()
 | 
			
		||||
{
 | 
			
		||||
  QgsAuthMethodsMap authmethods( QgsApplication::authManager()->authMethodsMap() );
 | 
			
		||||
  QStringList authMethodKeys = QgsApplication::authManager()->authMethodsKeys();
 | 
			
		||||
 | 
			
		||||
  int i = 0;
 | 
			
		||||
  for ( QgsAuthMethodsMap::const_iterator it = authmethods.constBegin(); it != authmethods.constEnd(); ++it, i++ )
 | 
			
		||||
  const auto constAuthMethodKeys = authMethodKeys;
 | 
			
		||||
  for ( const QString &authMethodKey : constAuthMethodKeys )
 | 
			
		||||
  {
 | 
			
		||||
    QgsAuthMethod *authmethod( it.value() );
 | 
			
		||||
    if ( !authmethod )
 | 
			
		||||
    const QgsAuthMethodMetadata *meta = QgsApplication::authManager()->authMethodMetadata( authMethodKey );
 | 
			
		||||
    const QgsAuthMethod *method = QgsApplication::authManager()->authMethod( authMethodKey );
 | 
			
		||||
    if ( !meta || !method )
 | 
			
		||||
    {
 | 
			
		||||
      QgsDebugMsg( QStringLiteral( "Load auth method instance FAILED for auth method key (%1)" ).arg( authMethodKey ) );
 | 
			
		||||
      continue;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    QTableWidgetItem *twi = new QTableWidgetItem( authmethod->key() );
 | 
			
		||||
    QTableWidgetItem *twi = new QTableWidgetItem( meta->key() );
 | 
			
		||||
    twi->setFlags( twi->flags() & ~Qt::ItemIsEditable );
 | 
			
		||||
    tblAuthPlugins->setItem( i, 0, twi );
 | 
			
		||||
 | 
			
		||||
    twi = new QTableWidgetItem( authmethod->displayDescription() );
 | 
			
		||||
    twi = new QTableWidgetItem( meta->description() );
 | 
			
		||||
    twi->setFlags( twi->flags() & ~Qt::ItemIsEditable );
 | 
			
		||||
    tblAuthPlugins->setItem( i, 1, twi );
 | 
			
		||||
 | 
			
		||||
    twi = new QTableWidgetItem( authmethod->supportedDataProviders().join( QLatin1String( ", " ) ) );
 | 
			
		||||
    twi = new QTableWidgetItem( method->supportedDataProviders().join( QLatin1String( ", " ) ) );
 | 
			
		||||
    twi->setFlags( twi->flags() & ~Qt::ItemIsEditable );
 | 
			
		||||
    tblAuthPlugins->setItem( i, 2, twi );
 | 
			
		||||
 | 
			
		||||
    i++;
 | 
			
		||||
  }
 | 
			
		||||
  tblAuthPlugins->sortItems( 0 );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user