Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
make SSL mode of PostgreSQL connections configuable
git-svn-id: http://svn.osgeo.org/qgis/trunk@10456 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Apr 2, 2009
1 parent e1d9527 commit 1e64ed3
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 31 deletions.
4 changes: 3 additions & 1 deletion python/core/qgsdatasourceuri.sip
Expand Up @@ -12,6 +12,7 @@ class QgsDataSourceURI
%End

public:
enum SSLmode { SSLprefer, SSLdisable, SSLallow, SSLrequire };

//! default constructor
QgsDataSourceURI();
Expand All @@ -33,7 +34,8 @@ public:
const QString& aPort,
const QString& aDatabase,
const QString& aUsername,
const QString& aPassword);
const QString& aPassword,
SSLmode sslmode );

//! Set all data source related members at once
void setDataSource(const QString& aSchema,
Expand Down
9 changes: 7 additions & 2 deletions src/app/qgsdbsourceselect.cpp
Expand Up @@ -240,6 +240,7 @@ void QgsDbSourceSelect::deleteConnection()
settings.remove( key + "/username" );
settings.remove( key + "/password" );
settings.remove( key + "/port" );
settings.remove( key + "/sslmode" );
settings.remove( key + "/save" );
settings.remove( key );
//if(!success){
Expand Down Expand Up @@ -373,7 +374,10 @@ void QgsDbSourceSelect::on_btnConnect_clicked()
settings.value( key + "/port" ).toString(),
database,
settings.value( key + "/username" ).toString(),
password );
password,
(QgsDataSourceURI::SSLmode) settings.value( key + "/sslmode", QgsDataSourceURI::SSLprefer ).toInt() );



bool searchPublicOnly = settings.value( key + "/publicOnly" ).toBool();
bool searchGeometryColumnsOnly = settings.value( key + "/geometryColumnsOnly" ).toBool();
Expand Down Expand Up @@ -410,7 +414,8 @@ void QgsDbSourceSelect::on_btnConnect_clicked()
settings.value( key + "/port" ).toString(),
database,
settings.value( key + "/username" ).toString(),
password );
password,
(QgsDataSourceURI::SSLmode) settings.value( key + "/sslmode", QgsDataSourceURI::SSLprefer ).toInt() );

m_connectionInfo = uri.connectionInfo();
PQfinish( pd );
Expand Down
9 changes: 8 additions & 1 deletion src/app/qgsnewconnection.cpp
Expand Up @@ -61,6 +61,12 @@ QgsNewConnection::QgsNewConnection( QWidget *parent, const QString& connName, Qt
// Ensure that cb_plublicSchemaOnly is set correctly
on_cb_geometryColumnsOnly_clicked();

cbxSSLmode->insertItem( QgsDataSourceURI::SSLprefer, tr("prefer") );
cbxSSLmode->insertItem( QgsDataSourceURI::SSLrequire, tr("require") );
cbxSSLmode->insertItem( QgsDataSourceURI::SSLallow, tr("allow") );
cbxSSLmode->insertItem( QgsDataSourceURI::SSLdisable, tr("disable") );
cbxSSLmode->setCurrentIndex( settings.value( key + "/sslmode", QgsDataSourceURI::SSLprefer ).toInt() );

if ( settings.value( key + "/save" ).toString() == "true" )
{
txtPassword->setText( settings.value( key + "/password" ).toString() );
Expand Down Expand Up @@ -108,7 +114,7 @@ QgsNewConnection::~QgsNewConnection()
void QgsNewConnection::testConnection()
{
QgsDataSourceURI uri;
uri.setConnection( txtHost->text(), txtPort->text(), txtDatabase->text(), txtUsername->text(), txtPassword->text() );
uri.setConnection( txtHost->text(), txtPort->text(), txtDatabase->text(), txtUsername->text(), txtPassword->text(), (QgsDataSourceURI::SSLmode) cbxSSLmode->currentIndex() );

QgsLogger::debug( "PQconnectdb(" + uri.connectionInfo() + ");" );

Expand Down Expand Up @@ -142,6 +148,7 @@ void QgsNewConnection::saveConnection()
settings.setValue( baseKey + "/publicOnly", cb_publicSchemaOnly->isChecked() );
settings.setValue( baseKey + "/geometryColumnsOnly", cb_geometryColumnsOnly->isChecked() );
settings.setValue( baseKey + "/save", chkStorePassword->isChecked() ? "true" : "false" );
settings.setValue( baseKey + "/sslmode", cbxSSLmode->currentIndex() );
accept();
}

Expand Down
33 changes: 29 additions & 4 deletions src/core/qgsdatasourceuri.cpp
Expand Up @@ -23,12 +23,12 @@
#include <QStringList>
#include <QRegExp>

QgsDataSourceURI::QgsDataSourceURI()
QgsDataSourceURI::QgsDataSourceURI() : mSSLmode(SSLprefer)
{
// do nothing
}

QgsDataSourceURI::QgsDataSourceURI( QString uri )
QgsDataSourceURI::QgsDataSourceURI( QString uri ) : mSSLmode(SSLprefer)
{
int i = 0;
while ( i < uri.length() )
Expand Down Expand Up @@ -146,7 +146,21 @@ QgsDataSourceURI::QgsDataSourceURI( QString uri )
}
else if ( pname == "sslmode" )
{
QgsDebugMsg( "sslmode ignored" );
if( pval == "disable" )
mSSLmode = SSLdisable;
else if( pval == "allow" )
mSSLmode = SSLallow;
else if( pval == "prefer" )
mSSLmode = SSLprefer;
else if( pval == "require" )
mSSLmode = SSLrequire;
}
else if ( pname == "requiressl" )
{
if( pval == "0" )
mSSLmode = SSLdisable;
else
mSSLmode = SSLprefer;
}
else if ( pname == "krbsrvname" )
{
Expand Down Expand Up @@ -293,6 +307,15 @@ QString QgsDataSourceURI::connectionInfo() const
}
}

if ( mSSLmode == SSLdisable )
connectionInfo += " sslmode=disable";
else if ( mSSLmode == SSLallow )
connectionInfo += " sslmode=allow";
else if ( mSSLmode == SSLrequire )
connectionInfo += " sslmode=require";
else if ( mSSLmode == SSLprefer )
connectionInfo += " sslmode=prefer";

return connectionInfo;
}

