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 11, 2017
1 parent 38a4397 commit 5de906f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/auth/basic/qgsauthbasicmethod.cpp
Expand Up @@ -20,6 +20,9 @@
#include "qgsauthmanager.h"
#include "qgslogger.h"

#include <QNetworkProxy>
#include <QMutexLocker>

static const QString AUTH_METHOD_KEY = "Basic";
static const QString AUTH_METHOD_DESCRIPTION = "Basic authentication";

Expand Down Expand Up @@ -149,6 +152,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 @@ -167,20 +171,23 @@ 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 ) );
mAuthConfigCache.insert( authcfg, mconfig );
}

void QgsAuthBasicMethod::removeMethodConfig( const QString &authcfg )
{
if ( mAuthConfigCache.contains( authcfg ) )
QMutexLocker locker( &mConfigMutex );
if ( sAuthConfigCache.contains( authcfg ) )
{
mAuthConfigCache.remove( authcfg );
QgsDebugMsg( QString( "Removed basic config for authcfg: %1" ).arg( authcfg ) );
Expand Down
5 changes: 4 additions & 1 deletion 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 @@ -57,7 +58,9 @@ class QgsAuthBasicMethod : public QgsAuthMethod

QString escapeUserPass( const QString &theVal, QChar delim = '\'' ) const;

static QMap<QString, QgsAuthMethodConfig> mAuthConfigCache;
static QMap<QString, QgsAuthMethodConfig> sAuthConfigCache;

QMutex mConfigMutex;
};

#endif // QGSAUTHBASICMETHOD_H

0 comments on commit 5de906f

Please sign in to comment.