Skip to content

Commit e033508

Browse files
committed
Updated parent version, site model and README
1 parent 29b06e1 commit e033508

File tree

3 files changed

+85
-63
lines changed

3 files changed

+85
-63
lines changed

README.md

Lines changed: 78 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,29 @@ Provides functionality for obfuscating JSON documents. This can be useful for lo
99

1010
To create a JSON obfuscator, simply create a builder, add properties to it, and let it build the final obfuscator:
1111

12-
Obfuscator obfuscator = JSONObfuscator.builder()
13-
.withProperty("password", Obfuscator.fixedLength(3))
14-
.build();
12+
```java
13+
Obfuscator obfuscator = JSONObfuscator.builder()
14+
.withProperty("password", Obfuscator.fixedLength(3))
15+
.build();
16+
```
1517

1618
## Obfuscation for objects and/or arrays
1719

1820
By default, a JSON obfuscator will obfuscate all properties; for object and array properties, their contents in the document including opening and closing characters will be obfuscated. This can be turned on or off for all properties, or per property. For example:
1921

20-
Obfuscator obfuscator = JSONObfuscator.builder()
21-
.scalarsOnlyByDefault()
22-
// .scalarsOnlyByDefault() is equivalent to:
23-
// .forObjectsByDefault(ObfuscationMode.EXCLUDE)
24-
// .forArraysByDefault(ObfuscationMode.EXCLUDE)
25-
.withProperty("password", Obfuscator.fixedLength(3))
26-
.withProperty("complex", Obfuscator.fixedLength(3))
27-
.forObjects(ObfuscationMode.OBFUSCATE) // override the default setting
28-
.withProperty("arrayOfComplex", Obfuscator.fixedLength(3))
29-
.forArrays(ObfuscationMode.INHERIT_OVERRIDABLE) // override the default setting
30-
.build();
22+
```java
23+
Obfuscator obfuscator = JSONObfuscator.builder()
24+
.scalarsOnlyByDefault()
25+
// .scalarsOnlyByDefault() is equivalent to:
26+
// .forObjectsByDefault(ObfuscationMode.EXCLUDE)
27+
// .forArraysByDefault(ObfuscationMode.EXCLUDE)
28+
.withProperty("password", Obfuscator.fixedLength(3))
29+
.withProperty("complex", Obfuscator.fixedLength(3))
30+
.forObjects(ObfuscationMode.OBFUSCATE) // override the default setting
31+
.withProperty("arrayOfComplex", Obfuscator.fixedLength(3))
32+
.forArrays(ObfuscationMode.INHERIT_OVERRIDABLE) // override the default setting
33+
.build();
34+
```
3135

3236
The four possible modes for both objects and arrays are:
3337
* `EXCLUDE`: don't obfuscate nested objects or arrays, but instead traverse into them.
@@ -39,77 +43,93 @@ The four possible modes for both objects and arrays are:
3943

4044
JSON obfuscators perform obfuscating by generating new, obfuscated JSON documents. By default this will use pretty-printing. This can be turned off when creating JSON obfuscators:
4145

42-
Obfuscator obfuscator = JSONObfuscator.builder()
43-
.withProperty("password", Obfuscator.fixedLength(3))
44-
.withPrettyPrinting(false)
45-
.build();
46+
```java
47+
Obfuscator obfuscator = JSONObfuscator.builder()
48+
.withProperty("password", Obfuscator.fixedLength(3))
49+
.withPrettyPrinting(false)
50+
.build();
51+
```
4652

