Skip to content

Commit 71d9026

Browse files
committedOct 6, 2017
[auth] Added mutex to protect cache for identcert auth
1 parent d76b04a commit 71d9026

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed
 

‎src/auth/identcert/qgsauthidentcertmethod.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <QSslConfiguration>
2626
#include <QSslError>
2727
#endif
28+
#include <QMutexLocker>
2829

2930
#include "qgsauthcertutils.h"
3031
#include "qgsauthmanager.h"
@@ -50,6 +51,7 @@ QgsAuthIdentCertMethod::QgsAuthIdentCertMethod()
5051

5152
QgsAuthIdentCertMethod::~QgsAuthIdentCertMethod()
5253
{
54+
QMutexLocker locker( &mConfigMutex );
5355
qDeleteAll( sPkiConfigBundleCache );
5456
sPkiConfigBundleCache.clear();
5557
}
@@ -219,6 +221,7 @@ void QgsAuthIdentCertMethod::updateMethodConfig( QgsAuthMethodConfig &mconfig )
219221

220222
QgsPkiConfigBundle *QgsAuthIdentCertMethod::getPkiConfigBundle( const QString &authcfg )
221223
{
224+
QMutexLocker locker( &mConfigMutex );
222225
QgsPkiConfigBundle *bundle = nullptr;
223226

224227
// check if it is cached
@@ -263,6 +266,7 @@ QgsPkiConfigBundle *QgsAuthIdentCertMethod::getPkiConfigBundle( const QString &a
263266

264267
bundle = new QgsPkiConfigBundle( mconfig, clientcert, clientkey );
265268

269+
locker.unlock();
266270
// cache bundle
267271
putPkiConfigBundle( authcfg, bundle );
268272

@@ -271,12 +275,14 @@ QgsPkiConfigBundle *QgsAuthIdentCertMethod::getPkiConfigBundle( const QString &a
271275

272276
void QgsAuthIdentCertMethod::putPkiConfigBundle( const QString &authcfg, QgsPkiConfigBundle *pkibundle )
273277
{
278+
QMutexLocker locker( &mConfigMutex );
274279
QgsDebugMsg( QString( "Putting PKI bundle for authcfg %1" ).arg( authcfg ) );
275280
sPkiConfigBundleCache.insert( authcfg, pkibundle );
276281
}
277282

278283
void QgsAuthIdentCertMethod::removePkiConfigBundle( const QString &authcfg )
279284
{
285+
QMutexLocker locker( &mConfigMutex );
280286
if ( sPkiConfigBundleCache.contains( authcfg ) )
281287
{
282288
QgsPkiConfigBundle *pkibundle = sPkiConfigBundleCache.take( authcfg );

‎src/auth/identcert/qgsauthidentcertmethod.h

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

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

2223
#include "qgsauthconfig.h"
2324
#include "qgsauthmethod.h"
@@ -57,6 +58,8 @@ class QgsAuthIdentCertMethod : public QgsAuthMethod
5758
void removePkiConfigBundle( const QString &authcfg );
5859

5960
static QMap<QString, QgsPkiConfigBundle *> sPkiConfigBundleCache;
61+
62+
QMutex mConfigMutex;
6063
};
6164

6265
#endif // QGSAUTHIDENTCERTMETHOD_H

0 commit comments

Comments
 (0)
Please sign in to comment.