Exemplo n.º 1
0
    def _wms_getcap(self, url):
        if url.find('?') < 0:
            url += '?'

        # add functionalities params
        sparams = get_mapserver_substitution_params(self.request)
        if sparams:  # pragma: no cover
            url += urllib.urlencode(sparams) + '&'

        return self._wms_getcap_cached(url)
Exemplo n.º 2
0
    def _wfs_types(self, wfs_url, role_id):
        if wfs_url.find('?') < 0:
            wfs_url += '?'

        # add functionalities query_string
        sparams = get_mapserver_substitution_params(self.request)
        if sparams:  # pragma: no cover
            wfs_url += urllib.urlencode(sparams) + '&'

        if role_id is not None:
            wfs_url += "role_id=%s&" % role_id

        return self._wfs_types_cached(wfs_url)
Exemplo n.º 3
0
    def proxy(self):

        self.user = self.request.user
        self.external = bool(self.request.params.get("EXTERNAL", None))

        # params hold the parameters we"re going to send to MapServer
        params = dict(self.request.params)

        # reset possible value of role_id and user_id
        if "role_id" in params:  # pragma: no cover
            del params["role_id"]
        if "user_id" in params:  # pragma: no cover
            del params["user_id"]

        self.lower_params = self._get_lower_params(params)

        if self.user is not None:
            # We have a user logged in. We need to set group_id and
            # possible layer_name in the params. We set layer_name
            # when either QUERY_PARAMS or LAYERS is set in the
            # WMS params, i.e. for GetMap and GetFeatureInfo
            # requests. For GetLegendGraphic requests we don't
            # send layer_name, but MapServer shouldn't use the DATA
            # string for GetLegendGraphic.

            params["role_id"] = self.user.parent_role.id if self.external else self.user.role.id

            # In some application we want to display the features owned by a user
            # than we need his id.
            if not self.external:
                params["user_id"] = self.user.id  # pragma: nocover

        # don't allows direct variable substitution
        for k in params.keys():
            if k[:2].capitalize() == "S_":
                log.warning("Direct substitution not allowed (%s=%s)." %
                            (k, params[k]))
                del params[k]

        # add functionalities params
        params.update(get_mapserver_substitution_params(self.request))

        # get method
        method = self.request.method

        # we want the browser to cache GetLegendGraphic and
        # DescribeFeatureType requests
        use_cache = False

        if method == "GET":
            # For GET requests, params are added only if the self.request
            # parameter is actually provided.
            if "request" not in self.lower_params:
                params = {}  # pragma: no cover
            else:
                use_cache = self.lower_params["request"] in (
                    u"getcapabilities",
                    u"getlegendgraphic",
                    u"describelayer",
                    u"describefeaturetype",
                )

                # no user_id and role_id or cached queries
                if use_cache and "user_id" in params:
                    del params["user_id"]
                if use_cache and "role_id" in params:
                    del params["role_id"]

            if "service" in self.lower_params and self.lower_params["service"] == u"wfs":
                _url = self._get_wfs_url()
            else:
                _url = self._get_wms_url()
        else:
            # POST means WFS
            _url = self._get_wfs_url()

        cache_control = PRIVATE_CACHE
        if method == "GET" and self.lower_params["service"] == u"wms":
            if self.lower_params["request"] in (u"getmap", u"getfeatureinfo"):
                cache_control = NO_CACHE
            elif self.lower_params["request"] == u"getlegendgraphic":
                cache_control = PUBLIC_CACHE
        elif method == "GET" and self.lower_params["service"] == u"wfs":
            if self.lower_params["request"] == u"getfeature":
                cache_control = NO_CACHE
        elif method != "GET":
            cache_control = NO_CACHE

        role_id = None if self.user is None else \
            self.user.parent_role.id if self.external else self.user.role.id
        response = self._proxy_callback(
            role_id, cache_control,
            url=_url, params=params, cache=use_cache,
            headers=self._get_headers(), body=self.request.body
        )
        return response
