From bb8ca9453a6e3b8d6479a5541e49387f2423796c Mon Sep 17 00:00:00 2001 From: Holash Chand Date: Thu, 23 May 2024 11:54:42 +0530 Subject: [PATCH] fixed decryption in list entity api --- .../sunbirdrc/registry/service/DecryptionHelper.java | 4 ++++ .../registry/service/NativeSearchService.java | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/java/registry/src/main/java/dev/sunbirdrc/registry/service/DecryptionHelper.java b/java/registry/src/main/java/dev/sunbirdrc/registry/service/DecryptionHelper.java index 0324ebc75..73ca2f76a 100644 --- a/java/registry/src/main/java/dev/sunbirdrc/registry/service/DecryptionHelper.java +++ b/java/registry/src/main/java/dev/sunbirdrc/registry/service/DecryptionHelper.java @@ -22,6 +22,10 @@ public JsonNode getDecryptedJson(JsonNode rootNode) throws EncryptionException { return objectNode; } + public JsonNode getDecryptedJson(String entityType, JsonNode data) throws EncryptionException { + return process(data, entityType, null); + } + protected Map performOperation(Map plainMap) throws EncryptionException { return encryptionService.decrypt(plainMap); } diff --git a/java/registry/src/main/java/dev/sunbirdrc/registry/service/NativeSearchService.java b/java/registry/src/main/java/dev/sunbirdrc/registry/service/NativeSearchService.java index 012dd3669..dad499634 100644 --- a/java/registry/src/main/java/dev/sunbirdrc/registry/service/NativeSearchService.java +++ b/java/registry/src/main/java/dev/sunbirdrc/registry/service/NativeSearchService.java @@ -84,6 +84,12 @@ public class NativeSearchService implements ISearchService { @Value("${search.removeNonPublicFieldsForNativeSearch:true}") private boolean removeNonPublicFieldsForNativeSearch; + @Autowired(required = false) + private DecryptionHelper decryptionHelper; + + @Value("${encryption.enabled}") + private boolean encryptionEnabled; + @Override public JsonNode search(JsonNode inputQueryNode, String userId) throws IOException { return search(inputQueryNode, userId, false); @@ -167,6 +173,10 @@ private ObjectNode removeNonPublicFields(SearchQuery searchQuery, ObjectNode sha for(JsonNode node : arrayNode) { data.add(JSONUtil.removeNodesByPath(node, definitionsManager.getExcludingFieldsForEntity(entityType))); } + } else if (encryptionEnabled) { + for(JsonNode node : arrayNode) { + data.add(decryptionHelper.getDecryptedJson(entityType, node)); + } } else { data = arrayNode; }