Skip to content

Commit

Permalink
[auth] Added mutex to protect cache for pkipaths auth
Browse files Browse the repository at this point in the history
  • Loading branch information
elpaso committed Oct 6, 2017
1 parent 71d9026 commit 537ebcc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/auth/pkipaths/qgsauthpkipathsmethod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <QSslConfiguration>
#include <QSslError>
#endif
#include <QMutexLocker>

#include "qgsauthcertutils.h"
#include "qgsauthmanager.h"
Expand All @@ -51,6 +52,7 @@ QgsAuthPkiPathsMethod::QgsAuthPkiPathsMethod()

QgsAuthPkiPathsMethod::~QgsAuthPkiPathsMethod()
{
QMutexLocker locker( &mConfigMutex );
qDeleteAll( sPkiConfigBundleCache );
sPkiConfigBundleCache.clear();
}
Expand Down Expand Up @@ -223,6 +225,7 @@ void QgsAuthPkiPathsMethod::updateMethodConfig( QgsAuthMethodConfig &mconfig )

QgsPkiConfigBundle *QgsAuthPkiPathsMethod::getPkiConfigBundle( const QString &authcfg )
{
QMutexLocker locker( &mConfigMutex );
QgsPkiConfigBundle *bundle = nullptr;

// check if it is cached
Expand Down Expand Up @@ -265,6 +268,7 @@ QgsPkiConfigBundle *QgsAuthPkiPathsMethod::getPkiConfigBundle( const QString &au

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

locker.unlock();
// cache bundle
putPkiConfigBundle( authcfg, bundle );

Expand All @@ -273,12 +277,14 @@ QgsPkiConfigBundle *QgsAuthPkiPathsMethod::getPkiConfigBundle( const QString &au

void QgsAuthPkiPathsMethod::putPkiConfigBundle( const QString &authcfg, QgsPkiConfigBundle *pkibundle )
{
QMutexLocker locker( &mConfigMutex );
QgsDebugMsg( QString( "Putting PKI bundle for authcfg %1" ).arg( authcfg ) );
sPkiConfigBundleCache.insert( authcfg, pkibundle );
}

void QgsAuthPkiPathsMethod::removePkiConfigBundle( const QString &authcfg )
{
QMutexLocker locker( &mConfigMutex );
if ( sPkiConfigBundleCache.contains( authcfg ) )
{
QgsPkiConfigBundle *pkibundle = sPkiConfigBundleCache.take( authcfg );
Expand Down
4 changes: 4 additions & 0 deletions src/auth/pkipaths/qgsauthpkipathsmethod.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#define QGSAUTHPKIPATHSMETHOD_H

#include <QObject>
#include <QMutex>

#include "qgsauthconfig.h"
#include "qgsauthmethod.h"
Expand Down Expand Up @@ -57,6 +58,9 @@ class QgsAuthPkiPathsMethod : public QgsAuthMethod
void removePkiConfigBundle( const QString &authcfg );

static QMap<QString, QgsPkiConfigBundle *> sPkiConfigBundleCache;

QMutex mConfigMutex;

};

#endif // QGSAUTHPKIPATHSMETHOD_H

0 comments on commit 537ebcc

Please sign in to comment.