From 20f9e22add8e1157e68bbabe23ad1c18f5eedd79 Mon Sep 17 00:00:00 2001
From: petruki <31597636+petruki@users.noreply.github.com>
Date: Wed, 24 Sep 2025 19:55:56 -0700
Subject: [PATCH 1/3] Added obfuscate feature for replacing source data with
****
---
README.md | 50 +++++-
pom.xml | 2 +-
src/main/java/ca/trackerforce/DotPathQL.java | 25 +++
src/main/java/ca/trackerforce/DotUtils.java | 4 +-
.../ca/trackerforce/path/DotPathFactory.java | 11 ++
.../ca/trackerforce/path/PathExclude.java | 12 ++
.../ca/trackerforce/ExcludeTypeClassTest.java | 10 +-
.../ObfuscateTypeClassRecordTest.java | 161 ++++++++++++++++++
.../trackerforce/ObfuscateTypeClassTest.java | 29 ++++
9 files changed, 292 insertions(+), 12 deletions(-)
create mode 100644 src/test/java/ca/trackerforce/ObfuscateTypeClassRecordTest.java
create mode 100644 src/test/java/ca/trackerforce/ObfuscateTypeClassTest.java
diff --git a/README.md b/README.md
index 245109b..3c6a3ee 100644
--- a/README.md
+++ b/README.md
@@ -15,6 +15,7 @@ The `DotPathQL` is the core component of this project that allows you to extract
- π― **Selective Property Extraction**: Extract only the properties you need
- π« **Property Exclusion**: Exclude specific properties and return everything else
+- π **Property Obfuscation**: Replace sensitive property values with "****" while preserving structure
- π **Deep Nested Support**: Navigate through multiple levels of object nesting
- π **Collection Handling**: Process Lists, Arrays, and other Collections
- πΊοΈ **Map Support**: Handle both simple and complex Map structures
@@ -25,10 +26,9 @@ The `DotPathQL` is the core component of this project that allows you to extract
## Quick Start
-## Install
-- Using the source code `mvn clean install`
-- Adding as a dependency - Maven
+### Library coordinates
+Maven
```xml
ca.trackerforce
@@ -37,6 +37,11 @@ The `DotPathQL` is the core component of this project that allows you to extract
```
+Gradle
+```groovy
+implementation 'ca.trackerforce:dot-path-ql:${dot-path-ql.version}'
+```
+
### Filter Usage
```java
@@ -59,6 +64,17 @@ Map result = new DotPathQL().exclude(userObject, List.of(
));
```
+### Obfuscate Usage
+
+```java
+// Obfuscate specific properties by replacing their values with "****"
+Map result = new DotPathQL().obfuscate(userObject, List.of(
+ "password",
+ "ssn",
+ "creditCard.number"
+));
+```
+
## Supported Data Structures
- Simple Properties (primitive and object types)
@@ -178,6 +194,34 @@ List reportFields = List.of(
);
```
+### Data Obfuscation for Security
+Mask sensitive information while maintaining data structure for logging, debugging, or sharing with third parties:
+
+```java
+// Obfuscate sensitive fields while keeping the structure intact
+List sensitiveFields = List.of(
+ "password",
+ "ssn",
+ "creditCard.number",
+ "bankAccount.accountNumber",
+ "personalInfo.phoneNumber"
+);
+
+Map obfuscatedData = doPathQl.obfuscate(userObject, sensitiveFields);
+
+// Result preserves structure but replaces sensitive values with "****"
+// {
+// "username": "john_doe",
+// "password": "****",
+// "ssn": "****",
+// "creditCard": {
+// "number": "****",
+// "expiryDate": "12/25"
+// },
+// "email": "john@example.com"
+// }
+```
+
## JSON Output
Convert your filtered or excluded results to JSON format using the built-in `toJson` method. This feature supports both pretty-formatted (indented) and compact (single-line) output.
diff --git a/pom.xml b/pom.xml
index 8f0d229..1077348 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
ca.trackerforce
dot-path-ql
- 1.2.0
+ 1.2.1
dot-path-ql
dotPathQL allows object attribute filtering
diff --git a/src/main/java/ca/trackerforce/DotPathQL.java b/src/main/java/ca/trackerforce/DotPathQL.java
index cc1ac55..ea74382 100644
--- a/src/main/java/ca/trackerforce/DotPathQL.java
+++ b/src/main/java/ca/trackerforce/DotPathQL.java
@@ -18,6 +18,7 @@ public class DotPathQL {
private final DotPath pathFilter;
private final DotPath pathExclude;
+ private final DotPath pathObfuscate;
private final DotPrinter pathPrinter;
/**
@@ -26,6 +27,7 @@ public class DotPathQL {
public DotPathQL() {
pathFilter = DotPathFactory.buildFilter();
pathExclude = DotPathFactory.buildExclude();
+ pathObfuscate = DotPathFactory.buildObfuscate();
pathPrinter = DotPathFactory.buildPrinter(2);
}
@@ -58,6 +60,20 @@ public Map exclude(T source, List excludePaths) {
return pathExclude.run(source, excludePaths);
}
+ /**
+ * Obfuscates the given source object based on the specified paths.
+ * The paths can include nested properties, collections, and arrays.
+ * Also supports grouped paths syntax like "parent[child1.prop,child2.prop]"
+ *
+ * @param the type of the source object
+ * @param source the source object to obfuscate
+ * @param obfuscatePaths the list of paths to obfuscate
+ * @return a map containing the obfuscated properties
+ */
+ public Map obfuscate(T source, List obfuscatePaths) {
+ return pathObfuscate.run(source, obfuscatePaths);
+ }
+
/**
* Adds default filter paths that will be included in every filtering operation.
*
@@ -76,6 +92,15 @@ public void addDefaultExcludePaths(List paths) {
pathExclude.addDefaultPaths(paths);
}
+ /**
+ * Adds default obfuscate paths that will be included in every obfuscation operation.
+ *
+ * @param paths the list of default obfuscate paths to add
+ */
+ public void addDefaultObfuscatePaths(List paths) {
+ pathObfuscate.addDefaultPaths(paths);
+ }
+
/**
* Converts the source object to a map representation.
*
diff --git a/src/main/java/ca/trackerforce/DotUtils.java b/src/main/java/ca/trackerforce/DotUtils.java
index d949a2d..855eb4d 100644
--- a/src/main/java/ca/trackerforce/DotUtils.java
+++ b/src/main/java/ca/trackerforce/DotUtils.java
@@ -66,6 +66,8 @@ public static List