Skip to content

Commit 665aff4

Browse files
committed
DATAMONGO-2306 - Polishing.
Add Nullable annotation to nullable method args. Remove IV from JSON Schema as it is not listed in Mongo specs. Tweak wording in docs.
1 parent 76332cd commit 665aff4

File tree

3 files changed

+11
-17
lines changed

3 files changed

+11
-17
lines changed

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoEncryptionSettingsFactoryBean.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import org.bson.BsonDocument;
2222
import org.springframework.beans.factory.FactoryBean;
23+
import org.springframework.lang.Nullable;
2324

2425
import com.mongodb.AutoEncryptionSettings;
2526
import com.mongodb.MongoClientSettings;
@@ -104,7 +105,7 @@ public AutoEncryptionSettings getObject() {
104105
.build();
105106
}
106107

107-
private <K, V> Map<K, V> orEmpty(Map<K, V> source) {
108+
private <K, V> Map<K, V> orEmpty(@Nullable Map<K, V> source) {
108109
return source != null ? source : Collections.emptyMap();
109110
}
110111

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/schema/IdentifiableJsonSchemaProperty.java

+7-14
Original file line numberDiff line numberDiff line change
@@ -1057,26 +1057,23 @@ public static class EncryptedJsonSchemaProperty implements JsonSchemaProperty {
10571057

10581058
private final JsonSchemaProperty targetProperty;
10591059
private final @Nullable String algorithm;
1060-
private final @Nullable char[] keyId;
1061-
private final @Nullable char[] iv;
1060+
private final @Nullable String keyId;
10621061

10631062
/**
10641063
* Create new instance of {@link EncryptedJsonSchemaProperty} wrapping the given {@link JsonSchemaProperty target}.
10651064
*
10661065
* @param target must not be {@literal null}.
10671066
*/
10681067
public EncryptedJsonSchemaProperty(JsonSchemaProperty target) {
1069-
this(target, null, null, null);
1068+
this(target, null, null);
10701069
}
10711070

1072-
private EncryptedJsonSchemaProperty(JsonSchemaProperty target, @Nullable String algorithm, @Nullable char[] keyId,
1073-
@Nullable char[] iv) {
1071+
private EncryptedJsonSchemaProperty(JsonSchemaProperty target, @Nullable String algorithm, @Nullable String keyId) {
10741072

10751073
Assert.notNull(target, "Target must not be null!");
10761074
this.targetProperty = target;
10771075
this.algorithm = algorithm;
10781076
this.keyId = keyId;
1079-
this.iv = iv;
10801077
}
10811078

10821079
/**
@@ -1113,19 +1110,15 @@ public EncryptedJsonSchemaProperty aead_aes_256_cbc_hmac_sha_512_deterministic()
11131110
* @return new instance of {@link EncryptedJsonSchemaProperty}.
11141111
*/
11151112
public EncryptedJsonSchemaProperty algorithm(String algorithm) {
1116-
return new EncryptedJsonSchemaProperty(targetProperty, algorithm, keyId, iv);
1113+
return new EncryptedJsonSchemaProperty(targetProperty, algorithm, keyId);
11171114
}
11181115

11191116
/**
11201117
* @param key
11211118
* @return
11221119
*/
1123-
public EncryptedJsonSchemaProperty keyId(char[] key) {
1124-
return new EncryptedJsonSchemaProperty(targetProperty, algorithm, key, iv);
1125-
}
1126-
1127-
public EncryptedJsonSchemaProperty keyId(String key) {
1128-
return keyId(key.toCharArray());
1120+
public EncryptedJsonSchemaProperty keyId(String keyId) {
1121+
return new EncryptedJsonSchemaProperty(targetProperty, algorithm, keyId);
11291122
}
11301123

11311124
/*
@@ -1141,7 +1134,7 @@ public Document toDocument() {
11411134
Document enc = new Document();
11421135

11431136
if (!ObjectUtils.isEmpty(keyId)) {
1144-
enc.append("keyId", new String(keyId));
1137+
enc.append("keyId", keyId);
11451138
}
11461139

11471140
Type type = extractPropertyType(propertySpecification);

src/main/asciidoc/reference/mongo-json-schema.adoc

+2-2
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ template.find(query(matchingDocumentStructure(schema)), Person.class);
208208
[[mongo.jsonSchema.encrypted-fields]]
209209
==== Encrypted Fields
210210

211-
MongoDB 4.2 https://docs.mongodb.com/master/core/security-client-side-encryption/[Field Level Encryption] allows to directly secure certain properties.
211+
MongoDB 4.2 https://docs.mongodb.com/master/core/security-client-side-encryption/[Field Level Encryption] allows to directly encrypt individual properties.
212212

213213
Properties can be wrapped within an encrypted property when setting up the JSON Schema as shown in the example below.
214214

@@ -225,7 +225,7 @@ MongoJsonSchema schema = MongoJsonSchema.builder()
225225
----
226226
====
227227

228-
NOTE: Make sure to set the drivers `com.mongodb.AutoEncryptionSettings` to use client side encryption.
228+
NOTE: Make sure to set the drivers `com.mongodb.AutoEncryptionSettings` to use client-side encryption.
229229

230230
[[mongo.jsonSchema.types]]
231231
==== JSON Schema Types

0 commit comments

Comments
 (0)