Skip to content
Permalink
Browse files

use QgsCredentials to request wms/ows credentials on demand and wms c…

…leanups (fixes #11184)
  • Loading branch information
jef-n committed Oct 21, 2014
1 parent 4bcde11 commit 3bdb104a0164c4db3549013e41a497af7b0701e1
@@ -11,6 +11,7 @@ class QgsOWSConnection : QObject
* @param theConnName connection name
*/
QgsOWSConnection( const QString & theService, const QString & theConnName );

//! Destructor
~QgsOWSConnection();

@@ -21,10 +22,9 @@ class QgsOWSConnection : QObject
static QString selectedConnection( const QString & theService );
static void setSelectedConnection( const QString & theService, const QString & name );

public:
//QgsDataProvider *provider();
QString connectionInfo();
QString mConnName;
QString mConnectionInfo;
QgsDataSourceURI uri();
QString mConnectionInfo;

QString connectionInfo() /Deprecated/;
};
@@ -9949,6 +9949,21 @@ void QgisApp::namAuthenticationRequired( QNetworkReply *reply, QAuthenticator *a
QString username = auth->user();
QString password = auth->password();

if ( username.isEmpty() && password.isEmpty() && reply->request().hasRawHeader( "Authorization" ) )
{
QByteArray header( reply->request().rawHeader( "Authorization" ) );
if ( header.startsWith( "Basic " ) )
{
QByteArray auth( QByteArray::fromBase64( header.mid( 6 ) ) );
int pos = auth.indexOf( ":" );
if ( pos >= 0 )
{
username = auth.left( pos );
password = auth.mid( pos + 1 );
}
}
}

{
QMutexLocker lock( QgsCredentials::instance()->mutex() );

@@ -57,11 +57,6 @@ QgsOWSConnection::QgsOWSConnection( const QString & theService, const QString &
if ( !username.isEmpty() )
{
// check for a password, if none prompt to get it
if ( password.isEmpty() )
{
password = QInputDialog::getText( 0, tr( "WMS Password for %1" ).arg( mConnName ), tr( "Password" ), QLineEdit::Password );
}
mConnectionInfo = "username=" + username + ",password=" + password + ",url=" + mConnectionInfo;
mUri.setParam( "username", username );
mUri.setParam( "password", password );
}
@@ -87,7 +82,7 @@ QgsOWSConnection::QgsOWSConnection( const QString & theService, const QString &
mUri.setParam( "InvertAxisOrientation", "1" );
}

QgsDebugMsg( QString( "Connection info: '%1'." ).arg( mConnectionInfo ) );
QgsDebugMsg( QString( "encoded uri: '%1'." ).arg( QString( mUri.encodedUri() ) ) );
}

QgsOWSConnection::~QgsOWSConnection()
@@ -105,24 +100,6 @@ QgsDataSourceURI QgsOWSConnection::uri()
return mUri;
}

#if 0
QgsDataProvider * QgsOWSConnection::provider()
{
// TODO: remove completely from this class?

// load the server data provider plugin
QgsProviderRegistry * pReg = QgsProviderRegistry::instance();

//QMap<QString,QString> keys;

QgsDataProvider *provider =
( QgsDataProvider* ) pReg->provider( "wms", mUri.encodedUri() );

return provider;
}
#endif


QStringList QgsOWSConnection::connectionList( const QString & theService )
{
QSettings settings;
@@ -27,20 +27,11 @@
#include <QStringList>
#include <QPushButton>

class QgisApp;
//class QgsDataProvider;
class QgsDataProvider;
/*class QButtonGroup;*/
/*class QgsNumericSortTreeWidgetItem;*/
class QDomDocument;
class QDomElement;

/*!
* \brief Connections management
*/
class CORE_EXPORT QgsOWSConnection : public QObject
{
// Q_OBJECT

public:
/**
@@ -49,6 +40,7 @@ class CORE_EXPORT QgsOWSConnection : public QObject
* @param theConnName connection name
*/
QgsOWSConnection( const QString & theService, const QString & theConnName );

//! Destructor
~QgsOWSConnection();

@@ -59,12 +51,12 @@ class CORE_EXPORT QgsOWSConnection : public QObject
static QString selectedConnection( const QString & theService );
static void setSelectedConnection( const QString & theService, const QString & name );

public:
//QgsDataProvider *provider();
QString connectionInfo();
QString mConnName;
QString mConnectionInfo;
QgsDataSourceURI uri();
QString mConnectionInfo;

Q_DECL_DEPRECATED QString connectionInfo();

private:
QgsDataSourceURI mUri;
QString mService;
@@ -351,8 +351,6 @@ void QgsOWSSourceSelect::on_mConnectButton_clicked()
mConnName = mConnectionsComboBox->currentText();

QgsOWSConnection connection( mService, mConnectionsComboBox->currentText() );
//QgsDataProvider *theProvider = connection.provider();
mConnectionInfo = connection.connectionInfo();
mUri = connection.uri();

QApplication::setOverrideCursor( Qt::WaitCursor );
@@ -48,21 +48,13 @@ QgsWMSConnection::QgsWMSConnection( QString theConnName ) :

QStringList connStringParts;

mConnectionInfo = settings.value( key + "/url" ).toString();
mUri.setParam( "url", settings.value( key + "/url" ).toString() );

// Check for credentials and prepend to the connection info
QString username = settings.value( credentialsKey + "/username" ).toString();
QString password = settings.value( credentialsKey + "/password" ).toString();
if ( !username.isEmpty() )
{
// check for a password, if none prompt to get it
if ( password.isEmpty() )
{
//password = QInputDialog::getText( this, tr( "WMS Password for %1" ).arg( theConnName ), "Password", QLineEdit::Password );
password = QInputDialog::getText( 0, tr( "WMS Password for %1" ).arg( mConnName ), "Password", QLineEdit::Password );
}
mConnectionInfo = "username=" + username + ",password=" + password + ",url=" + mConnectionInfo;
mUri.setParam( "username", username );
mUri.setParam( "password", password );
}
@@ -80,83 +72,49 @@ QgsWMSConnection::QgsWMSConnection( QString theConnName ) :
bool smoothPixmapTransform = settings.value( key + "/smoothPixmapTransform", false ).toBool();
QString dpiMode = settings.value( key + "/dpiMode", "all" ).toString();

QString connArgs, delim;

if ( ignoreGetMap )
{
connArgs += delim + "GetMap";
delim = ";";
mUri.setParam( "IgnoreGetMapUrl", "1" );
}

if ( ignoreGetFeatureInfo )
{
connArgs += delim + "GetFeatureInfo";
delim = ";";
mUri.setParam( "IgnoreGetFeatureInfoUrl", "1" );
}

if ( ignoreAxisOrientation )
{
connArgs += delim + "AxisOrientation";
delim = ";";
mUri.setParam( "IgnoreAxisOrientation", "1" );
}

if ( invertAxisOrientation )
{
connArgs += delim + "InvertAxisOrientation";
delim = ";";
mUri.setParam( "InvertAxisOrientation", "1" );
}

if ( smoothPixmapTransform )
{
connArgs += delim + "SmoothPixmapTransform";
delim = ";";
mUri.setParam( "SmoothPixmapTransform", "1" );
}

if ( !dpiMode.isEmpty() )
{
connArgs += delim + "dpiMode=" + dpiMode;
delim = ";";
mUri.setParam( "dpiMode", dpiMode );
}

if ( !connArgs.isEmpty() )
{
connArgs.prepend( "ignoreUrl=" );

if ( mConnectionInfo.startsWith( "username=" ) )
{
mConnectionInfo.prepend( connArgs + "," );
}
else
{
mConnectionInfo.prepend( connArgs + ",url=" );
}
}

QgsDebugMsg( QString( "Connection info: '%1'." ).arg( mConnectionInfo ) );
QgsDebugMsg( QString( "encodedUri: '%1'." ).arg( QString( mUri.encodedUri() ) ) );
}

QgsWMSConnection::~QgsWMSConnection()
{

}

QString QgsWMSConnection::connectionInfo()
{
return mConnectionInfo;
}

QgsDataSourceURI QgsWMSConnection::uri()
{
return mUri;
}


QStringList QgsWMSConnection::connectionList()
{
QSettings settings;
@@ -17,18 +17,10 @@

#ifndef QGSWMSCONNECTION_H
#define QGSWMSCONNECTION_H

#include "qgsdatasourceuri.h"
#include "qgisgui.h"
//#include "qgscontexthelp.h"

#include <QStringList>
#include <QPushButton>

class QgisApp;
/*class QButtonGroup;*/
/*class QgsNumericSortTreeWidgetItem;*/
class QDomDocument;
class QDomElement;

/*!
* \brief Connections management
@@ -50,14 +42,10 @@ class QgsWMSConnection : public QObject
static QString selectedConnection();
static void setSelectedConnection( QString name );


public:
QString connectionInfo();
QString mConnName;
QString mConnectionInfo;
QgsDataSourceURI uri();
QgsDataSourceURI mUri;
};


#endif // QGSWMSCONNECTION_H
@@ -434,7 +434,6 @@ void QgsWMSSourceSelect::on_btnConnect_clicked()
mConnName = cmbConnections->currentText();

QgsWMSConnection connection( cmbConnections->currentText() );
mConnectionInfo = connection.connectionInfo();
mUri = connection.uri();

QgsWmsSettings wmsSettings;
@@ -983,11 +982,6 @@ QString QgsWMSSourceSelect::connName()
return mConnName;
}

QString QgsWMSSourceSelect::connectionInfo()
{
return mConnectionInfo;
}

void QgsWMSSourceSelect::collectSelectedLayers( QStringList &layers, QStringList &styles, QStringList &titles )
{
//go through list in layer order tab
@@ -104,21 +104,6 @@ class QgsWMSSourceSelect : public QDialog, private Ui::QgsWMSSourceSelectBase
//! Connection name
QString connName();

//! Connection info (uri)
QString connectionInfo();

//! Connection Proxy Host
QString connProxyHost();

//! Connection Proxy Port
int connProxyPort();

//! Connection Proxy User
QString connProxyUser();

//! Connection Proxy Pass
QString connProxyPass();

//! Set the server connection combo box to that stored in the config file.
void setConnectionListPosition();

@@ -180,7 +165,6 @@ class QgsWMSSourceSelect : public QDialog, private Ui::QgsWMSSourceSelectBase
QString mConnName;

//! URI for selected connection
QString mConnectionInfo;
QgsDataSourceURI mUri;

//! layer name derived from latest layer selection (updated as long it's not edited manually)

0 comments on commit 3bdb104

Please sign in to comment.
You can’t perform that action at this time.