Skip to content

Commit

Permalink
[auth] Added mutex to protect cache for basic auth
Browse files Browse the repository at this point in the history
  • Loading branch information
elpaso committed Oct 6, 2017
1 parent a4a33df commit d76b04a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/auth/basic/qgsauthbasicmethod.cpp
Expand Up @@ -21,6 +21,7 @@
#include "qgslogger.h"

#include <QNetworkProxy>
#include <QMutexLocker>

static const QString AUTH_METHOD_KEY = QStringLiteral( "Basic" );
static const QString AUTH_METHOD_DESCRIPTION = QStringLiteral( "Basic authentication" );
Expand Down Expand Up @@ -169,6 +170,7 @@ void QgsAuthBasicMethod::clearCachedConfig( const QString &authcfg )

QgsAuthMethodConfig QgsAuthBasicMethod::getMethodConfig( const QString &authcfg, bool fullconfig )
{
QMutexLocker locker( &mConfigMutex );
QgsAuthMethodConfig mconfig;

// check if it is cached
Expand All @@ -187,19 +189,22 @@ QgsAuthMethodConfig QgsAuthBasicMethod::getMethodConfig( const QString &authcfg,
}

// cache bundle
locker.unlock();
putMethodConfig( authcfg, mconfig );

return mconfig;
}

void QgsAuthBasicMethod::putMethodConfig( const QString &authcfg, const QgsAuthMethodConfig &mconfig )
{
QMutexLocker locker( &mConfigMutex );
QgsDebugMsg( QString( "Putting basic config for authcfg: %1" ).arg( authcfg ) );
sAuthConfigCache.insert( authcfg, mconfig );
}

void QgsAuthBasicMethod::removeMethodConfig( const QString &authcfg )
{
QMutexLocker locker( &mConfigMutex );
if ( sAuthConfigCache.contains( authcfg ) )
{
sAuthConfigCache.remove( authcfg );
Expand Down
3 changes: 3 additions & 0 deletions src/auth/basic/qgsauthbasicmethod.h
Expand Up @@ -18,6 +18,7 @@
#define QGSAUTHBASICMETHOD_H

#include <QObject>
#include <QMutex>

#include "qgsauthconfig.h"
#include "qgsauthmethod.h"
Expand Down Expand Up @@ -61,6 +62,8 @@ class QgsAuthBasicMethod : public QgsAuthMethod
QString escapeUserPass( const QString &val, QChar delim = '\'' ) const;

static QMap<QString, QgsAuthMethodConfig> sAuthConfigCache;

QMutex mConfigMutex;
};

#endif // QGSAUTHBASICMETHOD_H

0 comments on commit d76b04a

Please sign in to comment.