@@ -41,14 +41,19 @@ QgsWFSDataSourceURI::QgsWFSDataSourceURI( const QString& uri )
41
41
QString typeName = url.queryItemValue ( QgsWFSConstants::URI_PARAM_TYPENAME );
42
42
QString version = url.queryItemValue ( QgsWFSConstants::URI_PARAM_VERSION );
43
43
QString filter = url.queryItemValue ( QgsWFSConstants::URI_PARAM_FILTER );
44
- mAuth .mUserName = url.queryItemValue ( QgsWFSConstants::URI_PARAM_USERNAME );
45
- // In QgsDataSourceURI, the "username" param is named "user", check it
46
- if ( mAuth .mUserName .isEmpty () )
44
+ mAuth .mAuthCfg = url.queryItemValue ( QgsWFSConstants::URI_PARAM_AUTHCFG );
45
+ // NOTE: A defined authcfg overrides any older username/password auth
46
+ // Only check for older auth if it is undefined
47
+ if ( mAuth .mAuthCfg .isEmpty () )
47
48
{
48
- mAuth .mUserName = url.queryItemValue ( QgsWFSConstants::URI_PARAM_USER );
49
+ mAuth .mUserName = url.queryItemValue ( QgsWFSConstants::URI_PARAM_USERNAME );
50
+ // In QgsDataSourceURI, the "username" param is named "user", check it
51
+ if ( mAuth .mUserName .isEmpty () )
52
+ {
53
+ mAuth .mUserName = url.queryItemValue ( QgsWFSConstants::URI_PARAM_USER );
54
+ }
55
+ mAuth .mPassword = url.queryItemValue ( QgsWFSConstants::URI_PARAM_PASSWORD );
49
56
}
50
- mAuth .mPassword = url.queryItemValue ( QgsWFSConstants::URI_PARAM_PASSWORD );
51
- mAuth .mAuthCfg = url.queryItemValue ( QgsWFSConstants::URI_PARAM_AUTHCFG );
52
57
53
58
// Now remove all stuff that is not the core URL
54
59
url.removeQueryItem ( " SERVICE" );
@@ -90,19 +95,24 @@ QgsWFSDataSourceURI::QgsWFSDataSourceURI( const QString& uri )
90
95
const QString QgsWFSDataSourceURI::uri ( bool expandAuthConfig ) const
91
96
{
92
97
QgsDataSourceURI theURI ( mURI );
93
- // Add auth params back into the uri
98
+ // Add authcfg param back into the uri (must be non-empty value)
94
99
if ( ! mAuth .mAuthCfg .isEmpty () )
95
100
{
96
101
theURI.setAuthConfigId ( mAuth .mAuthCfg );
97
102
}
98
- if ( ! mAuth .mUserName .isEmpty () )
99
- {
100
- theURI.setUsername ( mAuth .mUserName );
101
- }
102
- if ( ! mAuth .mPassword .isEmpty () )
103
+ else
103
104
{
104
- theURI.setPassword ( mAuth .mPassword );
105
+ // Add any older username/password auth params back in (allow empty values)
106
+ if ( ! mAuth .mUserName .isNull () )
107
+ {
108
+ theURI.setUsername ( mAuth .mUserName );
109
+ }
110
+ if ( ! mAuth .mPassword .isNull () )
111
+ {
112
+ theURI.setPassword ( mAuth .mPassword );
113
+ }
105
114
}
115
+ // NOTE: avoid expanding authcfg here; it is handled during network access
106
116
return theURI.uri ( expandAuthConfig );
107
117
}
108
118
0 commit comments