Skip to content

Commit 2f8e684

Browse files
committed
[auth] Allow capital letters in config ID
1 parent a72cec0 commit 2f8e684

File tree

5 files changed

+29
-7
lines changed

5 files changed

+29
-7
lines changed

python/core/auth/qgsauthmanager.sip

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ class QgsAuthManager : QObject
7777

7878
bool configIdUnique( const QString &id ) const;
7979

80+
bool hasConfigId( const QString &txt ) const;
81+
82+
QString configIdRegex() const;
83+
8084
QStringList configIds() const;
8185

8286

src/app/qgisapp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8198,7 +8198,7 @@ QgsVectorLayer* QgisApp::addVectorLayer( QString vectorLayerPath, QString baseNa
81988198

81998199
// if the layer needs authentication, ensure the master password is set
82008200
bool authok = true;
8201-
QRegExp rx( "authcfg=([a-z]|[0-9]){7}" );
8201+
QRegExp rx( "authcfg=([a-z]|[A-Z]|[0-9]){7}" );
82028202
if ( rx.indexIn( vectorLayerPath ) != -1 )
82038203
{
82048204
authok = false;

src/core/auth/qgsauthmanager.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ const QString QgsAuthManager::smAuthServersTable = "auth_servers";
5555
const QString QgsAuthManager::smAuthAuthoritiesTable = "auth_authorities";
5656
const QString QgsAuthManager::smAuthTrustTable = "auth_trust";
5757
const QString QgsAuthManager::smAuthManTag = QObject::tr( "Authentication Manager" );
58+
const QString QgsAuthManager::smAuthCfgRegex = "authcfg=([a-z]|[A-Z]|[0-9]){7}";
59+
5860

5961
QgsAuthManager *QgsAuthManager::instance()
6062
{
@@ -750,12 +752,18 @@ bool QgsAuthManager::configIdUnique( const QString& id ) const
750752
return !configids.contains( id );
751753
}
752754

755+
bool QgsAuthManager::hasConfigId( const QString &txt ) const
756+
{
757+
QRegExp rx( smAuthCfgRegex );
758+
return rx.indexIn( txt ) != -1;
759+
}
760+
753761
QgsAuthMethodConfigsMap QgsAuthManager::availableAuthMethodConfigs( const QString &dataprovider )
754762
{
755763
QStringList providerAuthMethodsKeys;
756764
if ( !dataprovider.isEmpty() )
757765
{
758-
providerAuthMethodsKeys = authMethodsKeys( dataprovider );
766+
providerAuthMethodsKeys = authMethodsKeys( dataprovider.toLower() );
759767
}
760768

761769
QgsAuthMethodConfigsMap baseConfigs;
@@ -847,7 +855,7 @@ QString QgsAuthManager::configAuthMethodKey( const QString &authcfg ) const
847855

848856
QStringList QgsAuthManager::authMethodsKeys( const QString &dataprovider )
849857
{
850-
return authMethodsMap( dataprovider ).uniqueKeys();
858+
return authMethodsMap( dataprovider.toLower() ).uniqueKeys();
851859
}
852860

853861
QgsAuthMethod *QgsAuthManager::authMethod( const QString &authMethodKey )
@@ -1294,7 +1302,7 @@ bool QgsAuthManager::updateNetworkRequest( QNetworkRequest &request, const QStri
12941302
return false;
12951303
}
12961304

1297-
if ( !authmethod->updateNetworkRequest( request, authcfg, dataprovider ) )
1305+
if ( !authmethod->updateNetworkRequest( request, authcfg, dataprovider.toLower() ) )
12981306
{
12991307
authmethod->clearCachedConfig( authcfg );
13001308
return false;
@@ -1320,7 +1328,7 @@ bool QgsAuthManager::updateNetworkReply( QNetworkReply *reply, const QString& au
13201328
return false;
13211329
}
13221330

1323-
if ( !authmethod->updateNetworkReply( reply, authcfg, dataprovider ) )
1331+
if ( !authmethod->updateNetworkReply( reply, authcfg, dataprovider.toLower() ) )
13241332
{
13251333
authmethod->clearCachedConfig( authcfg );
13261334
return false;
@@ -1346,7 +1354,7 @@ bool QgsAuthManager::updateDataSourceUriItems( QStringList &connectionItems, con
13461354
return false;
13471355
}
13481356

1349-
if ( !authmethod->updateDataSourceUriItems( connectionItems, authcfg, dataprovider ) )
1357+
if ( !authmethod->updateDataSourceUriItems( connectionItems, authcfg, dataprovider.toLower() ) )
13501358
{
13511359
authmethod->clearCachedConfig( authcfg );
13521360
return false;

src/core/auth/qgsauthmanager.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,15 @@ class CORE_EXPORT QgsAuthManager : public QObject
227227
*/
228228
bool configIdUnique( const QString &id ) const;
229229

230+
/**
231+
* Return whether a string includes an authcfg ID token
232+
* @param txt String to check
233+
*/
234+
bool hasConfigId( const QString &txt ) const;
235+
236+
/** Return regular expression for authcfg=.{7} key/value token for authentication ids */
237+
QString configIdRegex() const { return smAuthCfgRegex;}
238+
230239
/** Get list of authentication ids from database */
231240
QStringList configIds() const;
232241

@@ -587,6 +596,7 @@ class CORE_EXPORT QgsAuthManager : public QObject
587596
static const QString smAuthAuthoritiesTable;
588597
static const QString smAuthTrustTable;
589598
static const QString smAuthManTag;
599+
static const QString smAuthCfgRegex;
590600

591601
bool mAuthInit;
592602
QString mAuthDbPath;

src/core/qgsmaplayer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ bool QgsMapLayer::readLayerXML( const QDomElement& layerElement )
184184
mDataSource = mne.text();
185185

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

0 commit comments

Comments
 (0)