Skip to content

Commit 5de906f

Browse files
committed
[auth] Added mutex to protect cache for basic auth
1 parent 38a4397 commit 5de906f

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/auth/basic/qgsauthbasicmethod.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
#include "qgsauthmanager.h"
2121
#include "qgslogger.h"
2222

23+
#include <QNetworkProxy>
24+
#include <QMutexLocker>
25+
2326
static const QString AUTH_METHOD_KEY = "Basic";
2427
static const QString AUTH_METHOD_DESCRIPTION = "Basic authentication";
2528

@@ -149,6 +152,7 @@ void QgsAuthBasicMethod::clearCachedConfig( const QString &authcfg )
149152

150153
QgsAuthMethodConfig QgsAuthBasicMethod::getMethodConfig( const QString &authcfg, bool fullconfig )
151154
{
155+
QMutexLocker locker( &mConfigMutex );
152156
QgsAuthMethodConfig mconfig;
153157

154158
// check if it is cached
@@ -167,20 +171,23 @@ QgsAuthMethodConfig QgsAuthBasicMethod::getMethodConfig( const QString &authcfg,
167171
}
168172

169173
// cache bundle
174+
locker.unlock();
170175
putMethodConfig( authcfg, mconfig );
171176

172177
return mconfig;
173178
}
174179

175180
void QgsAuthBasicMethod::putMethodConfig( const QString &authcfg, const QgsAuthMethodConfig& mconfig )
176181
{
182+
QMutexLocker locker( &mConfigMutex );
177183
QgsDebugMsg( QString( "Putting basic config for authcfg: %1" ).arg( authcfg ) );
178184
mAuthConfigCache.insert( authcfg, mconfig );
179185
}
180186

181187
void QgsAuthBasicMethod::removeMethodConfig( const QString &authcfg )
182188
{
183-
if ( mAuthConfigCache.contains( authcfg ) )
189+
QMutexLocker locker( &mConfigMutex );
190+
if ( sAuthConfigCache.contains( authcfg ) )
184191
{
185192
mAuthConfigCache.remove( authcfg );
186193
QgsDebugMsg( QString( "Removed basic config for authcfg: %1" ).arg( authcfg ) );

src/auth/basic/qgsauthbasicmethod.h

Lines changed: 4 additions & 1 deletion
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"
@@ -57,7 +58,9 @@ class QgsAuthBasicMethod : public QgsAuthMethod
5758

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

60-
static QMap<QString, QgsAuthMethodConfig> mAuthConfigCache;
61+
static QMap<QString, QgsAuthMethodConfig> sAuthConfigCache;
62+
63+
QMutex mConfigMutex;
6164
};
6265

6366
#endif // QGSAUTHBASICMETHOD_H

0 commit comments

Comments
 (0)