Skip to content

Commit c5281aa

Browse files
jwkaltzsbrunner
authored andcommitted
add an authentication_required option (#4839)
Add an authentication_required option Authored-By: jwkaltz <[email protected]>
1 parent 3ac63ce commit c5281aa

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

c2cgeoportal/tests/functional/test_mapserverproxy.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -972,3 +972,14 @@ def test_geoserver(self):
972972
))
973973
response = MapservProxy(request).proxy()
974974
self.assert_contains(response.body, u"<Name>testpoint_protected</Name>")
975+
976+
def test_authentication_required(self):
977+
from c2cgeoportal.views.mapserverproxy import MapservProxy
978+
from pyramid.httpexceptions import HTTPUnauthorized
979+
980+
request = self._create_getcap_request()
981+
request.params.update(dict(
982+
service="wms", version="1.1.1", request="getcapabilities",
983+
authentication_required="true"
984+
))
985+
self.assertRaises(HTTPUnauthorized, MapservProxy(request).proxy)

c2cgeoportal/views/mapserverproxy.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
import logging
3232

33+
from pyramid.httpexceptions import HTTPUnauthorized
3334
from pyramid.view import view_config
3435

3536
from c2cgeoportal.lib.caching import get_region, NO_CACHE, PUBLIC_CACHE, PRIVATE_CACHE
@@ -51,6 +52,10 @@ def __init__(self, request):
5152
@view_config(route_name="mapserverproxy")
5253
def proxy(self):
5354

55+
if self.user is None and "authentication_required" in self.request.params:
56+
log.debug("proxy() detected authentication_required")
57+
raise HTTPUnauthorized(headers={"WWW-Authenticate": 'Basic realm="Access to restricted layers"'})
58+
5459
if self.user is not None:
5560
# We have a user logged in. We need to set group_id and
5661
# possible layer_name in the params. We set layer_name

doc/integrator/security.rst

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,27 @@ the WMS GetCapability when accessing the Mapserver proxy (mapserverproxy).
1111

1212
Default: ``false``
1313

14+
Force authentication when accessing the Mapserver proxy
15+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
16+
17+
If your WMS contains private layers and you wish to force a client to authenticate
18+
in order to always obtain all layers (including private layers), you can force
19+
authentication by adding the parameter ``authentication_required`` to the WMS URL.
20+
This setting may be necessary for the good operation of some clients such as ArcMap.
21+
22+
For example, if your WMS is accessible as
23+
24+
.. code:: html
25+
26+
https://<yourserver>/<yourinstance>/wsgi/mapserv_proxy
27+
28+
then you can use the following URL to force authentication:
29+
30+
.. code:: html
31+
32+
https://<yourserver>/<yourinstance>/wsgi/mapserv_proxy?authentication_required=true
33+
34+
1435
Enable / Disable the admin interface
1536
------------------------------------
1637

0 commit comments

Comments
 (0)