Skip to content

Commit

Permalink
Merge pull request #5429 from boundlessgeo/BD-2239-clear-access-cache
Browse files Browse the repository at this point in the history
[auth][needs-docs][feature] Clear access cache
  • Loading branch information
elpaso authored Oct 24, 2017
2 parents d34c09b + ceab42e commit 821be45
Show file tree
Hide file tree
Showing 7 changed files with 165 additions and 69 deletions.
16 changes: 16 additions & 0 deletions src/app/qgsoptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,15 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl, const QList<QgsOpti
connect( mBrowseCacheDirectory, &QAbstractButton::clicked, this, &QgsOptions::browseCacheDirectory );
connect( mClearCache, &QAbstractButton::clicked, this, &QgsOptions::clearCache );

// Access (auth) cache settings
mAutoClearAccessCache->setChecked( mSettings->value( QStringLiteral( "clear_auth_cache_on_errors" ), true, QgsSettings::Section::Auth ).toBool( ) );
connect( mClearAccessCache, &QAbstractButton::clicked, this, &QgsOptions::clearAccessCache );

connect( mAutoClearAccessCache, &QCheckBox::clicked, this, [ = ]( bool checked )
{
mSettings->setValue( QStringLiteral( "clear_auth_cache_on_errors" ), checked, QgsSettings::Section::Auth );
} );

//wms search server
leWmsSearch->setText( mSettings->value( QStringLiteral( "/qgis/WMSSearchUrl" ), "http://geopole.org/wms/search?search=%1&type=rss" ).toString() );

Expand Down Expand Up @@ -1978,6 +1987,13 @@ void QgsOptions::browseCacheDirectory()
void QgsOptions::clearCache()
{
QgsNetworkAccessManager::instance()->cache()->clear();
QMessageBox::information( this, tr( "Cache cleared" ), tr( "Content cache has been cleared" ) );
}

void QgsOptions::clearAccessCache()
{
QgsNetworkAccessManager::instance()->clearAccessCache();
QMessageBox::information( this, tr( "Cache cleared" ), tr( "Connection authentication cache has been cleared" ) );
}

void QgsOptions::mOptionsStackedWidget_currentChanged( int indx )
Expand Down
6 changes: 6 additions & 0 deletions src/app/qgsoptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,12 @@ class APP_EXPORT QgsOptions : public QgsOptionsDialogBase, private Ui::QgsOption
void browseCacheDirectory();
void clearCache();

/**
* \brief clearAuthenticationConnectionCache clears the QNetworkAccessManager
* authentication connection cache
*/
void clearAccessCache();

