def proxy(self): self.user = self.request.user if self.user is None: raise HTTPUnauthorized( "Authentication required", headers=[("WWW-Authenticate", 'Basic realm="TinyOWS"')] ) self.role_id = None if self.user is None else self.user.role.id # params hold the parameters we're going to send to TinyOWS params = dict(self.request.params) self.lower_params = self._get_lower_params(params) operation = self.lower_params.get("request") typenames = \ set([normalize_typename(self.lower_params.get("typename"))]) \ if "typename" in self.lower_params \ else set() method = self.request.method if method == "POST": try: (operation, typenames_post) = \ self._parse_body(self.request.body) except Exception as e: log.error("Error while parsing POST request body") log.exception(e) raise HTTPBadRequest( "Error parsing the request (see logs for more details)") typenames = typenames.union(typenames_post) if operation is None or operation == "": operation = "getcapabilities" if operation == "describefeaturetype": # for DescribeFeatureType we require that exactly one type-name # is given, otherwise we would have to filter the result if len(typenames) != 1: raise HTTPBadRequest( "Exactly one type-name must be given for " "DescribeFeatureType requests" ) if not self._is_allowed(typenames): raise HTTPForbidden( "No access rights for at least one of the given type-names" ) # we want clients to cache GetCapabilities and DescribeFeatureType req. use_cache = method == "GET" and operation in (u"getcapabilities", u"describefeaturetype") cache_control = PRIVATE_CACHE if use_cache else NO_CACHE response = self._proxy_callback( operation, self.role_id, cache_control, url=self._get_wfs_url(), params=params, cache=use_cache, headers=self._get_headers(), body=self.request.body, ) return response
def proxy(self): if self.user is None: raise HTTPUnauthorized("Authentication required", headers=[("WWW-Authenticate", 'Basic realm="TinyOWS"')]) operation = self.lower_params.get("request") typenames = \ set([normalize_typename(self.lower_params.get("typename"))]) \ if "typename" in self.lower_params \ else set() method = self.request.method if method == "POST": try: (operation, typenames_post) = \ self._parse_body(self.request.body) except Exception as e: log.error("Error while parsing POST request body") log.exception(e) raise HTTPBadRequest( "Error parsing the request (see logs for more details)") typenames = typenames.union(typenames_post) if operation is None or operation == "": operation = "getcapabilities" if operation == "describefeaturetype": # for DescribeFeatureType we require that exactly one type-name # is given, otherwise we would have to filter the result if len(typenames) != 1: raise HTTPBadRequest("Exactly one type-name must be given for " "DescribeFeatureType requests") if not self._is_allowed(typenames): raise HTTPForbidden( "No access rights for at least one of the given type-names") # we want clients to cache GetCapabilities and DescribeFeatureType req. use_cache = method == "GET" and operation in ("getcapabilities", "describefeaturetype") cache_control = PRIVATE_CACHE if use_cache else NO_CACHE response = self._proxy_callback( operation, self.role_id, cache_control, url=self._get_wfs_url(), params=dict(self.request.params), cache=use_cache, headers=self._get_headers(), body=self.request.body, ) return response
def _parse_body(self, body): """ Read the WFS-T request body and extract the referenced type-names and request method. """ xml = ElementTree.fromstring(body) wfs_request = normalize_tag(xml.tag) # get the type names typenames = set() for child in xml: tag = normalize_tag(child.tag) if tag == "typename": typenames.add(child.text) elif tag in ("query", "lock", "update", "delete"): typenames.add(child.get("typeName")) elif tag == "insert": for insert_child in child: typenames.add(normalize_tag(insert_child.tag)) # remove the namespace from the typenames typenames = {normalize_typename(t) for t in typenames} return (wfs_request, typenames)
def _parse_body(body): """ Read the WFS-T request body and extract the referenced type-names and request method. """ xml = ElementTree.fromstring(body) wfs_request = normalize_tag(xml.tag) # get the type names typenames = set() for child in xml: tag = normalize_tag(child.tag) if tag == "typename": typenames.add(child.text) elif tag in ("query", "lock", "update", "delete"): typenames.add(child.get("typeName")) elif tag == "insert": for insert_child in child: typenames.add(normalize_tag(insert_child.tag)) # remove the namespace from the typenames typenames = {normalize_typename(t) for t in typenames} return (wfs_request, typenames)