Expand All @@ -317,13 +340,15 @@ void QgsDataSourceURI::setConnection( const QString &host,
const QString &port,
const QString &database,
const QString &username,
const QString &password )
const QString &password,
SSLmode sslmode )
{
mHost = host;
mDatabase = database;
mPort = port;
mUsername = username;
mPassword = password;
mSSLmode = sslmode;
}

void QgsDataSourceURI::setDataSource( const QString &schema,
Expand Down
9 changes: 7 additions & 2 deletions src/core/qgsdatasourceuri.h
Expand Up @@ -29,8 +29,8 @@
*/
class CORE_EXPORT QgsDataSourceURI
{

public:
enum SSLmode { SSLprefer, SSLdisable, SSLallow, SSLrequire };

//! default constructor
QgsDataSourceURI();
Expand All @@ -52,19 +52,22 @@ class CORE_EXPORT QgsDataSourceURI
const QString& aPort,
const QString& aDatabase,
const QString& aUsername,
const QString& aPassword );
const QString& aPassword,
SSLmode sslmode );

//! Set all data source related members at once
void setDataSource( const QString& aSchema,
const QString& aTable,
const QString& aGeometryColumn,
const QString& aSql = QString() );


QString username() const;
QString schema() const;
QString table() const;
QString sql() const;
QString geometryColumn() const;
enum SSLmode sslMode() const;

void clearSchema();
void setSql( QString sql );
Expand Down Expand Up @@ -93,6 +96,8 @@ class CORE_EXPORT QgsDataSourceURI
QString mUsername;
//! password
QString mPassword;
//! ssl mode
enum SSLmode mSSLmode;
};

#endif //QGSDATASOURCEURI_H
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/spit/qgsspit.cpp
Expand Up @@ -413,7 +413,8 @@ void QgsSpit::dbConnect()
settings.value( key + "/port" ).toString(),
database,
settings.value( key + "/username" ).toString(),
password );
password,
(QgsDataSourceURI::SSLmode) settings.value( key + "/sslmode", QgsDataSourceURI::SSLprefer ).toInt() );

conn = PQconnectdb( uri.connectionInfo().toUtf8() );
}
Expand Down
48 changes: 28 additions & 20 deletions src/ui/qgsnewconnectionbase.ui
Expand Up @@ -6,13 +6,11 @@
<x>0</x>
<y>0</y>
<width>509</width>
<height>335</height>
<height>402</height>
</rect>
</property>
<property name="sizePolicy" >
<sizepolicy>
<hsizetype>3</hsizetype>
<vsizetype>3</vsizetype>
<sizepolicy vsizetype="MinimumExpanding" hsizetype="MinimumExpanding" >
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
Expand Down Expand Up @@ -93,12 +91,12 @@
</item>
<item row="1" column="1" >
<layout class="QHBoxLayout" >
<property name="margin" >
<number>0</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<property name="margin" >
<number>0</number>
</property>
<item>
<widget class="QCheckBox" name="chkStorePassword" >
<property name="text" >
Expand All @@ -117,20 +115,20 @@
</item>
<item row="0" column="1" >
<layout class="QHBoxLayout" >
<property name="margin" >
<number>0</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<property name="margin" >
<number>0</number>
</property>
<item>
<layout class="QVBoxLayout" >
<property name="margin" >
<number>0</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<property name="margin" >
<number>0</number>
</property>
<item>
<widget class="QLabel" name="TextLabel1_2" >
<property name="text" >
Expand Down Expand Up @@ -191,16 +189,23 @@
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="TextLabel3_3" >
<property name="text" >
<string>SSL mode</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" >
<property name="margin" >
<number>0</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<property name="margin" >
<number>0</number>
</property>
<item>
<widget class="QLineEdit" name="txtName" >
<property name="toolTip" >
Expand Down Expand Up @@ -231,6 +236,9 @@
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="cbxSSLmode" />
</item>
</layout>
</item>
</layout>
Expand All @@ -240,12 +248,12 @@
</item>
<item row="0" column="1" >
<layout class="QVBoxLayout" >
<property name="margin" >
<number>0</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<property name="margin" >
<number>0</number>
</property>
<item>
<widget class="QPushButton" name="btnOk" >
<property name="text" >
Expand Down Expand Up @@ -299,7 +307,7 @@
<property name="sizeType" >
<enum>QSizePolicy::Expanding</enum>
</property>
<property name="sizeHint" >
<property name="sizeHint" stdset="0" >
<size>
<width>87</width>
<height>150</height>
Expand Down

0 comments on commit 1e64ed3

Please sign in to comment.