Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[auth] Allow capital letters in config ID
  • Loading branch information
dakcarto committed Sep 26, 2015
1 parent a72cec0 commit 2f8e684
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 7 deletions.
4 changes: 4 additions & 0 deletions python/core/auth/qgsauthmanager.sip
Expand Up @@ -77,6 +77,10 @@ class QgsAuthManager : QObject

bool configIdUnique( const QString &id ) const;

bool hasConfigId( const QString &txt ) const;

QString configIdRegex() const;

QStringList configIds() const;


Expand Down
2 changes: 1 addition & 1 deletion src/app/qgisapp.cpp
Expand Up @@ -8198,7 +8198,7 @@ QgsVectorLayer* QgisApp::addVectorLayer( QString vectorLayerPath, QString baseNa

// if the layer needs authentication, ensure the master password is set
bool authok = true;
QRegExp rx( "authcfg=([a-z]|[0-9]){7}" );
QRegExp rx( "authcfg=([a-z]|[A-Z]|[0-9]){7}" );
if ( rx.indexIn( vectorLayerPath ) != -1 )
{
authok = false;
Expand Down
18 changes: 13 additions & 5 deletions src/core/auth/qgsauthmanager.cpp
Expand Up @@ -55,6 +55,8 @@ const QString QgsAuthManager::smAuthServersTable = "auth_servers";
const QString QgsAuthManager::smAuthAuthoritiesTable = "auth_authorities";
const QString QgsAuthManager::smAuthTrustTable = "auth_trust";
const QString QgsAuthManager::smAuthManTag = QObject::tr( "Authentication Manager" );
const QString QgsAuthManager::smAuthCfgRegex = "authcfg=([a-z]|[A-Z]|[0-9]){7}";


QgsAuthManager *QgsAuthManager::instance()
{
Expand Down Expand Up @@ -750,12 +752,18 @@ bool QgsAuthManager::configIdUnique( const QString& id ) const
return !configids.contains( id );
}

bool QgsAuthManager::hasConfigId( const QString &txt ) const
{
QRegExp rx( smAuthCfgRegex );
return rx.indexIn( txt ) != -1;
}

QgsAuthMethodConfigsMap QgsAuthManager::availableAuthMethodConfigs( const QString &dataprovider )
{
QStringList providerAuthMethodsKeys;
if ( !dataprovider.isEmpty() )
{
providerAuthMethodsKeys = authMethodsKeys( dataprovider );
providerAuthMethodsKeys = authMethodsKeys( dataprovider.toLower() );
}

QgsAuthMethodConfigsMap baseConfigs;
Expand Down Expand Up @@ -847,7 +855,7 @@ QString QgsAuthManager::configAuthMethodKey( const QString &authcfg ) const

QStringList QgsAuthManager::authMethodsKeys( const QString &dataprovider )
{
return authMethodsMap( dataprovider ).uniqueKeys();
return authMethodsMap( dataprovider.toLower() ).uniqueKeys();
}

QgsAuthMethod *QgsAuthManager::authMethod( const QString &authMethodKey )
Expand Down Expand Up @@ -1294,7 +1302,7 @@ bool QgsAuthManager::updateNetworkRequest( QNetworkRequest &request, const QStri
return false;
}

if ( !authmethod->updateNetworkRequest( request, authcfg, dataprovider ) )
if ( !authmethod->updateNetworkRequest( request, authcfg, dataprovider.toLower() ) )
{
authmethod->clearCachedConfig( authcfg );
return false;
Expand All @@ -1320,7 +1328,7 @@ bool QgsAuthManager::updateNetworkReply( QNetworkReply *reply, const QString& au
return false;
}

if ( !authmethod->updateNetworkReply( reply, authcfg, dataprovider ) )
if ( !authmethod->updateNetworkReply( reply, authcfg, dataprovider.toLower() ) )
{
authmethod->clearCachedConfig( authcfg );
return false;
Expand All @@ -1346,7 +1354,7 @@ bool QgsAuthManager::updateDataSourceUriItems( QStringList &connectionItems, con
return false;
}

if ( !authmethod->updateDataSourceUriItems( connectionItems, authcfg, dataprovider ) )
if ( !authmethod->updateDataSourceUriItems( connectionItems, authcfg, dataprovider.toLower() ) )
{
authmethod->clearCachedConfig( authcfg );
return false;
Expand Down
10 changes: 10 additions & 0 deletions src/core/auth/qgsauthmanager.h
Expand Up @@ -227,6 +227,15 @@ class CORE_EXPORT QgsAuthManager : public QObject
*/
bool configIdUnique( const QString &id ) const;

/**
* Return whether a string includes an authcfg ID token
* @param txt String to check
*/
bool hasConfigId( const QString &txt ) const;

/** Return regular expression for authcfg=.{7} key/value token for authentication ids */
QString configIdRegex() const { return smAuthCfgRegex;}

/** Get list of authentication ids from database */
QStringList configIds() const;

Expand Down Expand Up @@ -587,6 +596,7 @@ class CORE_EXPORT QgsAuthManager : public QObject
static const QString smAuthAuthoritiesTable;
static const QString smAuthTrustTable;
static const QString smAuthManTag;
static const QString smAuthCfgRegex;

bool mAuthInit;
QString mAuthDbPath;
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsmaplayer.cpp
Expand Up @@ -184,7 +184,7 @@ bool QgsMapLayer::readLayerXML( const QDomElement& layerElement )
mDataSource = mne.text();

// if the layer needs authentication, ensure the master password is set
QRegExp rx( "authcfg=([a-z]|[0-9]){7}" );
QRegExp rx( "authcfg=([a-z]|[A-Z]|[0-9]){7}" );
if (( rx.indexIn( mDataSource ) != -1 )
&& !QgsAuthManager::instance()->setMasterPassword( true ) )
{
Expand Down

0 comments on commit 2f8e684

Please sign in to comment.