27 #ifdef HAVE_STATIC_PROVIDERS 
   28 #include "qgsauthbasicmethod.h" 
   29 #include "qgsauthesritokenmethod.h" 
   30 #include "qgsauthidentcertmethod.h" 
   31 #ifdef HAVE_OAUTH2_PLUGIN 
   32 #include "qgsauthoauth2method.h" 
   34 #include "qgsauthpkipathsmethod.h" 
   35 #include "qgsauthpkcs12method.h" 
   41 #include <QRegularExpression> 
   52     const QMutexLocker locker( &sMutex );
 
   70     QString 
const &authMethodKey )
 
   72   const QgsAuthMethodRegistry::AuthMethods::const_iterator i =
 
   73     metaData.find( authMethodKey );
 
   75   if ( i != metaData.end() )
 
   83 QgsAuthMethodRegistry::QgsAuthMethodRegistry( 
const QString &pluginPath )
 
   89   char **argv = qApp->argv();
 
   90   QString appDir = argv[0];
 
   91   int bin = appDir.findRev( 
"/bin", -1, 
false );
 
   92   QString baseDir = appDir.left( bin );
 
   93   QString mLibraryDirectory = baseDir + 
"/lib";
 
   95   mLibraryDirectory.setPath( pluginPath );
 
   96   mLibraryDirectory.setSorting( QDir::Name | QDir::IgnoreCase );
 
   97   mLibraryDirectory.setFilter( QDir::Files | QDir::NoSymLinks );
 
  102 void QgsAuthMethodRegistry::init()
 
  104 #ifdef HAVE_STATIC_PROVIDERS 
  105   mAuthMethods[ QgsAuthBasicMethod::AUTH_METHOD_KEY] = 
new QgsAuthBasicMethodMetadata();
 
  106   mAuthMethods[ QgsAuthEsriTokenMethod::AUTH_METHOD_KEY] = 
new QgsAuthEsriTokenMethodMetadata();
 
  107   mAuthMethods[ QgsAuthIdentCertMethod::AUTH_METHOD_KEY] = 
new QgsAuthIdentCertMethodMetadata();
 
  108 #ifdef HAVE_OAUTH2_PLUGIN 
  109   mAuthMethods[ QgsAuthOAuth2Method::AUTH_METHOD_KEY] = 
new QgsAuthOAuth2MethodMetadata();
 
  111   mAuthMethods[ QgsAuthPkiPathsMethod::AUTH_METHOD_KEY] = 
new QgsAuthPkiPathsMethodMetadata();
 
  112   mAuthMethods[ QgsAuthPkcs12Method::AUTH_METHOD_KEY] = 
new QgsAuthPkcs12MethodMetadata();
 
  116 #if defined(Q_OS_WIN) || defined(__CYGWIN__) 
  117   mLibraryDirectory.setNameFilters( QStringList( 
"*authmethod_*.dll" ) );
 
  119   mLibraryDirectory.setNameFilters( QStringList( QStringLiteral( 
"*authmethod_*.so" ) ) );
 
  121   QgsDebugMsgLevel( QStringLiteral( 
"Checking for auth method plugins in: %1" ).arg( mLibraryDirectory.path() ), 2 );
 
  123   if ( mLibraryDirectory.count() == 0 )
 
  125     QString msg = QObject::tr( 
"No QGIS auth method plugins found in:\n%1\n" ).arg( mLibraryDirectory.path() );
 
  126     msg += QObject::tr( 
"No authentication methods can be used. Check your QGIS installation" );
 
  129     output->
setTitle( QObject::tr( 
"No Authentication Methods" ) );
 
  136   const QString filePattern = getenv( 
"QGIS_AUTHMETHOD_FILE" );
 
  137   QRegularExpression fileRegexp;
 
  138   if ( !filePattern.isEmpty() )
 
  140     fileRegexp.setPattern( filePattern );
 
  143   QListIterator<QFileInfo> it( mLibraryDirectory.entryInfoList() );
 
  144   while ( it.hasNext() )
 
  146     const QFileInfo fi( it.next() );
 
  148     if ( !filePattern.isEmpty() )
 
  150       if ( fi.fileName().indexOf( fileRegexp ) == -1 )
 
  152         QgsDebugMsg( 
"auth method " + fi.fileName() + 
" skipped because doesn't match pattern " + filePattern );
 
  157     QLibrary myLib( fi.filePath() );
 
  160       QgsDebugMsg( QStringLiteral( 
"Checking %1: ...invalid (lib not loadable): %2" ).arg( myLib.fileName(), myLib.errorString() ) );
 
  164     bool libraryLoaded { 
false };
 
  165     QFunctionPointer func = myLib.resolve( QStringLiteral( 
"authMethodMetadataFactory" ).toLatin1().data() );
 
  166     factory_function *
