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 11, 2017
1 parent 4ccaf11 commit afeaa7f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
14 changes: 10 additions & 4 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 Down Expand Up @@ -52,8 +53,9 @@ QgsAuthPkiPathsMethod::QgsAuthPkiPathsMethod()

QgsAuthPkiPathsMethod::~QgsAuthPkiPathsMethod()
{
qDeleteAll( mPkiConfigBundleCache );
mPkiConfigBundleCache.clear();
QMutexLocker locker( &mConfigMutex );
qDeleteAll( sPkiConfigBundleCache );
sPkiConfigBundleCache.clear();
}

QString QgsAuthPkiPathsMethod::key() const
Expand Down Expand Up @@ -224,7 +226,8 @@ void QgsAuthPkiPathsMethod::updateMethodConfig( QgsAuthMethodConfig &mconfig )

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

// check if it is cached
if ( mPkiConfigBundleCache.contains( authcfg ) )
Expand Down Expand Up @@ -266,6 +269,7 @@ QgsPkiConfigBundle *QgsAuthPkiPathsMethod::getPkiConfigBundle( const QString &au

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

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

Expand All @@ -274,13 +278,15 @@ 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 ) );
mPkiConfigBundleCache.insert( authcfg, pkibundle );
}

void QgsAuthPkiPathsMethod::removePkiConfigBundle( const QString &authcfg )
{
if ( mPkiConfigBundleCache.contains( authcfg ) )
QMutexLocker locker( &mConfigMutex );
if ( sPkiConfigBundleCache.contains( authcfg ) )
{
QgsPkiConfigBundle * pkibundle = mPkiConfigBundleCache.take( authcfg );
delete pkibundle;
Expand Down
6 changes: 5 additions & 1 deletion 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 @@ -56,7 +57,10 @@ class QgsAuthPkiPathsMethod : public QgsAuthMethod

void removePkiConfigBundle( const QString &authcfg );

static QMap<QString, QgsPkiConfigBundle *> mPkiConfigBundleCache;
static QMap<QString, QgsPkiConfigBundle *> sPkiConfigBundleCache;

QMutex mConfigMutex;

};

#endif // QGSAUTHPKIPATHSMETHOD_H

0 comments on commit afeaa7f

Please sign in to comment.