Fix up FLE support. (#1550)

Closes #763.
This commit is contained in:
Michael Reiche
2022-09-01 10:10:52 -07:00
committed by GitHub
parent 921b8c2e64
commit 5fcb8ed6b3
3 changed files with 8 additions and 9 deletions

View File

@@ -17,6 +17,7 @@ package org.springframework.data.couchbase.core.convert;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.nio.charset.StandardCharsets;
import java.util.HashSet;
import java.util.Set;
@@ -44,15 +45,11 @@ public class DecryptingReadingConverter implements ConditionalGenericConverter {
this.cryptoManager = cryptoManager;
}
public void setConversionService(ConversionService conversionService) {
this.conversionService = conversionService;
}
@Override
public Set<ConvertiblePair> getConvertibleTypes() {
Set<ConvertiblePair> convertiblePairs = new HashSet<>();
Class<?>[] clazzes = new Class[] { String.class, Integer.class, Long.class, Float.class, Double.class,
BigInteger.class, BigDecimal.class, Boolean.class };
BigInteger.class, BigDecimal.class, Boolean.class, Enum.class };
for (Class clazz : clazzes) {
convertiblePairs.add(new ConvertiblePair(CouchbaseDocument.class, clazz));
}
@@ -61,7 +58,8 @@ public class DecryptingReadingConverter implements ConditionalGenericConverter {
@Override
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
return source == null? null : new String(cryptoManager.decrypt(((CouchbaseDocument) source).getContent()));
return source == null ? null
: new String(cryptoManager.decrypt(((CouchbaseDocument) source).getContent()), StandardCharsets.UTF_8);
}
@Override

View File

@@ -17,6 +17,7 @@ package org.springframework.data.couchbase.core.convert;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
@@ -48,7 +49,7 @@ public class EncryptingWritingConverter implements ConditionalGenericConverter {
Set<ConvertiblePair> convertiblePairs = new HashSet<>();
Class<?>[] clazzes = new Class[] { String.class, Integer.class, Long.class, Float.class, Double.class,
BigInteger.class, BigDecimal.class, Boolean.class };
BigInteger.class, BigDecimal.class, Boolean.class, Enum.class };
for (Class clazz : clazzes) {
convertiblePairs.add(new ConvertiblePair(clazz, String.class));
}
@@ -63,7 +64,7 @@ public class EncryptingWritingConverter implements ConditionalGenericConverter {
com.couchbase.client.java.encryption.annotation.Encrypted ann = sourceType
.getAnnotation(com.couchbase.client.java.encryption.annotation.Encrypted.class);
Map<Object, Object> result = new HashMap<>();
result.putAll(cryptoManager.encrypt(source.toString().getBytes(), ann.encrypter()));
result.putAll(cryptoManager.encrypt(source.toString().getBytes(StandardCharsets.UTF_8), ann.encrypter()));
return new Encrypted(result);
}

View File

@@ -945,7 +945,7 @@ public class MappingCouchbaseConverter extends AbstractCouchbaseConverter implem
} else if (value instanceof CouchbaseList) {
return (R) readCollection(type, (CouchbaseList) value, parent);
} else {
return (R) getPotentiallyConvertedSimpleRead(value, type.getClass()); // type does not have annotations
return (R) getPotentiallyConvertedSimpleRead(value, type.getType()); // type does not have annotations
}
}