Skip to content

Commit

Permalink
Add configuration to filter out Elasticsearch fields when download or…
Browse files Browse the repository at this point in the history
… dynamic privileges are not set
  • Loading branch information
josegar74 authored and fxprunayre committed Feb 1, 2024
1 parent 43214ef commit 3a01af3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ Ce schéma est également composé des normes :
*/cit:protocol/gco:CharacterString = 'FILE' or
*/cit:protocol/gco:CharacterString = 'DB' or
*/cit:protocol/gco:CharacterString = 'COPYFILE']"
jsonpath="$['link'][?(@.protocol =~ /(DOWNLOAD|FILE|DB|COPYFILE).*?/i)]"
ifNotOperation="download"/>

<!--
Expand All @@ -157,6 +158,7 @@ Ce schéma est également composé des normes :
TODO: other type of services ?
-->
<filter xpath=".//mrd:onLine[starts-with(*/cit:protocol/gco:CharacterString, 'OGC:WMS')]"
jsonpath="$['link'][?(@.protocol =~ /OGC:WMS.*?/i)]"
ifNotOperation="dynamic"/>
</filters>
</schema>
2 changes: 2 additions & 0 deletions schemas/iso19139/src/main/plugin/iso19139/schema-ident.xml
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,10 @@ of data.]]>
</filter>
<filter
xpath=".//gmd:onLine[*/gmd:protocol/gco:CharacterString = 'WWW:DOWNLOAD-1.0-http--download']"
jsonpath="$['link'][?(@.protocol == 'WWW:DOWNLOAD-1.0-http--download')]"
ifNotOperation="download"/>
<filter xpath=".//gmd:onLine[starts-with(*/gmd:protocol/gco:CharacterString, 'OGC:WMS')]"
jsonpath="$['link'][?(@.protocol =~ /OGC:WMS.*?/i)]"
ifNotOperation="dynamic"/>
</filters>
</schema>
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import com.google.common.collect.Sets;
import com.jayway.jsonpath.DocumentContext;
import com.jayway.jsonpath.JsonPath;
import com.jayway.jsonpath.PathNotFoundException;
import io.swagger.v3.oas.annotations.Hidden;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
Expand Down Expand Up @@ -902,7 +903,11 @@ private JsonNode filterResponseElements(ObjectMapper mapper, ObjectNode sourceNo

for(String jsonPath : jsonPathFilters) {
if (StringUtils.isNotBlank(jsonPath)) {
jsonContext = jsonContext.delete(jsonPath);
try {
jsonContext = jsonContext.delete(jsonPath);
} catch (PathNotFoundException ex) {
// The node to remove is not returned in the response, ignore the error
}
}
}

Expand Down

0 comments on commit 3a01af3

Please sign in to comment.