Skip to content

Commit d76b04a

Browse files
committedOct 6, 2017
[auth] Added mutex to protect cache for basic auth
1 parent a4a33df commit d76b04a

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed
 

‎src/auth/basic/qgsauthbasicmethod.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "qgslogger.h"
2222

2323
#include <QNetworkProxy>
24+
#include <QMutexLocker>
2425

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

170171
QgsAuthMethodConfig QgsAuthBasicMethod::getMethodConfig( const QString &authcfg, bool fullconfig )
171172
{
173+
QMutexLocker locker( &mConfigMutex );
172174
QgsAuthMethodConfig mconfig;
173175

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

189191
// cache bundle
192+
locker.unlock();
190193
putMethodConfig( authcfg, mconfig );
191194

192195
return mconfig;
193196
}
194197

195198
void QgsAuthBasicMethod::putMethodConfig( const QString &authcfg, const QgsAuthMethodConfig &mconfig )
196199
{
200+
QMutexLocker locker( &mConfigMutex );
197201
QgsDebugMsg( QString( "Putting basic config for authcfg: %1" ).arg( authcfg ) );
198202
sAuthConfigCache.insert( authcfg, mconfig );
199203
}
200204

201205
void QgsAuthBasicMethod::removeMethodConfig( const QString &authcfg )
202206
{
207+
QMutexLocker locker( &mConfigMutex );
203208
if ( sAuthConfigCache.contains( authcfg ) )
204209
{
205210
sAuthConfigCache.remove( authcfg );

‎src/auth/basic/qgsauthbasicmethod.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#define QGSAUTHBASICMETHOD_H
1919

2020
#include <QObject>
21+
#include <QMutex>
2122

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

6364
static QMap<QString, QgsAuthMethodConfig> sAuthConfigCache;
65+
66+
QMutex mConfigMutex;
6467
};
6568

6669
#endif // QGSAUTHBASICMETHOD_H

0 commit comments

Comments
 (0)
Please sign in to comment.