Browse Source

allow keyId in raw format

issue/4185-light
Christoph Strobl 9 months ago
parent
commit
bd4fc25e6d
No known key found for this signature in database
GPG Key ID: E6054036D0C37A4B
  1. 18
      spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/schema/IdentifiableJsonSchemaProperty.java
  2. 4
      spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/encryption/MongoQueryableEncryptionCollectionCreationTests.java

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

@ -1085,7 +1085,7 @@ public class IdentifiableJsonSchemaProperty<T extends JsonSchemaObject> implemen
private final JsonSchemaProperty targetProperty; private final JsonSchemaProperty targetProperty;
private final @Nullable String algorithm; private final @Nullable String algorithm;
private final @Nullable String keyId; private final @Nullable Object keyId;
private final @Nullable List<?> keyIds; private final @Nullable List<?> keyIds;
/** /**
@ -1097,7 +1097,7 @@ public class IdentifiableJsonSchemaProperty<T extends JsonSchemaObject> implemen
this(target, null, null, null); this(target, null, null, null);
} }
private EncryptedJsonSchemaProperty(JsonSchemaProperty target, @Nullable String algorithm, @Nullable String keyId, private EncryptedJsonSchemaProperty(JsonSchemaProperty target, @Nullable String algorithm, @Nullable Object keyId,
@Nullable List<?> keyIds) { @Nullable List<?> keyIds) {
Assert.notNull(target, "Target must not be null"); Assert.notNull(target, "Target must not be null");
@ -1152,6 +1152,10 @@ public class IdentifiableJsonSchemaProperty<T extends JsonSchemaObject> implemen
return new EncryptedJsonSchemaProperty(targetProperty, algorithm, keyId, null); return new EncryptedJsonSchemaProperty(targetProperty, algorithm, keyId, null);
} }
public EncryptedJsonSchemaProperty keyId(Object keyId) {
return new EncryptedJsonSchemaProperty(targetProperty, algorithm, keyId, null);
}
/** /**
* @param keyId must not be {@literal null}. * @param keyId must not be {@literal null}.
* @return new instance of {@link EncryptedJsonSchemaProperty}. * @return new instance of {@link EncryptedJsonSchemaProperty}.
@ -1179,11 +1183,7 @@ public class IdentifiableJsonSchemaProperty<T extends JsonSchemaObject> implemen
if (!ObjectUtils.isEmpty(keyId)) { if (!ObjectUtils.isEmpty(keyId)) {
enc.append("keyId", keyId); enc.append("keyId", keyId);
} else if (!ObjectUtils.isEmpty(keyIds)) { } else if (!ObjectUtils.isEmpty(keyIds)) {
if(keyIds.size() == 1) { enc.append("keyId", keyIds);
enc.append("keyId", keyIds.iterator().next());
} else {
enc.append("keyId", keyIds);
}
} }
Type type = extractPropertyType(propertySpecification); Type type = extractPropertyType(propertySpecification);
@ -1226,10 +1226,10 @@ public class IdentifiableJsonSchemaProperty<T extends JsonSchemaObject> implemen
} }
public Object getKeyId() { public Object getKeyId() {
if(keyId != null) { if (keyId != null) {
return keyId; return keyId;
} }
if(keyIds != null && keyIds.size() == 1) { if (keyIds != null && keyIds.size() == 1) {
return keyIds.iterator().next(); return keyIds.iterator().next();
} }
return null; return null;

4
spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/encryption/MongoQueryableEncryptionCollectionCreationTests.java

@ -113,9 +113,9 @@ public class MongoQueryableEncryptionCollectionCreationTests {
range().min(-1L).max(1L).contention(0))); range().min(-1L).max(1L).contention(0)));
CollectionOptions schemaOptions = CollectionOptions.encrypted(MongoJsonSchema.builder() CollectionOptions schemaOptions = CollectionOptions.encrypted(MongoJsonSchema.builder()
.property(queryable(encrypted(int32("encryptedInt")).keys(key1), .property(queryable(encrypted(int32("encryptedInt")).keyId(key1),
new QueryCharacteristics(List.of(range().min(5).max(100).contention(1))))) new QueryCharacteristics(List.of(range().min(5).max(100).contention(1)))))
.property(queryable(encrypted(int64("nested.encryptedLong")).keys(key2), .property(queryable(encrypted(int64("nested.encryptedLong")).keyId(key2),
new QueryCharacteristics(List.of(range().min(-1L).max(1L).contention(0))))) new QueryCharacteristics(List.of(range().min(-1L).max(1L).contention(0)))))
.build()); .build());

Loading…
Cancel
Save