Project mangled encrypted field names. (#2058)

Closes #2057.
This commit is contained in:
Michael Reiche
2025-06-12 15:50:23 -07:00
committed by mikereiche
parent 728aabdfa0
commit 559ba38ac8
3 changed files with 13 additions and 2 deletions

View File

@@ -1130,7 +1130,7 @@ public class MappingCouchbaseConverter extends AbstractCouchbaseConverter implem
}
}
String maybeMangle(PersistentProperty<?> property) {
public String maybeMangle(PersistentProperty<?> property) {
Assert.notNull(property, "property");
if (!conversions.hasValueConverter(property)) {
return ((CouchbasePersistentProperty) property).getFieldName();

View File

@@ -34,6 +34,7 @@ import java.util.regex.Pattern;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.couchbase.core.convert.CouchbaseConverter;
import org.springframework.data.couchbase.core.convert.MappingCouchbaseConverter;
import org.springframework.data.couchbase.core.mapping.CouchbaseDocument;
import org.springframework.data.couchbase.core.mapping.CouchbaseList;
import org.springframework.data.couchbase.core.mapping.CouchbasePersistentProperty;
@@ -332,7 +333,13 @@ public class StringBasedN1qlQueryParser {
if (fieldList == null || fieldList.contains(prop.getFieldName())) {
PersistentPropertyPath<CouchbasePersistentProperty> path = couchbaseConverter.getMappingContext()
.getPersistentPropertyPath(prop.getName(), persistentEntity.getTypeInformation().getType());
projectField = N1qlQueryCreator.addMetaIfRequired(bucketName, path, prop, persistentEntity).toString();
String unmangled = prop.getFieldName();
String maybeMangled =((MappingCouchbaseConverter)couchbaseConverter).maybeMangle(prop);
if(maybeMangled.equals(unmangled)) {
projectField = N1qlQueryCreator.addMetaIfRequired(bucketName, path, prop, persistentEntity).toString();
} else {
projectField = i(maybeMangled).toString();
}
if (sb.length() > 0) {
sb.append(", ");
}

View File

@@ -154,10 +154,14 @@ public class CouchbaseRepositoryFieldLevelEncryptionIntegrationTests extends Clu
assertFalse(userEncryptedRepository.existsById(user.getId()));
userEncryptedRepository.save(user);
// read the user with Spring
Optional<UserEncrypted> writeSpringReadSpring = userEncryptedRepository.findById(user.getId());
assertTrue(writeSpringReadSpring.isPresent());
writeSpringReadSpring.ifPresent(u -> assertEquals(user, u));
List<UserEncrypted> writeSpringReadSpring2 = userEncryptedRepository.findAll();
assertEquals(user, writeSpringReadSpring2.stream().filter(u -> u.getId().equals(user.getId())).findFirst().get());
if (cleanAfter) {
try {
couchbaseTemplate.removeById(UserEncrypted.class).one(user.getId());