Exemplo n.º 4
0
    def proxy(self):

        if self.user is not None:
            # We have a user logged in. We need to set group_id and
            # possible layer_name in the params. We set layer_name
            # when either QUERY_PARAMS or LAYERS is set in the
            # WMS params, i.e. for GetMap and GetFeatureInfo
            # requests. For GetLegendGraphic requests we do not
            # send layer_name, but MapServer should not use the DATA
            # string for GetLegendGraphic.

            role = self.user.role
            if role is not None:
                self.params["role_id"] = role.id

                # In some application we want to display the features owned by a user
                # than we need his id.
                self.params["user_id"] = self.user.id  # pragma: no cover
            else:  # pragma nocover
                log.warning("The user '%s' has no role", self.user.name)

        # do not allows direct variable substitution
        for k in list(self.params.keys()):
            if k[:2].capitalize() == "S_":
                log.warning(
                    "Direct substitution not allowed ({0!s}={1!s}).".format(
                        k, self.params[k]))
                del self.params[k]

        # add functionalities params
        self.params.update(get_mapserver_substitution_params(self.request))

        # get method
        method = self.request.method

        # we want the browser to cache GetLegendGraphic and
        # DescribeFeatureType requests
        use_cache = False

        if method == "GET":
            # For GET requests, params are added only if the self.request
            # parameter is actually provided.
            if "request" not in self.lower_params:
                self.params = {}  # pragma: no cover
            else:
                use_cache = self.lower_params["request"] in (
                    "getcapabilities",
                    "getlegendgraphic",
                    "describelayer",
                    "describefeaturetype",
                )

                # no user_id and role_id or cached queries
                if use_cache and "user_id" in self.params:
                    del self.params["user_id"]
                if use_cache and "role_id" in self.params:
                    del self.params["role_id"]

            if "service" in self.lower_params and self.lower_params[
                    "service"] == "wfs":
                _url = self._get_wfs_url()
            else:
                _url = self._get_wms_url()
        else:
            # POST means WFS
            _url = self._get_wfs_url()

        cache_control = PRIVATE_CACHE
        if method == "GET" and \
                "service" in self.lower_params and \
                self.lower_params["service"] == "wms":
            if self.lower_params["request"] in ("getmap", "getfeatureinfo"):
                cache_control = NO_CACHE
            elif self.lower_params["request"] == "getlegendgraphic":
                cache_control = PUBLIC_CACHE
        elif method == "GET" and \
                "service" in self.lower_params and \
                self.lower_params["service"] == "wfs":
            if self.lower_params["request"] == "getfeature":
                cache_control = NO_CACHE
        elif method != "GET":
            cache_control = NO_CACHE

        role = None if self.user is None else self.user.role

        headers = self._get_headers()
        # Add headers for Geoserver
        if self._get_ogc_server().auth == OGCSERVER_AUTH_GEOSERVER and \
                self.user is not None:
            headers["sec-username"] = self.user.username
            headers["sec-roles"] = role.name

        response = self._proxy_callback(role.id if role is not None else None,
                                        cache_control,
                                        url=_url,
                                        params=self.params,
                                        cache=use_cache,
                                        headers=headers,
                                        body=self.request.body)
        return response
Exemplo n.º 5
0
    def proxy(self):

        self.user = self.request.user
        self.external = bool(self.request.params.get("EXTERNAL", None))

        # params hold the parameters we're going to send to MapServer
        params = dict(self.request.params)

        # reset possible value of role_id and user_id
        if 'role_id' in params:  # pragma: no cover
            del params['role_id']
        if 'user_id' in params:  # pragma: no cover
            del params['user_id']

        self.lower_params = dict(
            (k.lower(), unicode(v).lower()) for k, v in params.iteritems()
        )

        if self.user is not None:
            # We have a user logged in. We need to set group_id and
            # possible layer_name in the params. We set layer_name
            # when either QUERY_PARAMS or LAYERS is set in the
            # WMS params, i.e. for GetMap and GetFeatureInfo
            # requests. For GetLegendGraphic requests we don't
            # send layer_name, but MapServer shouldn't use the DATA
            # string for GetLegendGraphic.

            params['role_id'] = self.user.parent_role.id if self.external else self.user.role.id

            # In some application we want to display the features owned by a user
            # than we need his id.
            if not self.external:
                params['user_id'] = self.user.id  # pragma: nocover

        # don't allows direct variable substitution
        for k in params.keys():
            if k[:2].capitalize() == 'S_':
                log.warning("Direct substitution not allowed (%s=%s)." %
                            (k, params[k]))
                del params[k]

        # add functionalities params
        params.update(get_mapserver_substitution_params(self.request))

        # get method
        method = self.request.method

        # we want the browser to cache GetLegendGraphic and
        # DescribeFeatureType requests
        use_cache = False
        public_cache = False

        if method == "GET":
            # For GET requests, params are added only if the self.request
            # parameter is actually provided.
            if 'request' not in self.lower_params:
                params = {}  # pragma: no cover
            else:
                use_cache = (
                    self.lower_params['request'] == u'getcapabilities'
                ) or (
                    self.lower_params['request'] == u'getlegendgraphic'
                ) or (
                    self.lower_params['request'] == u'describelayer'
                ) or (
                    self.lower_params['request'] == u'describefeaturetype'
                )

                public_cache = self.lower_params['request'] == u'getlegendgraphic'

                # no user_id and role_id or cached queries
                if use_cache and 'user_id' in params:
                    del params['user_id']
                if use_cache and 'role_id' in params:
                    del params['role_id']

            if 'service' in self.lower_params and self.lower_params['service'] == u'wfs':
                _url = self._get_wfs_url()
            else:
                _url = self._get_wms_url()
        else:
            # POST means WFS
            _url = self._get_wfs_url()

        role_id = None if self.user is None else \
            self.user.parent_role.id if self.external else self.user.role.id
        response = self._proxy_callback(
            url=_url, params=params, cache=use_cache,
            headers=self._get_headers(), body=self.request.body, role_id=role_id
        )
        if self.user is not None and use_cache and not public_cache:
            response.cache_control.public = False
            response.cache_control.private = True
        return response