Skip to content

Commit

Permalink
fix(web-hook) implement what has been discussed during the architectu…
Browse files Browse the repository at this point in the history
…re session, fix small comments on PR
  • Loading branch information
mathias-vandaele committed Jul 15, 2024
1 parent 5c1110a commit f500b52
Showing 1 changed file with 11 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,13 @@ private String prepareForSignature(byte[] rawBody, String contentTypeHeader) {
.map(param -> param.split("="))
.collect(
Collectors.toMap(param -> param[0], param -> param.length == 1 ? "" : param[1]));
return strMap.keySet().stream()
.sorted()
.map(key -> key.concat(strMap.get(key)))
.reduce(String::concat)
.orElse("");
return extractSignatureFromMap(strMap);
}
Object o = mapBytesToObject(rawBody);
if (o instanceof Map<?, ?> map) {
for (Map.Entry<?, ?> entry : map.entrySet()) {
if (entry.getKey() instanceof String) {
Map<String, String> strMap = (Map<String, String>) map;
return strMap.keySet().stream()
.sorted()
.map(key -> key.concat(strMap.get(key)))
.reduce(String::concat)
.orElse("");
if (entry.getKey() instanceof String && entry.getValue() instanceof String) {
return extractSignatureFromMap((Map<String, String>) map);
}
}
} else {
Expand All @@ -58,6 +49,14 @@ private String prepareForSignature(byte[] rawBody, String contentTypeHeader) {
throw new RuntimeException("Can't extract signature data from body");
}

private String extractSignatureFromMap(Map<String, String> map) {
return map.keySet().stream()
.sorted()
.map(key -> key.concat(map.get(key)))
.reduce(String::concat)
.orElse("");
}

private String mapObjectToString(Object o) {
try {
return ConnectorsObjectMapperSupplier.DEFAULT_MAPPER.writeValueAsString(o);
Expand Down

0 comments on commit f500b52

Please sign in to comment.