@Ignore @Test public void decryptJsonObjectUsingRoles() throws IOException { JsonNode ciphertext = mapper.readTree("{\"User\":{\"mobileNumber\":\"341642|WfYfJPRug15R2wFh17PlQr5d9YhNkFk1" + "\",\"name\":\"341642|Ca5NbGHu3aB2ufjrNfZarW1VGBA=\"," + "\"userName\":\"341642|Ca5NbGHu3aB2ufjrNfZarW1VGBA=\",\"gender\":\"male\",\"active\":true," + "\"type\":\"CITIZEN\",\"password\":\"password\"},\"RequestInfo\":{\"api_id\":\"1\",\"ver\":\"1\"," + "\"ts\":null,\"action\":\"create\",\"did\":\"\",\"key\":\"\",\"msg_id\":\"\",\"requester_id\":\"\"," + "\"auth_token\":null}}"); User user = User.builder().roles(Arrays.asList(Role.builder().code("GRO").build())).build(); JsonNode plaintext = encryptionServiceImpl.decryptJson(ciphertext, "PGR-Complaints-Report", user, JsonNode.class); log.info(plaintext.toString()); }
public JsonNode decryptJson(Object ciphertextJson, Map<Attribute, AccessType> attributeAccessTypeMap, User user) throws IOException { JsonNode ciphertextNode = createJsonNode(ciphertextJson); JsonNode decryptNode = ciphertextNode.deepCopy(); if(attributeAccessTypeMap.containsValue(AccessType.NONE)) { List<Attribute> attributesToBeRemoved = attributeAccessTypeMap.keySet().stream() .filter(attribute -> attributeAccessTypeMap.get(attribute) == AccessType.NONE).collect(Collectors.toList()); List<String> pathsToBeRemoved = attributesToBeRemoved.stream().map(Attribute::getJsonPath).collect(Collectors.toList()); JsonNode nodeToBeEmptied = JacksonUtils.filterJsonNodeForPaths(decryptNode, pathsToBeRemoved); JsonNode emptyNode = JSONBrowseUtil.mapValues(nodeToBeEmptied, __ -> EncClientConstants.STRING_FOR_NONE_ACCESS); decryptNode = JacksonUtils.merge(emptyNode, decryptNode); } List<Attribute> attributesToBeDecrypted = attributeAccessTypeMap.keySet().stream() .filter(attribute -> attributeAccessTypeMap.get(attribute) != AccessType.NONE).collect(Collectors.toList()); List<String> pathsToBeDecrypted = attributesToBeDecrypted.stream().map(Attribute::getJsonPath).collect(Collectors.toList()); JsonNode jsonNode = JacksonUtils.filterJsonNodeForPaths(ciphertextNode, pathsToBeDecrypted); if(! jsonNode.isEmpty(objectMapper.getSerializerProvider())) { JsonNode returnedDecryptedNode = objectMapper.valueToTree(encryptionServiceRestConnection.callDecrypt(jsonNode)); decryptNode = JacksonUtils.merge(returnedDecryptedNode, decryptNode); } if(attributeAccessTypeMap.containsValue(AccessType.MASK)) { List<Attribute> attributesToBeMasked = attributeAccessTypeMap.keySet().stream() .filter(attribute -> attributeAccessTypeMap.get(attribute) == AccessType.MASK).collect(Collectors.toList()); decryptNode = maskingService.maskData(decryptNode, attributesToBeMasked); } return decryptNode; }
EncryptionServiceImpl implements EncryptionService { public JsonNode decryptJson(Object ciphertextJson, Map<Attribute, AccessType> attributeAccessTypeMap, User user) throws IOException { JsonNode ciphertextNode = createJsonNode(ciphertextJson); JsonNode decryptNode = ciphertextNode.deepCopy(); if(attributeAccessTypeMap.containsValue(AccessType.NONE)) { List<Attribute> attributesToBeRemoved = attributeAccessTypeMap.keySet().stream() .filter(attribute -> attributeAccessTypeMap.get(attribute) == AccessType.NONE).collect(Collectors.toList()); List<String> pathsToBeRemoved = attributesToBeRemoved.stream().map(Attribute::getJsonPath).collect(Collectors.toList()); JsonNode nodeToBeEmptied = JacksonUtils.filterJsonNodeForPaths(decryptNode, pathsToBeRemoved); JsonNode emptyNode = JSONBrowseUtil.mapValues(nodeToBeEmptied, __ -> EncClientConstants.STRING_FOR_NONE_ACCESS); decryptNode = JacksonUtils.merge(emptyNode, decryptNode); } List<Attribute> attributesToBeDecrypted = attributeAccessTypeMap.keySet().stream() .filter(attribute -> attributeAccessTypeMap.get(attribute) != AccessType.NONE).collect(Collectors.toList()); List<String> pathsToBeDecrypted = attributesToBeDecrypted.stream().map(Attribute::getJsonPath).collect(Collectors.toList()); JsonNode jsonNode = JacksonUtils.filterJsonNodeForPaths(ciphertextNode, pathsToBeDecrypted); if(! jsonNode.isEmpty(objectMapper.getSerializerProvider())) { JsonNode returnedDecryptedNode = objectMapper.valueToTree(encryptionServiceRestConnection.callDecrypt(jsonNode)); decryptNode = JacksonUtils.merge(returnedDecryptedNode, decryptNode); } if(attributeAccessTypeMap.containsValue(AccessType.MASK)) { List<Attribute> attributesToBeMasked = attributeAccessTypeMap.keySet().stream() .filter(attribute -> attributeAccessTypeMap.get(attribute) == AccessType.MASK).collect(Collectors.toList()); decryptNode = maskingService.maskData(decryptNode, attributesToBeMasked); } return decryptNode; } }
EncryptionServiceImpl implements EncryptionService { public JsonNode decryptJson(Object ciphertextJson, Map<Attribute, AccessType> attributeAccessTypeMap, User user) throws IOException { JsonNode ciphertextNode = createJsonNode(ciphertextJson); JsonNode decryptNode = ciphertextNode.deepCopy(); if(attributeAccessTypeMap.containsValue(AccessType.NONE)) { List<Attribute> attributesToBeRemoved = attributeAccessTypeMap.keySet().stream() .filter(attribute -> attributeAccessTypeMap.get(attribute) == AccessType.NONE).collect(Collectors.toList()); List<String> pathsToBeRemoved = attributesToBeRemoved.stream().map(Attribute::getJsonPath).collect(Collectors.toList()); JsonNode nodeToBeEmptied = JacksonUtils.filterJsonNodeForPaths(decryptNode, pathsToBeRemoved); JsonNode emptyNode = JSONBrowseUtil.mapValues(nodeToBeEmptied, __ -> EncClientConstants.STRING_FOR_NONE_ACCESS); decryptNode = JacksonUtils.merge(emptyNode, decryptNode); } List<Attribute> attributesToBeDecrypted = attributeAccessTypeMap.keySet().stream() .filter(attribute -> attributeAccessTypeMap.get(attribute) != AccessType.NONE).collect(Collectors.toList()); List<String> pathsToBeDecrypted = attributesToBeDecrypted.stream().map(Attribute::getJsonPath).collect(Collectors.toList()); JsonNode jsonNode = JacksonUtils.filterJsonNodeForPaths(ciphertextNode, pathsToBeDecrypted); if(! jsonNode.isEmpty(objectMapper.getSerializerProvider())) { JsonNode returnedDecryptedNode = objectMapper.valueToTree(encryptionServiceRestConnection.callDecrypt(jsonNode)); decryptNode = JacksonUtils.merge(returnedDecryptedNode, decryptNode); } if(attributeAccessTypeMap.containsValue(AccessType.MASK)) { List<Attribute> attributesToBeMasked = attributeAccessTypeMap.keySet().stream() .filter(attribute -> attributeAccessTypeMap.get(attribute) == AccessType.MASK).collect(Collectors.toList()); decryptNode = maskingService.maskData(decryptNode, attributesToBeMasked); } return decryptNode; }  }
EncryptionServiceImpl implements EncryptionService { public JsonNode decryptJson(Object ciphertextJson, Map<Attribute, AccessType> attributeAccessTypeMap, User user) throws IOException { JsonNode ciphertextNode = createJsonNode(ciphertextJson); JsonNode decryptNode = ciphertextNode.deepCopy(); if(attributeAccessTypeMap.containsValue(AccessType.NONE)) { List<Attribute> attributesToBeRemoved = attributeAccessTypeMap.keySet().stream() .filter(attribute -> attributeAccessTypeMap.get(attribute) == AccessType.NONE).collect(Collectors.toList()); List<String> pathsToBeRemoved = attributesToBeRemoved.stream().map(Attribute::getJsonPath).collect(Collectors.toList()); JsonNode nodeToBeEmptied = JacksonUtils.filterJsonNodeForPaths(decryptNode, pathsToBeRemoved); JsonNode emptyNode = JSONBrowseUtil.mapValues(nodeToBeEmptied, __ -> EncClientConstants.STRING_FOR_NONE_ACCESS); decryptNode = JacksonUtils.merge(emptyNode, decryptNode); } List<Attribute> attributesToBeDecrypted = attributeAccessTypeMap.keySet().stream() .filter(attribute -> attributeAccessTypeMap.get(attribute) != AccessType.NONE).collect(Collectors.toList()); List<String> pathsToBeDecrypted = attributesToBeDecrypted.stream().map(Attribute::getJsonPath).collect(Collectors.toList()); JsonNode jsonNode = JacksonUtils.filterJsonNodeForPaths(ciphertextNode, pathsToBeDecrypted); if(! jsonNode.isEmpty(objectMapper.getSerializerProvider())) { JsonNode returnedDecryptedNode = objectMapper.valueToTree(encryptionServiceRestConnection.callDecrypt(jsonNode)); decryptNode = JacksonUtils.merge(returnedDecryptedNode, decryptNode); } if(attributeAccessTypeMap.containsValue(AccessType.MASK)) { List<Attribute> attributesToBeMasked = attributeAccessTypeMap.keySet().stream() .filter(attribute -> attributeAccessTypeMap.get(attribute) == AccessType.MASK).collect(Collectors.toList()); decryptNode = maskingService.maskData(decryptNode, attributesToBeMasked); } return decryptNode; }  JsonNode encryptJson(Object plaintextJson, String key, String tenantId); P encryptJson(Object plaintextJson, String key, String tenantId, Class<E> valueType); JsonNode decryptJson(Object ciphertextJson, Map<Attribute, AccessType> attributeAccessTypeMap, User user); JsonNode decryptJson(Object ciphertextJson, String key, User user); P decryptJson(Object ciphertextJson, String key, User user, Class<E> valueType); String encryptValue(Object plaintext, String tenantId, String type); List<String> encryptValue(List<Object> plaintext, String tenantId, String type); }
EncryptionServiceImpl implements EncryptionService { public JsonNode decryptJson(Object ciphertextJson, Map<Attribute, AccessType> attributeAccessTypeMap, User user) throws IOException { JsonNode ciphertextNode = createJsonNode(ciphertextJson); JsonNode decryptNode = ciphertextNode.deepCopy(); if(attributeAccessTypeMap.containsValue(AccessType.NONE)) { List<Attribute> attributesToBeRemoved = attributeAccessTypeMap.keySet().stream() .filter(attribute -> attributeAccessTypeMap.get(attribute) == AccessType.NONE).collect(Collectors.toList()); List<String> pathsToBeRemoved = attributesToBeRemoved.stream().map(Attribute::getJsonPath).collect(Collectors.toList()); JsonNode nodeToBeEmptied = JacksonUtils.filterJsonNodeForPaths(decryptNode, pathsToBeRemoved); JsonNode emptyNode = JSONBrowseUtil.mapValues(nodeToBeEmptied, __ -> EncClientConstants.STRING_FOR_NONE_ACCESS); decryptNode = JacksonUtils.merge(emptyNode, decryptNode); } List<Attribute> attributesToBeDecrypted = attributeAccessTypeMap.keySet().stream() .filter(attribute -> attributeAccessTypeMap.get(attribute) != AccessType.NONE).collect(Collectors.toList()); List<String> pathsToBeDecrypted = attributesToBeDecrypted.stream().map(Attribute::getJsonPath).collect(Collectors.toList()); JsonNode jsonNode = JacksonUtils.filterJsonNodeForPaths(ciphertextNode, pathsToBeDecrypted); if(! jsonNode.isEmpty(objectMapper.getSerializerProvider())) { JsonNode returnedDecryptedNode = objectMapper.valueToTree(encryptionServiceRestConnection.callDecrypt(jsonNode)); decryptNode = JacksonUtils.merge(returnedDecryptedNode, decryptNode); } if(attributeAccessTypeMap.containsValue(AccessType.MASK)) { List<Attribute> attributesToBeMasked = attributeAccessTypeMap.keySet().stream() .filter(attribute -> attributeAccessTypeMap.get(attribute) == AccessType.MASK).collect(Collectors.toList()); decryptNode = maskingService.maskData(decryptNode, attributesToBeMasked); } return decryptNode; }  JsonNode encryptJson(Object plaintextJson, String key, String tenantId); P encryptJson(Object plaintextJson, String key, String tenantId, Class<E> valueType); JsonNode decryptJson(Object ciphertextJson, Map<Attribute, AccessType> attributeAccessTypeMap, User user); JsonNode decryptJson(Object ciphertextJson, String key, User user); P decryptJson(Object ciphertextJson, String key, User user, Class<E> valueType); String encryptValue(Object plaintext, String tenantId, String type); List<String> encryptValue(List<Object> plaintext, String tenantId, String type);  }