Skip to content

Commit 1e64ed3

Browse files
author
jef
committed
make SSL mode of PostgreSQL connections configuable
git-svn-id: http://svn.osgeo.org/qgis/trunk@10456 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent e1d9527 commit 1e64ed3

File tree

7 files changed

+84
-31
lines changed

7 files changed

+84
-31
lines changed

python/core/qgsdatasourceuri.sip

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class QgsDataSourceURI
1212
%End
1313

1414
public:
15+
enum SSLmode { SSLprefer, SSLdisable, SSLallow, SSLrequire };
1516

1617
//! default constructor
1718
QgsDataSourceURI();
@@ -33,7 +34,8 @@ public:
3334
const QString& aPort,
3435
const QString& aDatabase,
3536
const QString& aUsername,
36-
const QString& aPassword);
37+
const QString& aPassword,
38+
SSLmode sslmode );
3739

3840
//! Set all data source related members at once
3941
void setDataSource(const QString& aSchema,

src/app/qgsdbsourceselect.cpp

+7-2
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ void QgsDbSourceSelect::deleteConnection()
240240
settings.remove( key + "/username" );
241241
settings.remove( key + "/password" );
242242
settings.remove( key + "/port" );
243+
settings.remove( key + "/sslmode" );
243244
settings.remove( key + "/save" );
244245
settings.remove( key );
245246
//if(!success){
@@ -373,7 +374,10 @@ void QgsDbSourceSelect::on_btnConnect_clicked()
373374
settings.value( key + "/port" ).toString(),
374375
database,
375376
settings.value( key + "/username" ).toString(),
376-
password );
377+
password,
378+
(QgsDataSourceURI::SSLmode) settings.value( key + "/sslmode", QgsDataSourceURI::SSLprefer ).toInt() );
379+
380+
377381

378382
bool searchPublicOnly = settings.value( key + "/publicOnly" ).toBool();
379383
bool searchGeometryColumnsOnly = settings.value( key + "/geometryColumnsOnly" ).toBool();
@@ -410,7 +414,8 @@ void QgsDbSourceSelect::on_btnConnect_clicked()
410414
settings.value( key + "/port" ).toString(),
411415
database,
412416
settings.value( key + "/username" ).toString(),
413-
password );
417+
password,
418+
(QgsDataSourceURI::SSLmode) settings.value( key + "/sslmode", QgsDataSourceURI::SSLprefer ).toInt() );
414419

415420
m_connectionInfo = uri.connectionInfo();
416421
PQfinish( pd );

