<div dir="ltr"><div style>Hi all,</div><div style><br></div><div style>I've been working on accessing protected layers in GeoServer via WFS from QGIS. I ran into some problems, similar to those described by someone on the mailing list a couple of years ago (except I'm using WFS rather than WMS). I've found a workaround that is enough for my current needs.</div>
<div style><br></div><div style>First off, as far as I can tell, entering WFS basic auth credentials when creating the layer does not help in any way. Auth won't be done unless the server demands it, and then it will always ask the user for them again anyway (I'm using QGIS from master, at commit <span style="font-size:12.727272033691406px;font-family:arial,sans-serif">d68524</span>). There is an open bug related to this:</div>
<div style> <a href="http://hub.qgis.org/issues/6609">http://hub.qgis.org/issues/6609</a><br></div><div style><br></div><div style>As for accessing protected layers, I found that the problem was that QGIS first tries to do the GetCapabilities without credentials, and only prompts the user for them if the anonymous request was denied by the server. Usually an anonymous request will succeed, showing all the public layers, and the user won't have a chance to get at the protected layers. The same thing is done by MapInfo, by the way.</div>
<div style><br></div><div style>My workaround for this was to have the Apache running in front of GeoServer force authentication in certain cases.</div><div style><br></div><div style>Instead of using a WFS url like:</div>
<div style> <a href="http://myserver.com/geoserver/wfs">http://myserver.com/geoserver/wfs</a></div><div style><br></div><div style><div>I enter it as:</div><div> <a href="http://myserver.com/geoserver/wfs?forcebasicauth=true">http://myserver.com/geoserver/wfs?forcebasicauth=true</a></div>
<div><br></div><div>Then I have apache intercept requests with that special query string as follows:</div><div><br></div><div><div> RewriteEngine On</div><div> RewriteCond %{HTTP:Authorization} ^$</div><div>
RewriteCond %{QUERY_STRING} forcebasicauth=true</div><div> RewriteRule .* /var/www/forcebasicauth.php [L]<br></div></div><div><br></div></div><div style>So that if the request has no auth details, it will be passed to a small PHP handler that will request them:</div>
<div style><br></div><div style> <?php header('WWW-Authenticate: Basic realm="main"', true, 401); ?></div><div style><br></div><div style>All requests with auth details will get passed through to GeoServer as usual, as wil anything without the forcebasicauth key.</div>
<div style>I tried to do this without PHP but couldn't get both the 401 http code and the header to be returned conditionally in pure Apache config (the code is enough for MapInfo, QGIS needs the correct header too).</div>
<div style><br></div><div style>Cheers,</div><div style>Chris</div><div><br></div><div><br></div>========================================<br><a href="http://lists.osgeo.org/pipermail/qgis-user/2011-March/011580.html">http://lists.osgeo.org/pipermail/qgis-user/2011-March/011580.html</a><div>
<br>[Qgis-user] qGIS and GeoServer security<br><br>Jeff Dege jeff.dege at <a href="http://korterra.com">korterra.com</a> <br>Thu Mar 24 14:13:21 EDT 2011<br><br>Previous message: [Qgis-user] qgis microblogging<br>Next message: [Qgis-user] Arbitrary CRS<br>
Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]<br><br>________________________________<br><br>I'm playing around with the security settings on a GeoServer site.<br><br>In GeoServer, I can set the "Catalog mode":<br>
Catalog mode configuration - mode=HIDE|CHALLENGE|MIXED<br>Set the catalog mode level<br><br>hide (default): does not show to the user the layers that he cannot access, behaves as if a layer was read only if the user does not have write permissins. The capabilities document do not contain the clayers the current user cannot access to. This is the highest security mode, it assumes a privileged user has logged in before showing him the secured layers. Because of this, it does not work very well with clients such as uDig or Google Earth, where the authentication dialog pops up only if the server returns a HTTP 401 after attempting to access a secured resource.<br>
<br>challenge: allows free access to metadata, any attempt at accessing actual data is metby a HTTP 401 code that forces most clients to show an authentication dialog. The capabilities do contain the full list of layers, DescribeFeatureType and DescribeCoverage do work fine, the first attempt to access the actual data without the necessary privileges is met with a 401 error. This mode works fine with capabilities driven clients such as uDig, and with any client that needs a 401 in order to trigger an authentication dialog.<br>
<br>mixed: hides the layers the user cannot read from the capabilities, but triggers authentication for any other attempt to access the data or the metadata. Useful if you don't want the world to see the very existence of some of your data, but you still want selected people whom you give direct data access links to get the data after authentication.<br>
<br>When I set the mode to challenge, and do a Connect from the "Add Layer(s) from a Server" dialog, I see all the layers. If I try to add one to the map, I get a "Enter Credentials" dialog, where I can enter Username and Password, and if correct I see the layer in the map.<br>
<br>When I set the mode to hide, and do a Connect, I don't see the layers.<br><br>But here's the thing. All of the above is with the User name and Password fields of the "Create a new WMS connection" dialog blank. And the above is the behavior I'd expect, with those fields blank.<br>
<br>But if I fill in username and password, in the connection dialog, I still get the same behavior. I'd expect to be able to see the authenticated-only layers, in the getCapabilities XML, and hence in the layer list in the qGIS dialog, if the user name and password are correct. I'm not seeing that.<br>
<br>In fact, it looks as if it makes no difference whatsoever whether I enter a username and password when defining a WMS connection.<br><br>Am I misunderstanding what the username and password fields are for? Or are they not working? Or is GeoServer handling something incorrectly?<br>
<br>-------------- next part --------------<br>An HTML attachment was scrubbed...<br>URL: <a href="http://lists.osgeo.org/pipermail/qgis-user/attachments/20110324/6fd68d4f/attachment.html">http://lists.osgeo.org/pipermail/qgis-user/attachments/20110324/6fd68d4f/attachment.html</a><br>
<br>________________________________<br><br>Previous message: [Qgis-user] qgis microblogging<br>Next message: [Qgis-user] Arbitrary CRS<br>Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]<br><br>________________________________<br>
More information about the Qgis-user mailing list</div></div>