Skip to content

Commit

Permalink
allow to build auth methods statically (#43866)
Browse files Browse the repository at this point in the history
* allow to build auth methods statically

* enable static build of all auth methods

* follow-up

* fix static auths

* fix dynamic

* fix bindings

* fix core only

* fix dox

* fix dox again

* fix bindings again

* fix test and more

* some cleanup

* fix test

* add missing gui edits

* O2_DLL

* fix bindings with core only

* fix SIP feature

* fix SIP condition

* disable feature earlier

* fix auth manager bindings without gui

* put back virtual methods
  • Loading branch information
3nids committed Jun 24, 2021
2 parents cb2fb67 + 8915a07 commit 6cdbced
Show file tree
Hide file tree
Showing 46 changed files with 781 additions and 730 deletions.
5 changes: 5 additions & 0 deletions CMakeLists.txt
Expand Up @@ -138,6 +138,11 @@ if(WITH_CORE)

set (WITH_GUI TRUE CACHE BOOL "Determines whether QGIS GUI library (and everything built on top of it) should be built")

set (WITH_OAUTH2_PLUGIN TRUE CACHE BOOL "Build OAuth2 authentication method plugin")
if(WITH_OAUTH2_PLUGIN)
set(HAVE_OAUTH2_PLUGIN TRUE)
endif()

set (WITH_AUTH TRUE CACHE BOOL "Determines whether QGIS authentication methods should be built")

set (WITH_ANALYSIS TRUE CACHE BOOL "Determines whether QGIS analysis library should be built")
Expand Down
2 changes: 2 additions & 0 deletions cmake_templates/qgsconfig.h.in
Expand Up @@ -69,6 +69,8 @@

#cmakedefine HAVE_SERVER_PYTHON_PLUGINS

#cmakedefine HAVE_OAUTH2_PLUGIN

#cmakedefine HAVE_OPENCL
#cmakedefine OPENCL_USE_NEW_HEADER

Expand Down
4 changes: 4 additions & 0 deletions python/CMakeLists.txt
Expand Up @@ -151,6 +151,10 @@ if((${PYQT5_VERSION_STR} VERSION_EQUAL 5.15) OR (${PYQT5_VERSION_STR} VERSION_GR
set(SIP_DISABLE_FEATURES ${SIP_DISABLE_FEATURES} VECTOR_MAPPED_TYPE)
endif()

if(NOT WITH_GUI)
set(SIP_DISABLE_FEATURES ${SIP_DISABLE_FEATURES} HAVE_GUI)
endif()

GENERATE_SIP_PYTHON_MODULE_CODE(qgis._core core/core.sip "${sip_files_core}" cpp_files)
BUILD_SIP_PYTHON_MODULE(qgis._core core/core.sip ${cpp_files} "" qgis_core)
set(SIP_CORE_CPP_FILES ${cpp_files})
Expand Down
4 changes: 4 additions & 0 deletions python/core/auto_generated/auth/qgsauthmanager.sip.in
Expand Up @@ -218,12 +218,16 @@ Gets authentication method from the config/provider cache via its key
%End



%If (HAVE_GUI)

QWidget *authMethodEditWidget( const QString &authMethodKey, QWidget *parent );
%Docstring
Gets authentication method edit widget via its key

:param authMethodKey: Authentication method key
:param parent: Parent widget
%End
%End

QgsAuthMethod::Expansions supportedAuthMethodExpansions( const QString &authcfg );
Expand Down
12 changes: 11 additions & 1 deletion python/core/auto_generated/auth/qgsauthmethod.sip.in
Expand Up @@ -10,7 +10,6 @@




class QgsAuthMethod : QObject
{
%Docstring(signature="appended")
Expand Down Expand Up @@ -55,6 +54,17 @@ Translatable display version of the ':py:func:`~QgsAuthMethod.description`'
Increment this if method is significantly updated, allow updater code to be written for previously stored authcfg
%End


%If (HAVE_GUI)

virtual QWidget *editWidget( QWidget *parent ) const;
%Docstring
Constructs the configuration for the authentication method

.. versionadded:: 3.22
%End
%End

QgsAuthMethod::Expansions supportedExpansions() const;
%Docstring
Flags that represent the update points (where authentication configurations are expanded)
Expand Down
1 change: 1 addition & 0 deletions python/core/core.sip.in
Expand Up @@ -99,6 +99,7 @@ done:
%Import QtWidgets/QtWidgetsmod.sip
%Import QtPositioning/QtPositioningmod.sip

%Feature HAVE_GUI
%Feature ANDROID
%Feature VECTOR_MAPPED_TYPE

Expand Down
1 change: 0 additions & 1 deletion src/auth/CMakeLists.txt
Expand Up @@ -18,7 +18,6 @@ add_subdirectory(identcert)
add_subdirectory(pkipaths)
add_subdirectory(pkipkcs12)

set(WITH_OAUTH2_PLUGIN TRUE CACHE BOOL "Build OAuth2 authentication method plugin")
if (WITH_OAUTH2_PLUGIN)
add_subdirectory(oauth2)
endif()
58 changes: 42 additions & 16 deletions src/auth/basic/CMakeLists.txt
Expand Up @@ -10,7 +10,6 @@ set(AUTH_BASIC_UIS_H "")

if (WITH_GUI)
set(AUTH_BASIC_SRCS ${AUTH_BASIC_SRCS}
gui/qgsauthbasicmethodgui.cpp
gui/qgsauthbasicedit.cpp
)
set(AUTH_BASIC_HDRS ${AUTH_BASIC_HDRS}
Expand All @@ -20,28 +19,55 @@ if (WITH_GUI)
QT5_WRAP_UI(AUTH_BASIC_UIS_H ${AUTH_BASIC_UIS})
endif()

add_library(authmethod_basic MODULE ${AUTH_BASIC_SRCS} ${AUTH_BASIC_HDRS} ${AUTH_BASIC_UIS_H})

target_include_directories(authmethod_basic PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/core
)
# static library
add_library(authmethod_basic_a STATIC ${AUTH_BASIC_SRCS} ${AUTH_BASIC_HDRS} ${AUTH_BASIC_UIS_H})

target_include_directories(authmethod_basic_a PUBLIC ${CMAKE_SOURCE_DIR}/src/auth/basic/core)

# require c++17
target_compile_features(authmethod_basic PRIVATE cxx_std_17)
target_compile_features(authmethod_basic_a PRIVATE cxx_std_17)

target_link_libraries(authmethod_basic qgis_core)
target_link_libraries(authmethod_basic_a qgis_core)

if (WITH_GUI)
target_include_directories(authmethod_basic PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/gui
${CMAKE_CURRENT_BINARY_DIR}
target_include_directories(authmethod_basic_a PRIVATE
${CMAKE_SOURCE_DIR}/src/auth/basic/gui
${CMAKE_BINARY_DIR}/src/auth/basic
)
target_link_libraries(authmethod_basic qgis_gui)

target_link_libraries (authmethod_basic_a qgis_gui)
endif()

target_compile_definitions(authmethod_basic PRIVATE "-DQT_NO_FOREACH")
target_compile_definitions(authmethod_basic_a PRIVATE "-DQT_NO_FOREACH")

install(TARGETS authmethod_basic
RUNTIME DESTINATION ${QGIS_PLUGIN_DIR}
LIBRARY DESTINATION ${QGIS_PLUGIN_DIR}
)


if (FORCE_STATIC_LIBS)
# for (external) mobile apps to be able to pick up provider for linking
install (TARGETS authmethod_basic_a ARCHIVE DESTINATION ${QGIS_PLUGIN_DIR})
else()
# dynamically loaded module
add_library(authmethod_basic MODULE ${AUTH_BASIC_SRCS} ${AUTH_BASIC_HDRS} ${AUTH_BASIC_UIS_H})

# require c++17
target_compile_features(authmethod_basic PRIVATE cxx_std_17)

target_link_libraries(authmethod_basic qgis_core)

if (WITH_GUI)
target_include_directories(authmethod_basic PRIVATE
${CMAKE_SOURCE_DIR}/src/auth/basic/gui
${CMAKE_BINARY_DIR}/src/auth/basic
)
target_link_libraries (authmethod_basic qgis_gui)
add_dependencies(authmethod_basic ui)
endif()

target_compile_definitions(authmethod_basic PRIVATE "-DQT_NO_FOREACH")

install (TARGETS authmethod_basic
RUNTIME DESTINATION ${QGIS_PLUGIN_DIR}
LIBRARY DESTINATION ${QGIS_PLUGIN_DIR}
)
endif()
56 changes: 20 additions & 36 deletions src/auth/basic/core/qgsauthbasicmethod.cpp
Expand Up @@ -20,12 +20,17 @@
#include "qgslogger.h"
#include "qgsapplication.h"

#ifdef HAVE_GUI
#include "qgsauthbasicedit.h"
#endif

#include <QNetworkProxy>
#include <QMutexLocker>
#include <QUuid>

static const QString AUTH_METHOD_KEY = QStringLiteral( "Basic" );
static const QString AUTH_METHOD_DESCRIPTION = QStringLiteral( "Basic authentication" );
const QString QgsAuthBasicMethod::AUTH_METHOD_KEY = QStringLiteral( "Basic" );
const QString QgsAuthBasicMethod::AUTH_METHOD_DESCRIPTION = QStringLiteral( "Basic authentication" );
const QString QgsAuthBasicMethod::AUTH_METHOD_DISPLAY_DESCRIPTION = tr( "Basic authentication" );

QMap<QString, QgsAuthMethodConfig> QgsAuthBasicMethod::sAuthConfigCache = QMap<QString, QgsAuthMethodConfig>();

Expand Down Expand Up @@ -60,9 +65,10 @@ QString QgsAuthBasicMethod::description() const

QString QgsAuthBasicMethod::displayDescription() const
{
return tr( "Basic authentication" );
return AUTH_METHOD_DISPLAY_DESCRIPTION;
}


bool QgsAuthBasicMethod::updateNetworkRequest( QNetworkRequest &request, const QString &authcfg,
const QString &dataprovider )
{
Expand Down Expand Up @@ -313,6 +319,13 @@ void QgsAuthBasicMethod::updateMethodConfig( QgsAuthMethodConfig &mconfig )
// TODO: add updates as method version() increases due to config storage changes
}

#ifdef HAVE_GUI
QWidget *QgsAuthBasicMethod::editWidget( QWidget *parent ) const
{
return new QgsAuthBasicEdit( parent );
}
#endif

void QgsAuthBasicMethod::clearCachedConfig( const QString &authcfg )
{
removeMethodConfig( authcfg );
Expand Down Expand Up @@ -375,42 +388,13 @@ QString QgsAuthBasicMethod::escapeUserPass( const QString &val, QChar delim ) co
// Plugin externals
//////////////////////////////////////////////

/**
* Required class factory to return a pointer to a newly created object
*/
QGISEXTERN QgsAuthBasicMethod *classFactory()
{
return new QgsAuthBasicMethod();
}

/**
* Required key function (used to map the plugin to a data store type)
*/
QGISEXTERN QString authMethodKey()
#ifndef HAVE_STATIC_PROVIDERS
QGISEXTERN QgsAuthMethodMetadata *authMethodMetadataFactory()
{
return AUTH_METHOD_KEY;
return new QgsAuthBasicMethodMetadata();
}
#endif

/**
* Required description function
*/
QGISEXTERN QString description()
{
return AUTH_METHOD_DESCRIPTION;
}

/**
* Required isAuthMethod function. Used to determine if this shared library
* is an authentication method plugin
*/
QGISEXTERN bool isAuthMethod()
{
return true;
}

/**
* Required cleanup function
*/
QGISEXTERN void cleanupAuthMethod() // pass QgsAuthMethod *method, then delete method ?
{
}
23 changes: 23 additions & 0 deletions src/auth/basic/core/qgsauthbasicmethod.h
Expand Up @@ -22,13 +22,20 @@

#include "qgsauthconfig.h"
#include "qgsauthmethod.h"
#include "qgsauthmethodmetadata.h"

class QWidget;

class QgsAuthBasicMethod : public QgsAuthMethod
{
Q_OBJECT

public:

static const QString AUTH_METHOD_KEY;
static const QString AUTH_METHOD_DESCRIPTION;
static const QString AUTH_METHOD_DISPLAY_DESCRIPTION;

explicit QgsAuthBasicMethod();

// QgsAuthMethod interface
Expand All @@ -52,6 +59,10 @@ class QgsAuthBasicMethod : public QgsAuthMethod

void updateMethodConfig( QgsAuthMethodConfig &mconfig ) override;

#ifdef HAVE_GUI
QWidget *editWidget( QWidget *parent )const override;
#endif

private:
QgsAuthMethodConfig getMethodConfig( const QString &authcfg, bool fullconfig = true );

Expand All @@ -62,7 +73,19 @@ class QgsAuthBasicMethod : public QgsAuthMethod
QString escapeUserPass( const QString &val, QChar delim = '\'' ) const;

static QMap<QString, QgsAuthMethodConfig> sAuthConfigCache;
};

class QgsAuthBasicMethodMetadata : public QgsAuthMethodMetadata
{
public:
QgsAuthBasicMethodMetadata()
: QgsAuthMethodMetadata( QgsAuthBasicMethod::AUTH_METHOD_KEY, QgsAuthBasicMethod::AUTH_METHOD_DESCRIPTION )
{}
QgsAuthBasicMethod *createAuthMethod() const override {return new QgsAuthBasicMethod;}
//QStringList supportedDataProviders() const override;
};




#endif // QGSAUTHBASICMETHOD_H
25 changes: 0 additions & 25 deletions src/auth/basic/gui/qgsauthbasicmethodgui.cpp

This file was deleted.

0 comments on commit 6cdbced

Please sign in to comment.