@@ -62,8 +62,16 @@ QgsWmsProvider::QgsWmsProvider( QString const & uri )
62
62
extentDirty( TRUE ),
63
63
mGetFeatureInfoUrlBase( 0 ),
64
64
mLayerCount( -1 )
65
+
65
66
{
66
- QgsDebugMsg ( " QgsWmsProvider: constructing with uri '" + uri + " '." );
67
+ // URL may contain username/password information for a WMS
68
+ // requiring authentication. In this case the URL is prefixed
69
+ // with username=user,password=pass,url=http://xxx.xxx.xx/yyy...
70
+ mUserName = " " ;
71
+ mPassword = " " ;
72
+ setAuthentication ( httpuri );
73
+
74
+ QgsDebugMsg ( " QgsWmsProvider: constructing with uri '" + httpuri + " '." );
67
75
68
76
// assume this is a valid layer until we determine otherwise
69
77
valid = true ;
@@ -100,6 +108,39 @@ QgsWmsProvider::QgsWmsProvider( QString const & uri )
100
108
QgsDebugMsg ( " QgsWmsProvider: exiting constructor." );
101
109
}
102
110
111
+ void QgsWmsProvider::setAuthentication ( QString uri )
112
+ {
113
+ // Strip off and store the user name and password (if they exist)
114
+ if ( ! uri.startsWith (" http:" ) )
115
+ {
116
+ // uri potentially contains username and password
117
+ QStringList parts = uri.split ( " ," );
118
+ QStringListIterator iter ( parts );
119
+ while ( iter.hasNext () )
120
+ {
121
+ QString item = iter.next ();
122
+ QgsDebugMsg ( " QgsWmsProvider: Testing for creds: " + item );
123
+ if ( item.startsWith ( " username=" ) )
124
+ {
125
+ mUserName = item.mid ( 9 );
126
+ QgsDebugMsg ( " QgsWmsProvider: Set username to " + mUserName );
127
+ }
128
+ else if ( item.startsWith ( " password=" ) )
129
+ {
130
+ mPassword = item.mid ( 9 );
131
+ QgsDebugMsg ( " QgsWmsProvider: Set password to " + mPassword );
132
+ }
133
+ else if ( item.startsWith ( " url=" ) )
134
+ {
135
+ // strip the authentication information from the front of the uri
136
+ httpuri = item.mid ( 4 );
137
+ QgsDebugMsg ( " QgsWmsProvider: Set httpuri to " + httpuri );
138
+ }
139
+ }
140
+
141
+ }
142
+
143
+ }
103
144
QString QgsWmsProvider::prepareUri ( QString uri )
104
145
{
105
146
if ( !( uri.contains ( " ?" ) ) )
@@ -221,6 +262,10 @@ void QgsWmsProvider::addLayers( QStringList const &layers,
221
262
QgsDebugMsg ( " Exiting." );
222
263
}
223
264
265
+ void QgsWmsProvider::setConnectionName ( QString const &connName )
266
+ {
267
+ connectionName = connName;
268
+ }
224
269
225
270
void QgsWmsProvider::setLayerOrder ( QStringList const &layers )
226
271
{
@@ -640,7 +685,9 @@ QByteArray QgsWmsProvider::retrieveUrl( QString url )
640
685
{
641
686
QgsDebugMsg ( " WMS request Url: " + url );
642
687
QgsHttpTransaction http ( url );
643
-
688
+ QgsDebugMsg ( " Setting creds: " + mUserName + " /" + mPassword );
689
+ http.setCredentials ( mUserName , mPassword );
690
+
644
691
// Do a passthrough for the status bar text
645
692
connect (
646
693
&http, SIGNAL ( statusChanged ( QString ) ),
0 commit comments