Re: [Qlandkartegt-users] Proxy authentication issue
Brought to you by:
kiozen
From: solitone <sol...@ma...> - 2012-09-25 16:36:03
|
Albrecht Dreß wrote: > Just a dumb question - wouldn't it be sufficient to just add the user > name and password to the call of > > > QNetworkProxy::setApplicationProxy(QNetworkProxy(QNetworkProxy::HttpProxy,m_httpProxy,m_httpProxyPort)); > > > in CResources::CResources()? After struggling with QT's proxy support (and reading the Getting Started to QT Programming doc), I eventually found out that it's not that straightforward. In my scenario, it is pointless to pass username and password to the QNetworkProxy constructor, as I pointed out in a previous message. Instead, in every class using proxy, I had to add a connection between the proxyAuthenticationRequired() signal and a slot that manages proxy authentication--something like this: > connect(&networkAccessManager, SIGNAL(proxyAuthenticationRequired(const QNetworkProxy&, QAuthenticator*)), > this, SLOT(slotProxyAuthenticationRequired(const QNetworkProxy&, QAuthenticator*))); The slot then picks up authentication data from my Windows registry, and passes them to the QAuthenticator object: > void CSearchDB::slotProxyAuthenticationRequired(const QNetworkProxy &prox, QAuthenticator *auth) > { > QString user; > QString pwd; > > CResources::self().getHttpProxyAuth(user,pwd); > > auth->setUser(user); > auth->setPassword(pwd); > } Here you can find a simple example of this technique: http://qt-project.org/forums/viewthread/20539/#98842 I found the proxy is set up in 11 classes. These are the source files that I tweaked: > Search "setProxy" (12 hits in 11 files) > C:\usr\qlandkartegt-1.5.1\src\CCreateMapWMS.cpp (1 hits) > Line 72: server->setProxy(url,port); > C:\usr\qlandkartegt-1.5.1\src\CDlgMapWmsConfig.cpp (1 hits) > Line 147: accessManager->setProxy(QNetworkProxy(QNetworkProxy::DefaultProxy)); > C:\usr\qlandkartegt-1.5.1\src\CMapTms.cpp (1 hits) > Line 87: accessManager->setProxy(QNetworkProxy(QNetworkProxy::DefaultProxy)); > C:\usr\qlandkartegt-1.5.1\src\CMapWms.cpp (1 hits) > Line 158: accessManager->setProxy(QNetworkProxy(QNetworkProxy::DefaultProxy)); > C:\usr\qlandkartegt-1.5.1\src\COsmTilesHash.cpp (1 hits) > Line 52: m_networkAccessManager->setProxy(QNetworkProxy(QNetworkProxy::DefaultProxy)); > C:\usr\qlandkartegt-1.5.1\src\CRouteToolWidget.cpp (2 hits) > Line 64: m_networkAccessManager->setProxy(QNetworkProxy(QNetworkProxy::DefaultProxy,url,port)); > Line 171: m_networkAccessManager->setProxy(QNetworkProxy(QNetworkProxy::DefaultProxy)); > C:\usr\qlandkartegt-1.5.1\src\CSearchDB.cpp (1 hits) > Line 44: networkAccessManager.setProxy(QNetworkProxy(QNetworkProxy::DefaultProxy)); > C:\usr\qlandkartegt-1.5.1\src\CTrack.cpp (1 hits) > Line 630: geonames->setProxy(QNetworkProxy(QNetworkProxy::DefaultProxy)); Hopefully I didn't miss any. Albrecht Dreß wrote: > Adding two more config elements and optionally tweaking > CResources::getHttpProxy() to pick up the authentication tokens from the > environment (although the latter is not a good idea from the security > pov) should then be trivial... At the moment, I manually added two keys for my proxy username and password to Windows registry. I understand your point on security, but I am currently unaware of what other options might be explored. Rather than changing the signature of CResources::getHttpProxy(), in the end I added another method to get the authentication tokens: > void CResources::getHttpProxyAuth(QString& user, QString& pwd) > { > // Proxy authentication support > user = m_httpProxyUser; > pwd = m_httpProxyPwd; > } I tested it and everything seems to work just fine! OpenStreet/CycleMaps are displayed, and both Google and OpenRouteService search do work as well. Please let me know whether I could perform some other test. The only thing missing is setting up proxy authentication data from the GUI--and not by manually editing the registry. I'm not a C++ / GT programmer, so it'll presumably take me some time. I would share the changes I made to the code. I know there's a diff tool that would be helpful, but I have to refresh my memory on how to take advantage of it. Any further suggestion is welcomed! |