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 );