Compare commits
4 Commits
main
...
issue/4454
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9439e7feef | ||
|
|
f80e2e7f1d | ||
|
|
d1ed973fa0 | ||
|
|
24e1ae0a2b |
2
pom.xml
2
pom.xml
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
<groupId>org.springframework.data</groupId>
|
<groupId>org.springframework.data</groupId>
|
||||||
<artifactId>spring-data-mongodb-parent</artifactId>
|
<artifactId>spring-data-mongodb-parent</artifactId>
|
||||||
<version>4.2.0-SNAPSHOT</version>
|
<version>4.2.x-4454-SNAPSHOT</version>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
|
|
||||||
<name>Spring Data MongoDB</name>
|
<name>Spring Data MongoDB</name>
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.springframework.data</groupId>
|
<groupId>org.springframework.data</groupId>
|
||||||
<artifactId>spring-data-mongodb-parent</artifactId>
|
<artifactId>spring-data-mongodb-parent</artifactId>
|
||||||
<version>4.2.0-SNAPSHOT</version>
|
<version>4.2.x-4454-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.springframework.data</groupId>
|
<groupId>org.springframework.data</groupId>
|
||||||
<artifactId>spring-data-mongodb-parent</artifactId>
|
<artifactId>spring-data-mongodb-parent</artifactId>
|
||||||
<version>4.2.0-SNAPSHOT</version>
|
<version>4.2.x-4454-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.springframework.data</groupId>
|
<groupId>org.springframework.data</groupId>
|
||||||
<artifactId>spring-data-mongodb-parent</artifactId>
|
<artifactId>spring-data-mongodb-parent</artifactId>
|
||||||
<version>4.2.0-SNAPSHOT</version>
|
<version>4.2.x-4454-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@@ -203,8 +203,9 @@ class MappingMongoJsonSchemaCreator implements MongoJsonSchemaCreator {
|
|||||||
target.properties(nestedProperties.toArray(new JsonSchemaProperty[0])), required));
|
target.properties(nestedProperties.toArray(new JsonSchemaProperty[0])), required));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return targetProperties.size() == 1 ? targetProperties.iterator().next()
|
JsonSchemaProperty schemaProperty = targetProperties.size() == 1 ? targetProperties.iterator().next()
|
||||||
: JsonSchemaProperty.merged(targetProperties);
|
: JsonSchemaProperty.merged(targetProperties);
|
||||||
|
return applyEncryptionDataIfNecessary(property, schemaProperty);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ import org.springframework.data.mongodb.core.schema.TypedJsonSchemaObject.Timest
|
|||||||
import org.springframework.lang.Nullable;
|
import org.springframework.lang.Nullable;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.util.ObjectUtils;
|
import org.springframework.util.ObjectUtils;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link JsonSchemaProperty} implementation.
|
* {@link JsonSchemaProperty} implementation.
|
||||||
@@ -1139,7 +1140,9 @@ public class IdentifiableJsonSchemaProperty<T extends JsonSchemaObject> implemen
|
|||||||
enc.append("bsonType", type.toBsonType().value()); // TODO: no samples with type -> is it bson type all the way?
|
enc.append("bsonType", type.toBsonType().value()); // TODO: no samples with type -> is it bson type all the way?
|
||||||
}
|
}
|
||||||
|
|
||||||
enc.append("algorithm", algorithm);
|
if (StringUtils.hasText(algorithm)) {
|
||||||
|
enc.append("algorithm", algorithm);
|
||||||
|
}
|
||||||
|
|
||||||
propertySpecification.append("encrypt", enc);
|
propertySpecification.append("encrypt", enc);
|
||||||
|
|
||||||
|
|||||||
@@ -271,6 +271,17 @@ class MappingMongoJsonSchemaCreatorUnitTests {
|
|||||||
.containsEntry("properties.value", new Document("type", "string"));
|
.containsEntry("properties.value", new Document("type", "string"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test // GH-4454
|
||||||
|
void wrapEncryptedEntityTypeLikeProperty() {
|
||||||
|
|
||||||
|
MongoJsonSchema schema = MongoJsonSchemaCreator.create() //
|
||||||
|
.filter(MongoJsonSchemaCreator.encryptedOnly()) // filter non encrypted fields
|
||||||
|
.createSchemaFor(WithEncryptedEntityLikeProperty.class);
|
||||||
|
|
||||||
|
assertThat(schema.schemaDocument()) //
|
||||||
|
.containsEntry("properties.domainTypeValue", Document.parse("{'encrypt': {'bsonType': 'object' } }"));
|
||||||
|
}
|
||||||
|
|
||||||
// --> TYPES AND JSON
|
// --> TYPES AND JSON
|
||||||
|
|
||||||
// --> ENUM
|
// --> ENUM
|
||||||
@@ -676,4 +687,9 @@ class MappingMongoJsonSchemaCreatorUnitTests {
|
|||||||
static class PropertyClashWithA {
|
static class PropertyClashWithA {
|
||||||
Integer aNonEncrypted;
|
Integer aNonEncrypted;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Encrypted(algorithm = "AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic")
|
||||||
|
static class WithEncryptedEntityLikeProperty {
|
||||||
|
@Encrypted SomeDomainType domainTypeValue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,8 +33,10 @@ import org.springframework.context.annotation.Configuration;
|
|||||||
import org.springframework.dao.DataIntegrityViolationException;
|
import org.springframework.dao.DataIntegrityViolationException;
|
||||||
import org.springframework.data.mongodb.config.AbstractMongoClientConfiguration;
|
import org.springframework.data.mongodb.config.AbstractMongoClientConfiguration;
|
||||||
import org.springframework.data.mongodb.core.CollectionOptions.ValidationOptions;
|
import org.springframework.data.mongodb.core.CollectionOptions.ValidationOptions;
|
||||||
|
import org.springframework.data.mongodb.core.mapping.Encrypted;
|
||||||
import org.springframework.data.mongodb.core.mapping.Field;
|
import org.springframework.data.mongodb.core.mapping.Field;
|
||||||
import org.springframework.data.mongodb.core.query.Criteria;
|
import org.springframework.data.mongodb.core.query.Criteria;
|
||||||
|
import org.springframework.data.mongodb.core.schema.MongoJsonSchema;
|
||||||
import org.springframework.data.mongodb.test.util.Client;
|
import org.springframework.data.mongodb.test.util.Client;
|
||||||
import org.springframework.data.mongodb.test.util.MongoClientExtension;
|
import org.springframework.data.mongodb.test.util.MongoClientExtension;
|
||||||
import org.springframework.lang.Nullable;
|
import org.springframework.lang.Nullable;
|
||||||
@@ -46,11 +48,13 @@ import com.mongodb.client.model.ValidationLevel;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Integration tests for {@link CollectionOptions#validation(ValidationOptions)} using
|
* Integration tests for {@link CollectionOptions#validation(ValidationOptions)} using
|
||||||
* {@link org.springframework.data.mongodb.core.validation.CriteriaValidator} and
|
* {@link org.springframework.data.mongodb.core.validation.CriteriaValidator},
|
||||||
* {@link org.springframework.data.mongodb.core.validation.DocumentValidator}.
|
* {@link org.springframework.data.mongodb.core.validation.DocumentValidator} and
|
||||||
|
* {@link org.springframework.data.mongodb.core.validation.JsonSchemaValidator}.
|
||||||
*
|
*
|
||||||
* @author Andreas Zink
|
* @author Andreas Zink
|
||||||
* @author Christoph Strobl
|
* @author Christoph Strobl
|
||||||
|
* @author Julia Lee
|
||||||
*/
|
*/
|
||||||
@ExtendWith({ MongoClientExtension.class, SpringExtension.class })
|
@ExtendWith({ MongoClientExtension.class, SpringExtension.class })
|
||||||
public class MongoTemplateValidationTests {
|
public class MongoTemplateValidationTests {
|
||||||
@@ -186,6 +190,20 @@ public class MongoTemplateValidationTests {
|
|||||||
assertThat(getValidatorInfo(COLLECTION_NAME)).isEqualTo(new Document("customName", new Document("$type", "bool")));
|
assertThat(getValidatorInfo(COLLECTION_NAME)).isEqualTo(new Document("customName", new Document("$type", "bool")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test // GH-4454
|
||||||
|
public void failsJsonSchemaValidationForEncryptedDomainEntityProperty() {
|
||||||
|
|
||||||
|
MongoJsonSchema schema = MongoJsonSchemaCreator.create().createSchemaFor(BeanWithEncryptedDomainEntity.class);
|
||||||
|
template.createCollection(COLLECTION_NAME, CollectionOptions.empty().schema(schema));
|
||||||
|
|
||||||
|
BeanWithEncryptedDomainEntity person = new BeanWithEncryptedDomainEntity();
|
||||||
|
person.encryptedDomainEntity = new SimpleBean("some string", 100, null);
|
||||||
|
|
||||||
|
assertThatExceptionOfType(DataIntegrityViolationException.class)
|
||||||
|
.isThrownBy(() -> template.save(person))
|
||||||
|
.withMessageContaining("Document failed validation");
|
||||||
|
}
|
||||||
|
|
||||||
private Document getCollectionOptions(String collectionName) {
|
private Document getCollectionOptions(String collectionName) {
|
||||||
return getCollectionInfo(collectionName).get("options", Document.class);
|
return getCollectionInfo(collectionName).get("options", Document.class);
|
||||||
}
|
}
|
||||||
@@ -271,4 +289,10 @@ public class MongoTemplateValidationTests {
|
|||||||
return "MongoTemplateValidationTests.SimpleBean(nonNullString=" + this.getNonNullString() + ", rangedInteger=" + this.getRangedInteger() + ", customFieldName=" + this.getCustomFieldName() + ")";
|
return "MongoTemplateValidationTests.SimpleBean(nonNullString=" + this.getNonNullString() + ", rangedInteger=" + this.getRangedInteger() + ", customFieldName=" + this.getCustomFieldName() + ")";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@org.springframework.data.mongodb.core.mapping.Document(collection = COLLECTION_NAME)
|
||||||
|
@Encrypted(algorithm = "AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic")
|
||||||
|
static class BeanWithEncryptedDomainEntity {
|
||||||
|
@Encrypted SimpleBean encryptedDomainEntity;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user