/**
* Let the user add a scale to the list of scales
* used in scale combobox
Expand Down
31 changes: 25 additions & 6 deletions src/gui/auth/qgsautheditorwidgets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "qgsauthcertificatemanager.h"
#include "qgsauthguiutils.h"
#include "qgsauthmanager.h"
#include "qgsnetworkaccessmanager.h"


QgsAuthMethodPlugins::QgsAuthMethodPlugins( QWidget *parent )
Expand Down Expand Up @@ -140,12 +141,17 @@ void QgsAuthEditorWidgets::setupUtilitiesMenu()
this, &QgsAuthEditorWidgets::authMessageOut );

// set up utility actions menu
mActionSetMasterPassword = new QAction( QStringLiteral( "Input master password" ), this );
mActionClearCachedMasterPassword = new QAction( QStringLiteral( "Clear cached master password" ), this );
mActionResetMasterPassword = new QAction( QStringLiteral( "Reset master password" ), this );
mActionClearCachedAuthConfigs = new QAction( QStringLiteral( "Clear cached authentication configurations" ), this );
mActionRemoveAuthConfigs = new QAction( QStringLiteral( "Remove all authentication configurations" ), this );
mActionEraseAuthDatabase = new QAction( QStringLiteral( "Erase authentication database" ), this );
mActionSetMasterPassword = new QAction( tr( "Input master password" ), this );
mActionClearCachedMasterPassword = new QAction( tr( "Clear cached master password" ), this );
mActionResetMasterPassword = new QAction( tr( "Reset master password" ), this );
mActionClearCachedAuthConfigs = new QAction( tr( "Clear cached authentication configurations" ), this );
mActionRemoveAuthConfigs = new QAction( tr( "Remove all authentication configurations" ), this );
mActionEraseAuthDatabase = new QAction( tr( "Erase authentication database" ), this );

mActionClearAccessCacheNow = new QAction( tr( "Clear network authentication access cache" ), this );
mActionAutoClearAccessCache = new QAction( tr( "Automatically clear network authentication access cache on SSL errors" ), this );
mActionAutoClearAccessCache->setCheckable( true );
mActionAutoClearAccessCache->setChecked( QgsSettings().value( QStringLiteral( "clear_auth_cache_on_errors" ), true, QgsSettings::Section::Auth ).toBool( ) );

mActionPasswordHelperSync = new QAction( tr( "Store/update the master password in your %1" )
.arg( QgsAuthManager::AUTH_PASSWORD_HELPER_DISPLAY_NAME ), this );
Expand Down Expand Up @@ -173,11 +179,24 @@ void QgsAuthEditorWidgets::setupUtilitiesMenu()
connect( mActionPasswordHelperEnable, &QAction::triggered, this, &QgsAuthEditorWidgets::passwordHelperEnableTriggered );
connect( mActionPasswordHelperLoggingEnable, &QAction::triggered, this, &QgsAuthEditorWidgets::passwordHelperLoggingEnableTriggered );

connect( mActionClearAccessCacheNow, &QAction::triggered, this, [ = ]
{
QgsNetworkAccessManager::instance()->clearAccessCache();
messageBar()->pushSuccess( tr( "Auth cache cleared" ), tr( "Network authentication cache has been cleared" ) );
} );
connect( mActionAutoClearAccessCache, &QAction::triggered, this, [ ]( bool checked )
{
QgsSettings().setValue( QStringLiteral( "clear_auth_cache_on_errors" ), checked, QgsSettings::Section::Auth );
} );

mAuthUtilitiesMenu = new QMenu( this );
mAuthUtilitiesMenu->addAction( mActionSetMasterPassword );
mAuthUtilitiesMenu->addAction( mActionClearCachedMasterPassword );
mAuthUtilitiesMenu->addAction( mActionResetMasterPassword );
mAuthUtilitiesMenu->addSeparator();
mAuthUtilitiesMenu->addAction( mActionClearAccessCacheNow );
mAuthUtilitiesMenu->addAction( mActionAutoClearAccessCache );
mAuthUtilitiesMenu->addSeparator();
mAuthUtilitiesMenu->addAction( mActionPasswordHelperEnable );
mAuthUtilitiesMenu->addAction( mActionPasswordHelperSync );
mAuthUtilitiesMenu->addAction( mActionPasswordHelperDelete );
Expand Down
2 changes: 2 additions & 0 deletions src/gui/auth/qgsautheditorwidgets.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ class GUI_EXPORT QgsAuthEditorWidgets : public QWidget, private Ui::QgsAuthEdito
QAction *mActionPasswordHelperSync = nullptr;
QAction *mActionPasswordHelperEnable = nullptr;
QAction *mActionPasswordHelperLoggingEnable = nullptr;
QAction *mActionClearAccessCacheNow = nullptr;
QAction *mActionAutoClearAccessCache = nullptr;
};

#endif // QGSAUTHEDITORWIDGETS_H
10 changes: 10 additions & 0 deletions src/gui/auth/qgsauthsslerrorsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <QToolButton>

#include "qgsauthmanager.h"
#include "qgsnetworkaccessmanager.h"
#include "qgsauthcertutils.h"
#include "qgsauthtrustedcasdialog.h"
#include "qgscollapsiblegroupbox.h"
Expand Down Expand Up @@ -188,6 +189,15 @@ void QgsAuthSslErrorsDialog::buttonBox_clicked( QAbstractButton *button )
reject();
break;
}
// Clear access cache if the user choose abort and the
// setting allows it
if ( btnenum == QDialogButtonBox::Abort &&
QgsSettings().value( QStringLiteral( "clear_auth_cache_on_errors" ),
true,
QgsSettings::Section::Auth ).toBool( ) )
{
QgsNetworkAccessManager::instance()->clearAccessCache();
}
}

void QgsAuthSslErrorsDialog::populateErrorsList()
Expand Down
29 changes: 18 additions & 11 deletions src/ui/auth/qgsauthsslerrorsdialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
<rect>
<x>0</x>
<y>0</y>
<width>617</width>
<height>710</height>
<width>493</width>
<height>430</height>
</rect>
</property>
<property name="contextMenuPolicy">
<enum>Qt::PreventContextMenu</enum>
</property>
<property name="windowTitle">
<string>Custom Certificate Configuration</string>
</property>
Expand Down Expand Up @@ -169,7 +172,7 @@
</sizepolicy>
</property>
<property name="title">
<string>Save SSL server exception</string>
<string>Save SSL server e&amp;xception</string>
</property>
<property name="checkable">
<bool>true</bool>
Expand Down Expand Up @@ -219,14 +222,18 @@
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Abort|QDialogButtonBox::Ignore|QDialogButtonBox::Save</set>
</property>
</widget>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Abort|QDialogButtonBox::Ignore|QDialogButtonBox::Save</set>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
Expand Down
140 changes: 88 additions & 52 deletions src/ui/qgsoptionsbase.ui
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@
<item>
<widget class="QStackedWidget" name="mOptionsStackedWidget">
<property name="currentIndex">
<number>0</number>
<number>12</number>
</property>
<widget class="QWidget" name="mOptionsPageGeneral">
<layout class="QVBoxLayout" name="verticalLayout_3">
Expand Down Expand Up @@ -338,14 +338,14 @@
<x>0</x>
<y>0</y>
<width>580</width>
<height>672</height>
<height>804</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_28">
<item>
<widget class="QgsCollapsibleGroupBox" name="grpLocale">
<property name="title">
<string>O&amp;verride system locale</string>
<string>Override system &amp;locale</string>
</property>
<property name="checkable">
<bool>true</bool>
Expand Down Expand Up @@ -4755,7 +4755,7 @@ The bigger the number, the faster zooming with the mouse wheel will be.</string>
<item row="3" column="0">
<widget class="QRadioButton" name="radUseGlobalProjection">
<property name="text">
<string>Use a default CRS</string>
<string>&amp;Use a default CRS</string>
</property>
</widget>
</item>
Expand Down Expand Up @@ -4947,53 +4947,91 @@ The bigger the number, the faster zooming with the mouse wheel will be.</string>
<property name="title">
<string>Cache settings</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="label_10">
<property name="text">
<string>Directory</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="mCacheDirectory"/>
</item>
<item row="0" column="2">
<widget class="QToolButton" name="mBrowseCacheDirectory">
<property name="toolTip">
<string>Select folder</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/mActionFileOpen.svg</normaloff>:/images/themes/default/mActionFileOpen.svg</iconset>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_11">
<property name="text">
<string>Size [KiB]</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QSpinBox" name="mCacheSize"/>
</item>
<item row="2" column="2">
<widget class="QToolButton" name="mClearCache">
<property name="toolTip">
<string>Clear</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/mActionUndo.svg</normaloff>:/images/themes/default/mActionUndo.svg</iconset>
<layout class="QVBoxLayout" name="verticalLayout_19">
<item>
<widget class="QTabWidget" name="tabContentCache">
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="tab">
<attribute name="title">
<string>Content</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_2">
<item row="4" column="0">
<widget class="QLabel" name="label_11">
<property name="text">
<string>Size [KiB]</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_10">
<property name="text">
<string>Directory</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="mCacheDirectory"/>
</item>
<item row="4" column="1">
<widget class="QSpinBox" name="mCacheSize"/>
</item>
<item row="0" column="2">
<widget class="QToolButton" name="mBrowseCacheDirectory">
<property name="toolTip">
<string>Select folder</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/mActionFileOpen.svg</normaloff>:/images/themes/default/mActionFileOpen.svg</iconset>
</property>
</widget>
</item>
<item row="4" column="2">
<widget class="QToolButton" name="mClearCache">
<property name="toolTip">
<string>Clear cache</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/mActionDeleteSelected.svg</normaloff>:/images/themes/default/mActionDeleteSelected.svg</iconset>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_2">
<attribute name="title">
<string>Authentication</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_5">
<item row="0" column="0">
<widget class="QCheckBox" name="mAutoClearAccessCache">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;The connection cache stores all authentication connections data even when the connection fails.&lt;br/&gt;If you make any change to the authentication configurations or to the certification authorities, you should clear the authentication cache or&lt;br/&gt;restart QGIS. &lt;br/&gt;When this option is checked, the authentication cache will be automatically cleared every time an SSL error occurs and you choose to abort the connection.&lt;br/&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Automatically clear the connection authentication cache on SSL errors (recommended)</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QPushButton" name="mClearAccessCache">
<property name="text">
<string>Clear authentication connection cache</string>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
Expand Down Expand Up @@ -5610,9 +5648,7 @@ The bigger the number, the faster zooming with the mouse wheel will be.</string>
<tabstop>mDefaultTileMaxRetrySpinBox</tabstop>
<tabstop>leUserAgent</tabstop>
<tabstop>mCacheDirectory</tabstop>
<tabstop>mBrowseCacheDirectory</tabstop>
<tabstop>mCacheSize</tabstop>
<tabstop>mClearCache</tabstop>
<tabstop>grpProxy</tabstop>
<tabstop>mProxyTypeComboBox</tabstop>
<tabstop>leProxyHost</tabstop>
Expand Down

0 comments on commit 821be45

Please sign in to comment.