Skip to content
Permalink
Browse files
allow to build auth methods statically
  • Loading branch information
3nids committed Jun 23, 2021
1 parent 6995cfd commit a42df3b856754d325e5e66c38e4406a2565222a4
@@ -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,19 +230,29 @@ 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
* \note not available in Python bindings
*/
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

0 comments on commit a42df3b

Please sign in to comment.