4753
If the structure of the original JSON document needs to be kept intact, you should use [obfuscation-jackson](https://robtimus.github.io/obfuscation-jackson/) instead.
4854

4955
## Producing valid JSON
5056

5157
If string values are obfuscated, the obfuscated value remains quoted. For other values, the obfuscated values are not quoted. This could lead to invalid JSON. For instance:
5258

53-
{
54-
"boolean": ***
55-
}
59+
```json
60+
{
61+
"boolean": ***
62+
}
63+
```
5664

5765
For most use cases this is not an issue. If the obfuscated JSON needs to be valid, this can be achieved by converting obfuscated values to strings:
5866

59-
Obfuscator obfuscator = JSONObfuscator.builder()
60-
.withProperty("boolean", Obfuscator.fixedLength(3))
61-
.produceValidJSON()
62-
.build();
67+
```java
68+
Obfuscator obfuscator = JSONObfuscator.builder()
69+
.withProperty("boolean", Obfuscator.fixedLength(3))
70+
.produceValidJSON()
71+
.build();
72+
```
6373

6474
This will turn the above result into this:
6575

66-
{
67-
"boolean": "***"
68-
}
76+
```json
77+
{
78+
"boolean": "***"
79+
}
80+
```
6981

7082
An exception is made for [Obfuscator.none()](https://robtimus.github.io/obfuscation-core/apidocs/com/github/robtimus/obfuscation/Obfuscator.html#none--). Since this obfuscator does not actually obfuscate anything, any property that is configured to use it will be added as-is. This still allows skipping obfuscating values inside certain properties:
7183

72-
Obfuscator obfuscator = JSONObfuscator.builder()
73-
.withProperty("object", Obfuscator.none())
74-
.withProperty("boolean", Obfuscator.fixedLength(3))
75-
.produceValidJSON()
76-
.build();
84+
```java
85+
Obfuscator obfuscator = JSONObfuscator.builder()
86+
.withProperty("object", Obfuscator.none())
87+
.withProperty("boolean", Obfuscator.fixedLength(3))
88+
.produceValidJSON()
89+
.build();
90+
```
7791

7892
Possible output:
7993

80-
{
81-
"boolean": "***",
82-
"object": {
83-
"boolean": true
84-
}
94+
```json
95+
{
96+
"boolean": "***",
97+
"object": {
98+
"boolean": true
8599
}
100+
}
101+
```
86102

87103
## Handling malformed JSON
88104

89105
If malformed JSON is encountered, obfuscation aborts. It will add a message to the result indicating that obfuscation was aborted. This message can be changed or turned off when creating JSON obfuscators:
90106

91-
Obfuscator obfuscator = JSONObfuscator.builder()
92-
.withProperty("password", Obfuscator.fixedLength(3))
93-
// use null to turn it off
94-
.withMalformedJSONWarning("<invalid JSON>")
95-
.build();
107+
```java
108+
Obfuscator obfuscator = JSONObfuscator.builder()
109+
.withProperty("password", Obfuscator.fixedLength(3))
110+
// use null to turn it off
111+
.withMalformedJSONWarning("<invalid JSON>")
112+
.build();
113+
```
96114

97115
## Changing JSON implementation
98116

99117
This library uses the Java API for Processing JSON ([JSR 374](https://www.jcp.org/en/jsr/detail?id=374)) for parsing and generating JSON. By default it uses the Glassfish reference implementation. If you want to use a different implementation instead, you should exclude the Glassfish dependency, and add a dependency for that different implementation. In your POM:
100118

101-
<dependency>
102-
<groupId>com.github.robtimus</groupId>
103-
<artifactId>obfuscation-json</artifactId>
104-
<version>...</version>
105-
<exclusions>
106-
<exclusion>
107-
<groupId>org.glassfish</groupId>
108-
<artifactId>javax.json</artifactId>
109-
</exclusion>
110-
</exclusions>
111-
</dependency>
112-
113-
<dependency>
114-
...
115-
</dependency>
119+
```xml
120+
<dependency>
121+
<groupId>com.github.robtimus</groupId>
122+
<artifactId>obfuscation-json</artifactId>
123+
<version>...</version>
124+
<exclusions>
125+
<exclusion>
126+
<groupId>org.glassfish</groupId>
127+
<artifactId>javax.json</artifactId>
128+
</exclusion>
129+
</exclusions>
130+
</dependency>
131+
132+
<dependency>
133+
...
134+
</dependency>
135+
```

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<parent>
2323
<groupId>com.github.robtimus</groupId>
2424
<artifactId>robtimus-parent</artifactId>
25-
<version>1.14</version>
25+
<version>1.15</version>
2626
<relativePath />
2727
</parent>
2828

src/site/site.xml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@
1515
limitations under the License.
1616
-->
1717

18-
<project name="obfuscation-json"
19-
xmlns="http://maven.apache.org/DECORATION/1.8.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
20-
xsi:schemaLocation="http://maven.apache.org/DECORATION/1.8.0 https://maven.apache.org/xsd/decoration-1.8.0.xsd">
18+
<site name="obfuscation-json"
19+
xmlns="http://maven.apache.org/SITE/2.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
20+
xsi:schemaLocation="http://maven.apache.org/SITE/2.0.0 https://maven.apache.org/xsd/site-2.0.0.xsd">
21+
22+
<bannerLeft name="obfuscation-json" />
2123

2224
<body>
2325
<menu name="obfuscation-json">
@@ -27,4 +29,4 @@
2729
<item name="Javadoc" href="apidocs/index.html" />
2830
</menu>
2931
</body>
30-
</project>
32+
</site>

0 commit comments

Comments
 (0)