src/app/qgsnewconnection.cpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ QgsNewConnection::QgsNewConnection( QWidget *parent, const QString& connName, Qt
6161
// Ensure that cb_plublicSchemaOnly is set correctly
6262
on_cb_geometryColumnsOnly_clicked();
6363

64+
cbxSSLmode->insertItem( QgsDataSourceURI::SSLprefer, tr("prefer") );
65+
cbxSSLmode->insertItem( QgsDataSourceURI::SSLrequire, tr("require") );
66+
cbxSSLmode->insertItem( QgsDataSourceURI::SSLallow, tr("allow") );
67+
cbxSSLmode->insertItem( QgsDataSourceURI::SSLdisable, tr("disable") );
68+
cbxSSLmode->setCurrentIndex( settings.value( key + "/sslmode", QgsDataSourceURI::SSLprefer ).toInt() );
69+
6470
if ( settings.value( key + "/save" ).toString() == "true" )
6571
{
6672
txtPassword->setText( settings.value( key + "/password" ).toString() );
@@ -108,7 +114,7 @@ QgsNewConnection::~QgsNewConnection()
108114
void QgsNewConnection::testConnection()
109115
{
110116
QgsDataSourceURI uri;
111-
uri.setConnection( txtHost->text(), txtPort->text(), txtDatabase->text(), txtUsername->text(), txtPassword->text() );
117+
uri.setConnection( txtHost->text(), txtPort->text(), txtDatabase->text(), txtUsername->text(), txtPassword->text(), (QgsDataSourceURI::SSLmode) cbxSSLmode->currentIndex() );
112118

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

@@ -142,6 +148,7 @@ void QgsNewConnection::saveConnection()
142148
settings.setValue( baseKey + "/publicOnly", cb_publicSchemaOnly->isChecked() );
143149
settings.setValue( baseKey + "/geometryColumnsOnly", cb_geometryColumnsOnly->isChecked() );
144150
settings.setValue( baseKey + "/save", chkStorePassword->isChecked() ? "true" : "false" );
151+
settings.setValue( baseKey + "/sslmode", cbxSSLmode->currentIndex() );
145152
accept();
146153
}
147154

src/core/qgsdatasourceuri.cpp

+29-4
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@
2323
#include <QStringList>
2424
#include <QRegExp>
2525

26-
QgsDataSourceURI::QgsDataSourceURI()
26+
QgsDataSourceURI::QgsDataSourceURI() : mSSLmode(SSLprefer)
2727
{
2828
// do nothing
2929
}
3030

31-
QgsDataSourceURI::QgsDataSourceURI( QString uri )
31+
QgsDataSourceURI::QgsDataSourceURI( QString uri ) : mSSLmode(SSLprefer)
3232
{
3333
int i = 0;
3434
while ( i < uri.length() )
@@ -146,7 +146,21 @@ QgsDataSourceURI::QgsDataSourceURI( QString uri )
146146
}
147147
else if ( pname == "sslmode" )
148148
{
149-
QgsDebugMsg( "sslmode ignored" );
149+
if( pval == "disable" )
150+
mSSLmode = SSLdisable;
151+
else if( pval == "allow" )
152+
mSSLmode = SSLallow;
153+
else if( pval == "prefer" )
154+
mSSLmode = SSLprefer;
155+
else if( pval == "require" )
156+
mSSLmode = SSLrequire;
157+
}
158+
else if ( pname == "requiressl" )
159+
{
160+
if( pval == "0" )
161+
mSSLmode = SSLdisable;
162+
else
163+
mSSLmode = SSLprefer;
150164
}
151165
else if ( pname == "krbsrvname" )
152166
{
@@ -293,6 +307,15 @@ QString QgsDataSourceURI::connectionInfo() const
293307
}
294308
}
295309

310+
if ( mSSLmode == SSLdisable )
311+
connectionInfo += " sslmode=disable";
312+
else if ( mSSLmode == SSLallow )
313+
connectionInfo += " sslmode=allow";
314+
else if ( mSSLmode == SSLrequire )
315+
connectionInfo += " sslmode=require";
316+
else if ( mSSLmode == SSLprefer )
317+
connectionInfo += " sslmode=prefer";
318+
296319
return connectionInfo;
297320
}
298321

@@ -317,13 +340,15 @@ void QgsDataSourceURI::setConnection( const QString &host,
317340
const QString &port,
318341
const QString &database,
319342
const QString &username,
320-
const QString &password )
343+
const QString &password,
344+
SSLmode sslmode )
321345
{
322346
mHost = host;
323347
mDatabase = database;
324348
mPort = port;
325349
mUsername = username;
326350
mPassword = password;
351+
mSSLmode = sslmode;
327352
}
328353

329354
void QgsDataSourceURI::setDataSource( const QString &schema,

src/core/qgsdatasourceuri.h

+7-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
*/
3030
class CORE_EXPORT QgsDataSourceURI
3131
{
32-
3332
public:
33+
enum SSLmode { SSLprefer, SSLdisable, SSLallow, SSLrequire };
3434

3535
//! default constructor
3636
QgsDataSourceURI();
@@ -52,19 +52,22 @@ class CORE_EXPORT QgsDataSourceURI
5252
const QString& aPort,
5353
const QString& aDatabase,
5454
const QString& aUsername,
55-
const QString& aPassword );
55+
const QString& aPassword,
56+
SSLmode sslmode );
5657

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

64+
6365
QString username() const;
6466
QString schema() const;
6567
QString table() const;
6668
QString sql() const;
6769
QString geometryColumn() const;
70+
enum SSLmode sslMode() const;
6871

6972
void clearSchema();
7073
void setSql( QString sql );
@@ -93,6 +96,8 @@ class CORE_EXPORT QgsDataSourceURI
9396
QString mUsername;
9497
//! password
9598
QString mPassword;
99+
//! ssl mode
100+
enum SSLmode mSSLmode;
96101
};
97102

98103
#endif //QGSDATASOURCEURI_H

