Skip to content

Commit a4242f2

Browse files
committed
Mask Handler Response.
1 parent 1ba8b10 commit a4242f2

File tree

7 files changed

+40
-46
lines changed

7 files changed

+40
-46
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ mavenPassword=YourPassword
1010
# When updating the version, please as well consider:
1111
# - here-naksha-lib-core/src/main/com/here/naksha/lib/core/NakshaVersion (static property: latest)
1212
# - here-naksha-app-service/src/main/resources/swagger/openapi.yaml (info.version property)
13-
version=2.2.2
13+
version=2.2.3
1414

here-naksha-app-service/src/main/java/com/here/naksha/app/service/http/ops/MaskingUtil.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,26 +25,27 @@
2525
import java.util.Set;
2626

2727
public class MaskingUtil {
28-
28+
public static final Set<String> SENSITIVE_PROPERTIES = Set.of("password", "authorization");
2929
static final String MASK = "xxxxxx";
3030

3131
private MaskingUtil() {}
3232

33-
public static void maskProperties(XyzFeature feature, Set<String> propertiesToMask) {
34-
maskProperties(feature.getProperties(), propertiesToMask);
33+
public static void maskProperties(XyzFeature feature) {
34+
maskProperties(feature.getProperties());
3535
}
3636

37-
private static void maskProperties(Map<String, Object> propertiesAsMap, Set<String> propertiesToMask) {
37+
private static void maskProperties(Map<String, Object> propertiesAsMap) {
3838
for (Entry<String, Object> entry : propertiesAsMap.entrySet()) {
39-
if (propertiesToMask.stream().anyMatch(entry.getKey()::contains)) {
39+
if (SENSITIVE_PROPERTIES.stream()
40+
.anyMatch(property -> entry.getKey().toLowerCase().contains(property.toLowerCase()))) {
4041
entry.setValue(MASK);
4142
} else if (entry.getValue() instanceof Map) {
42-
maskProperties((Map<String, Object>) entry.getValue(), propertiesToMask);
43+
maskProperties((Map<String, Object>) entry.getValue());
4344
} else if (entry.getValue() instanceof ArrayList array) {
4445
// recursive call to the nested array json
4546
for (Object arrayEntry : array) {
4647
if (arrayEntry instanceof Map) {
47-
maskProperties((Map<String, Object>) arrayEntry, propertiesToMask);
48+
maskProperties((Map<String, Object>) arrayEntry);
4849
}
4950
}
5051
}

here-naksha-app-service/src/main/java/com/here/naksha/app/service/http/tasks/EventHandlerApiTask.java

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,7 @@
3939
import com.here.naksha.lib.core.util.json.Json;
4040
import com.here.naksha.lib.core.util.storage.RequestHelper;
4141
import com.here.naksha.lib.core.view.ViewDeserialize;
42-
import com.here.naksha.lib.psql.PsqlInstanceConfig;
4342
import io.vertx.ext.web.RoutingContext;
44-
import java.util.Set;
4543
import org.jetbrains.annotations.NotNull;
4644
import org.slf4j.Logger;
4745
import org.slf4j.LoggerFactory;
@@ -50,9 +48,6 @@ public class EventHandlerApiTask<T extends XyzResponse> extends AbstractApiTask<
5048

5149
private static final Logger logger = LoggerFactory.getLogger(EventHandlerApiTask.class);
5250

53-
private static final Set<String> SENSITIVE_PROPERTIES =
54-
Set.of(PsqlInstanceConfig.PASSWORD, "Authorization", "authorization");
55-
5651
private final @NotNull EventHandlerApiReqType reqType;
5752

5853
public EventHandlerApiTask(
@@ -103,11 +98,7 @@ protected void init() {}
10398
// Read request JSON
10499
final EventHandler newHandler = handlerFromRequestBody();
105100
final WriteXyzFeatures writeRequest = RequestHelper.createFeatureRequest(EVENT_HANDLERS, newHandler, false);
106-
// persist new handler in Admin DB (if doesn't exist already)
107-
try (Result writeResult = executeWriteRequestFromSpaceStorage(writeRequest)) {
108-
return transformWriteResultToXyzFeatureResponse(
109-
writeResult, EventHandler.class, this::handlerWithMaskedSensitiveProperties);
110-
}
101+
return transformedResponseTo(writeRequest);
111102
}
112103

113104
private @NotNull XyzResponse executeGetHandlers() {
@@ -116,20 +107,15 @@ protected void init() {}
116107
// Submit request to NH Space Storage
117108
try (Result rdResult = executeReadRequestFromSpaceStorage(request)) {
118109
// transform ReadResult to Http FeatureCollection response
119-
return transformReadResultToXyzCollectionResponse(
120-
rdResult, EventHandler.class, this::handlerWithMaskedSensitiveProperties);
110+
return transformReadResultToXyzCollectionResponse(rdResult, EventHandler.class);
121111
}
122112
}
123113

124114
private @NotNull XyzResponse executeGetHandlerById() {
125115
// Create ReadFeatures Request to read the handler with the specific ID from Admin DB
126116
final String handlerId = routingContext.pathParam(HANDLER_ID);
127117
final ReadFeatures request = new ReadFeatures(EVENT_HANDLERS).withPropertyOp(POp.eq(PRef.id(), handlerId));
128-
// Submit request to NH Space Storage
129-
try (Result rdResult = executeReadRequestFromSpaceStorage(request)) {
130-
return transformReadResultToXyzFeatureResponse(
131-
rdResult, EventHandler.class, this::handlerWithMaskedSensitiveProperties);
132-
}
118+
return transformedResponseTo(request);
133119
}
134120

135121
private @NotNull XyzResponse executeUpdateHandler() throws JsonProcessingException {
@@ -141,10 +127,7 @@ protected void init() {}
141127
} else {
142128
final WriteXyzFeatures updateHandlerReq =
143129
RequestHelper.updateFeatureRequest(EVENT_HANDLERS, handlerToUpdate);
144-
try (Result updateHandlerResult = executeWriteRequestFromSpaceStorage(updateHandlerReq)) {
145-
return transformWriteResultToXyzFeatureResponse(
146-
updateHandlerResult, EventHandler.class, this::handlerWithMaskedSensitiveProperties);
147-
}
130+
return transformedResponseTo(updateHandlerReq);
148131
}
149132
}
150133

@@ -157,8 +140,25 @@ protected void init() {}
157140
}
158141
}
159142

143+
@NotNull
144+
private XyzResponse transformedResponseTo(ReadFeatures rdRequest) {
145+
try (Result rdResult = executeReadRequestFromSpaceStorage(rdRequest)) {
146+
return transformReadResultToXyzFeatureResponse(
147+
rdResult, EventHandler.class, this::handlerWithMaskedSensitiveProperties);
148+
}
149+
}
150+
151+
@NotNull
152+
private XyzResponse transformedResponseTo(WriteXyzFeatures updateHandlerReq) {
153+
// persist new handler in Admin DB (if doesn't exist already)
154+
try (Result updateHandlerResult = executeWriteRequestFromSpaceStorage(updateHandlerReq)) {
155+
return transformWriteResultToXyzFeatureResponse(
156+
updateHandlerResult, EventHandler.class, this::handlerWithMaskedSensitiveProperties);
157+
}
158+
}
159+
160160
private EventHandler handlerWithMaskedSensitiveProperties(EventHandler handler) {
161-
maskProperties(handler, SENSITIVE_PROPERTIES);
161+
maskProperties(handler);
162162
return handler;
163163
}
164164

here-naksha-app-service/src/main/java/com/here/naksha/app/service/http/tasks/StorageApiTask.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,14 @@
3939
import com.here.naksha.lib.core.util.json.Json;
4040
import com.here.naksha.lib.core.util.storage.RequestHelper;
4141
import com.here.naksha.lib.core.view.ViewDeserialize;
42-
import com.here.naksha.lib.psql.PsqlInstanceConfig;
4342
import io.vertx.ext.web.RoutingContext;
44-
import java.util.Set;
4543
import org.jetbrains.annotations.NotNull;
4644
import org.slf4j.Logger;
4745
import org.slf4j.LoggerFactory;
4846

4947
public class StorageApiTask extends AbstractApiTask<XyzResponse> {
5048

5149
private static final Logger logger = LoggerFactory.getLogger(StorageApiTask.class);
52-
53-
private static final Set<String> SENSITIVE_PROPERTIES =
54-
Set.of(PsqlInstanceConfig.PASSWORD, "Authorization", "authorization");
5550
private final @NotNull StorageApiReqType reqType;
5651

5752
public enum StorageApiReqType {
@@ -164,7 +159,7 @@ private XyzResponse transformedResponseTo(WriteXyzFeatures updateStorageReq) {
164159
}
165160

166161
private Storage storageWithMaskedSensitiveProperties(Storage storage) {
167-
maskProperties(storage, SENSITIVE_PROPERTIES);
162+
maskProperties(storage);
168163
return storage;
169164
}
170165

here-naksha-app-service/src/main/resources/swagger/openapi.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ servers:
1212
info:
1313
title: "Naksha Hub-API"
1414
description: "Naksha Hub-API is a REST API to provide simple access to geo data."
15-
version: "2.2.2"
15+
version: "2.2.3"
1616

1717
security:
1818
- AccessToken: [ ]

here-naksha-app-service/src/test/java/com/here/naksha/app/service/http/ops/MaskingUtilTest.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class MaskingUtilTest {
1515
void shouldMaskProperties(){
1616
// Given
1717
XyzFeature feature = featureWithProps(mutableMapOf(
18-
"sensitiveObject", mutableMapOf(
18+
"Authorization", mutableMapOf(
1919
"some_entry_1", 123,
2020
"some_entry_2", "lorem ipsum"
2121
),
@@ -30,7 +30,7 @@ void shouldMaskProperties(){
3030
"nested", mutableMapOf(
3131
"map", mutableMapOf(
3232
"to", mutableMapOf(
33-
"sensitiveObject", mutableMapOf(
33+
"authorization", mutableMapOf(
3434
"foo", "bar"
3535
)
3636
)
@@ -39,15 +39,12 @@ void shouldMaskProperties(){
3939
)
4040
));
4141

42-
// And:
43-
Set<String> sensitiveProperties = Set.of("sensitiveObject", "Authorization", "password");
44-
4542
// When:
46-
MaskingUtil.maskProperties(feature, sensitiveProperties);
43+
MaskingUtil.maskProperties(feature);
4744

4845
// Then:
4946
assertEquals(Map.of(
50-
"sensitiveObject", MaskingUtil.MASK,
47+
"Authorization", MaskingUtil.MASK,
5148
"headers", Map.of(
5249
"Authorization", MaskingUtil.MASK,
5350
"Content-Type", "application/json"
@@ -59,7 +56,7 @@ void shouldMaskProperties(){
5956
"nested", Map.of(
6057
"map", Map.of(
6158
"to", Map.of(
62-
"sensitiveObject", MaskingUtil.MASK
59+
"authorization", MaskingUtil.MASK
6360
)
6461
)
6562
)

here-naksha-lib-core/src/main/java/com/here/naksha/lib/core/NakshaVersion.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,13 @@ public class NakshaVersion implements Comparable<NakshaVersion> {
6060
public static final String v2_2_0 = "2.2.0";
6161
public static final String v2_2_1 = "2.2.1";
6262
public static final String v2_2_2 = "2.2.2";
63+
public static final String v2_2_3 = "2.2.3";
6364

6465
/**
6566
* The latest version of the naksha-extension stored in the resources.
6667
*/
6768
@AvailableSince(v2_0_5)
68-
public static final NakshaVersion latest = of(v2_2_2);
69+
public static final NakshaVersion latest = of(v2_2_3);
6970

7071
private final int major;
7172
private final int minor;

0 commit comments

Comments
 (0)