function = 
reinterpret_cast< factory_function * 
>( 
cast_to_fptr( func ) );
 
  172         if ( findMetadata_( mAuthMethods, meta->
key() ) )
 
  174           QgsDebugMsg( QStringLiteral( 
"Checking %1: ...invalid (key %2 already registered)" ).arg( myLib.fileName() ).arg( meta->
key() ) );
 
  179         mAuthMethods[meta->
key()] = meta;
 
  180         libraryLoaded = 
true;
 
  183     if ( ! libraryLoaded )
 
  185       QgsDebugMsgLevel( QStringLiteral( 
"Checking %1: ...invalid (no authMethodMetadataFactory method)" ).arg( myLib.fileName() ), 2 );
 
  197   if ( sInstance == 
this )
 
  201 void QgsAuthMethodRegistry::clean()
 
  203   AuthMethods::const_iterator it = mAuthMethods.begin();
 
  205   while ( it != mAuthMethods.end() )
 
  208     const QString lib = it->second->library();
 
  209     QLibrary myLib( lib );
 
  210     if ( myLib.isLoaded() )
 
  239   AuthMethods::const_iterator it = mAuthMethods.begin();
 
  241   if ( mAuthMethods.empty() )
 
  243     return QObject::tr( 
"No authentication method plugins are available." );
 
  250     list += QLatin1String( 
"<ol>" );
 
  253   while ( it != mAuthMethods.end() )
 
  257       list += QLatin1String( 
"<li>" );
 
  260     list += it->second->description();
 
  264       list += QLatin1String( 
"<br></li>" );
 
  276     list += QLatin1String( 
"</ol>" );
 
  284   return mLibraryDirectory;
 
  289   mLibraryDirectory = path;
 
  298   return findMetadata_( mAuthMethods, authMethodKey );
 
  316   for ( AuthMethods::const_iterator it = mAuthMethods.begin(); it != mAuthMethods.end(); ++it )
 
  318     lst.append( it->first );
 
A registry / canonical manager of authentication methods.
const QgsAuthMethodMetadata * authMethodMetadata(const QString &authMethodKey) const
Returns metadata of the auth method or nullptr if not found.
static QgsAuthMethodRegistry * instance(const QString &pluginPath=QString())
Means of accessing canonical single instance.
QString pluginList(bool asHtml=false) const
Returns list of auth method plugins found.
void setLibraryDirectory(const QDir &path)
Sets library directory where to search for plugins.
QDir libraryDirectory() const
Returns library directory where plugins are found.
virtual ~QgsAuthMethodRegistry()
Virtual dectructor.
Q_DECL_DEPRECATED QString library(const QString &authMethodKey) const
Returns path for the library of the auth method.
QStringList authMethodList() const
Returns list of available auth methods by their keys.
std::map< QString, QgsAuthMethodMetadata * > AuthMethods
Type for auth method metadata associative container.
QgsAuthMethod * createAuthMethod(const QString &authMethodKey)
Create an instance of the auth method.
Abstract base class for authentication method plugins.
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::MessageLevel::Warning, bool notifyUser=true)
Adds a message to the log instance (and creates it if necessary).
Interface for showing messages from QGIS in GUI independent way.
virtual void showMessage(bool blocking=true)=0
display the message to the user and deletes itself
static QgsMessageOutput * createMessageOutput()
function that returns new class derived from QgsMessageOutput (don't forget to delete it then if show...
virtual void setMessage(const QString &message, MessageType msgType)=0
Sets message, it won't be displayed until.
virtual void setTitle(const QString &title)=0
Sets title for the messages.
#define Q_NOWARN_DEPRECATED_POP
#define Q_NOWARN_DEPRECATED_PUSH
void cleanupAuthMethod_t()
QgsAuthMethod * classFactoryFunction_t()
#define QgsDebugMsgLevel(str, level)