src/plugins/spit/qgsspit.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,8 @@ void QgsSpit::dbConnect()
413413
settings.value( key + "/port" ).toString(),
414414
database,
415415
settings.value( key + "/username" ).toString(),
416-
password );
416+
password,
417+
(QgsDataSourceURI::SSLmode) settings.value( key + "/sslmode", QgsDataSourceURI::SSLprefer ).toInt() );
417418

418419
conn = PQconnectdb( uri.connectionInfo().toUtf8() );
419420
}

src/ui/qgsnewconnectionbase.ui

+28-20
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,11 @@
66
<x>0</x>
77
<y>0</y>
88
<width>509</width>
9-
<height>335</height>
9+
<height>402</height>
1010
</rect>
1111
</property>
1212
<property name="sizePolicy" >
13-
<sizepolicy>
14-
<hsizetype>3</hsizetype>
15-
<vsizetype>3</vsizetype>
13+
<sizepolicy vsizetype="MinimumExpanding" hsizetype="MinimumExpanding" >
1614
<horstretch>0</horstretch>
1715
<verstretch>0</verstretch>
1816
</sizepolicy>
@@ -93,12 +91,12 @@
9391
</item>
9492
<item row="1" column="1" >
9593
<layout class="QHBoxLayout" >
96-
<property name="margin" >
97-
<number>0</number>
98-
</property>
9994
<property name="spacing" >
10095
<number>6</number>
10196
</property>
97+
<property name="margin" >
98+
<number>0</number>
99+
</property>
102100
<item>
103101
<widget class="QCheckBox" name="chkStorePassword" >
104102
<property name="text" >
@@ -117,20 +115,20 @@
117115
</item>
118116
<item row="0" column="1" >
119117
<layout class="QHBoxLayout" >
120-
<property name="margin" >
121-
<number>0</number>
122-
</property>
123118
<property name="spacing" >
124119
<number>6</number>
125120
</property>
121+
<property name="margin" >
122+
<number>0</number>
123+
</property>
126124
<item>
127125
<layout class="QVBoxLayout" >
128-
<property name="margin" >
129-
<number>0</number>
130-
</property>
131126
<property name="spacing" >
132127
<number>6</number>
133128
</property>
129+
<property name="margin" >
130+
<number>0</number>
131+
</property>
134132
<item>
135133
<widget class="QLabel" name="TextLabel1_2" >
136134
<property name="text" >
@@ -191,16 +189,23 @@
191189
</property>
192190
</widget>
193191
</item>
192+
<item>
193+
<widget class="QLabel" name="TextLabel3_3" >
194+
<property name="text" >
195+
<string>SSL mode</string>
196+
</property>
197+
</widget>
198+
</item>
194199
</layout>
195200
</item>
196201
<item>
197202
<layout class="QVBoxLayout" >
198-
<property name="margin" >
199-
<number>0</number>
200-
</property>
201203
<property name="spacing" >
202204
<number>6</number>
203205
</property>
206+
<property name="margin" >
207+
<number>0</number>
208+
</property>
204209
<item>
205210
<widget class="QLineEdit" name="txtName" >
206211
<property name="toolTip" >
@@ -231,6 +236,9 @@
231236
</property>
232237
</widget>
233238
</item>
239+
<item>
240+
<widget class="QComboBox" name="cbxSSLmode" />
241+
</item>
234242
</layout>
235243
</item>
236244
</layout>
@@ -240,12 +248,12 @@
240248
</item>
241249
<item row="0" column="1" >
242250
<layout class="QVBoxLayout" >
243-
<property name="margin" >
244-
<number>0</number>
245-
</property>
246251
<property name="spacing" >
247252
<number>6</number>
248253
</property>
254+
<property name="margin" >
255+
<number>0</number>
256+
</property>
249257
<item>
250258
<widget class="QPushButton" name="btnOk" >
251259
<property name="text" >
@@ -299,7 +307,7 @@
299307
<property name="sizeType" >
300308
<enum>QSizePolicy::Expanding</enum>
301309
</property>
302-
<property name="sizeHint" >
310+
<property name="sizeHint" stdset="0" >
303311
<size>
304312
<width>87</width>
305313
<height>150</height>

0 commit comments

Comments
 (0)