Skip to content

Commit b7d1654

Browse files
authored
Revert fle using generic converter (#1552)
* Revert "Fix up FLE support. (#1550)" Closes #1551. This reverts commit 5fcb8ed. * Revert "Field Level Encryption Support. (#1546)" This reverts commit 921b8c2. Closes #1551.
1 parent 5fcb8ed commit b7d1654

16 files changed

+64
-1004
lines changed

README.adoc

-7
Original file line numberDiff line numberDiff line change
@@ -200,13 +200,6 @@ The generated documentation is available from `target/site/reference/html/index.
200200
popd
201201
----
202202

203-
=== Intellij Issue with Importing pom.xml
204-
205-
There is an issue in Intellij that prevents it from importing modules when one of the module
206-
directories has the same name as the project directory. The work-around is to create a new module (any name, any type will suffice).
207-
When Intellij creates the new module, it will also recognize the existing modules. Once the new module is
208-
created, it can be deleted and Intellij will now recognize the existing modules.
209-
210203
The generated documentation is available from `target/site/reference/html/index.html`.
211204

212205
== Examples

spring-data-couchbase/pom.xml

+2-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
43

54
<modelVersion>4.0.0</modelVersion>
65

@@ -218,13 +217,6 @@
218217
<scope>test</scope>
219218
</dependency>
220219

221-
<dependency>
222-
<groupId>com.couchbase.client</groupId>
223-
<artifactId>couchbase-encryption</artifactId>
224-
<version>3.1.0</version>
225-
<scope>test</scope>
226-
</dependency>
227-
228220
</dependencies>
229221

230222
<repositories>
@@ -311,9 +303,7 @@
311303
</goals>
312304
<configuration>
313305
<outputDirectory>target/generated-test-sources</outputDirectory>
314-
<processor>
315-
org.springframework.data.couchbase.repository.support.CouchbaseAnnotationProcessor
316-
</processor>
306+
<processor>org.springframework.data.couchbase.repository.support.CouchbaseAnnotationProcessor</processor>
317307
</configuration>
318308
</execution>
319309
</executions>

spring-data-couchbase/src/main/java/org/springframework/data/couchbase/config/AbstractCouchbaseConfiguration.java

+8-46
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,15 @@
1818

1919
import static com.couchbase.client.java.ClusterOptions.clusterOptions;
2020

21-
import java.util.ArrayList;
21+
import java.util.Collections;
2222
import java.util.HashSet;
23-
import java.util.List;
2423
import java.util.Set;
2524

2625
import org.springframework.beans.factory.config.BeanDefinition;
2726
import org.springframework.context.annotation.Bean;
2827
import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider;
2928
import org.springframework.context.annotation.Configuration;
3029
import org.springframework.context.annotation.Role;
31-
import org.springframework.core.convert.converter.GenericConverter;
3230
import org.springframework.core.type.filter.AnnotationTypeFilter;
3331
import org.springframework.data.convert.CustomConversions;
3432
import org.springframework.data.couchbase.CouchbaseClientFactory;
@@ -37,7 +35,6 @@
3735
import org.springframework.data.couchbase.core.ReactiveCouchbaseTemplate;
3836
import org.springframework.data.couchbase.core.convert.CouchbaseCustomConversions;
3937
import org.springframework.data.couchbase.core.convert.MappingCouchbaseConverter;
40-
import org.springframework.data.couchbase.core.convert.OtherConverters;
4138
import org.springframework.data.couchbase.core.convert.translation.JacksonTranslationService;
4239
import org.springframework.data.couchbase.core.convert.translation.TranslationService;
4340
import org.springframework.data.couchbase.core.mapping.CouchbaseMappingContext;
@@ -152,9 +149,7 @@ public ClusterEnvironment couchbaseClusterEnvironment() {
152149
if (!nonShadowedJacksonPresent()) {
153150
throw new CouchbaseException("non-shadowed Jackson not present");
154151
}
155-
CryptoManager cryptoManager = cryptoManager();
156-
builder.jsonSerializer(JacksonJsonSerializer.create(couchbaseObjectMapper(cryptoManager)));
157-
builder.cryptoManager(cryptoManager);
152+
builder.jsonSerializer(JacksonJsonSerializer.create(couchbaseObjectMapper()));
158153
configureEnvironment(builder);
159154
return builder.build();
160155
}
@@ -285,8 +280,8 @@ public MappingCouchbaseConverter mappingCouchbaseConverter(CouchbaseMappingConte
285280
@Bean
286281
public TranslationService couchbaseTranslationService() {
287282
final JacksonTranslationService jacksonTranslationService = new JacksonTranslationService();
288-
jacksonTranslationService.setObjectMapper(couchbaseObjectMapper(cryptoManager()));
289283
jacksonTranslationService.afterPropertiesSet();
284+
290285
// for sdk3, we need to ask the mapper _it_ uses to ignore extra fields...
291286
JacksonTransformers.MAPPER.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
292287
return jacksonTranslationService;
@@ -313,25 +308,10 @@ public CouchbaseMappingContext couchbaseMappingContext(CustomConversions customC
313308
*/
314309

315310
public ObjectMapper couchbaseObjectMapper() {
316-
return couchbaseObjectMapper(cryptoManager());
317-
}
318-
319-
/**
320-
* Creates a {@link ObjectMapper} for the jsonSerializer of the ClusterEnvironment
321-
*
322-
* @param cryptoManager
323-
* @return ObjectMapper
324-
*/
325-
326-
ObjectMapper mapper;
327-
328-
public ObjectMapper couchbaseObjectMapper(CryptoManager cryptoManager) {
329-
if (mapper != null) {
330-
return mapper;
331-
}
332-
mapper = new ObjectMapper(); // or use the one from the Java SDK (?) JacksonTransformers.MAPPER
311+
ObjectMapper mapper = new ObjectMapper();
333312
mapper.configure(com.fasterxml.jackson.databind.DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
334313
mapper.registerModule(new JsonValueModule());
314+
CryptoManager cryptoManager = null;
335315
if (cryptoManager != null) {
336316
mapper.registerModule(new EncryptionModule(cryptoManager));
337317
}
@@ -340,7 +320,7 @@ public ObjectMapper couchbaseObjectMapper(CryptoManager cryptoManager) {
340320

341321
/**
342322
* The default blocking transaction manager. It is an implementation of CallbackPreferringTransactionManager
343-
* CallbackPreferringTransactionManagers do not play well with test-cases that rely
323+
* CallbackPreferrringTransactionmanagers do not play well with test-cases that rely
344324
* on @TestTransaction/@BeforeTransaction/@AfterTransaction
345325
*
346326
* @param clientFactory
@@ -361,7 +341,6 @@ CouchbaseCallbackTransactionManager couchbaseTransactionManager(CouchbaseClientF
361341
TransactionTemplate couchbaseTransactionTemplate(CouchbaseCallbackTransactionManager couchbaseTransactionManager) {
362342
return new TransactionTemplate(couchbaseTransactionManager);
363343
}
364-
365344
/**
366345
* The default TransactionalOperator.
367346
*
@@ -400,28 +379,11 @@ protected boolean autoIndexCreation() {
400379
* and {@link #couchbaseMappingContext(CustomConversions)}. Returns an empty {@link CustomConversions} instance by
401380
* default.
402381
*
403-
* @param cryptoManagerOptional optional cryptoManager. Make varargs for backwards compatibility.
404382
* @return must not be {@literal null}.
405383
*/
406384
@Bean(name = BeanNames.COUCHBASE_CUSTOM_CONVERSIONS)
407-
public CustomConversions customConversions(CryptoManager... cryptoManagerOptional) {
408-
assert (cryptoManagerOptional == null || cryptoManagerOptional.length <= 1);
409-
CryptoManager cryptoManager = cryptoManagerOptional != null && cryptoManagerOptional.length == 1
410-
? cryptoManagerOptional[0]
411-
: null;
412-
List<GenericConverter> newConverters = new ArrayList();
413-
// the cryptoConverters take an argument, so they cannot be created in the
414-
// static block of CouchbaseCustomConversions. And they must be set before the super() constructor
415-
// in CouchbaseCustomerConversions
416-
if (cryptoManager != null) {
417-
newConverters.addAll(OtherConverters.getCryptoConverters(cryptoManager));
418-
}
419-
return new CouchbaseCustomConversions(newConverters);
420-
}
421-
422-
@Bean
423-
protected CryptoManager cryptoManager() {
424-
return null;
385+
public CustomConversions customConversions() {
386+
return new CouchbaseCustomConversions(Collections.emptyList());
425387
}
426388

427389
/**

spring-data-couchbase/src/main/java/org/springframework/data/couchbase/core/convert/AbstractCouchbaseConverter.java

-34
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,15 @@
2020

2121
import org.springframework.beans.factory.InitializingBean;
2222
import org.springframework.core.convert.ConversionService;
23-
import org.springframework.core.convert.TypeDescriptor;
2423
import org.springframework.core.convert.support.GenericConversionService;
2524
import org.springframework.data.convert.CustomConversions;
26-
import org.springframework.data.couchbase.core.mapping.CouchbasePersistentProperty;
27-
import org.springframework.data.mapping.model.ConvertingPropertyAccessor;
2825
import org.springframework.data.mapping.model.EntityInstantiators;
2926

3027
/**
3128
* An abstract {@link CouchbaseConverter} that provides the basics for the {@link MappingCouchbaseConverter}.
3229
*
3330
* @author Michael Nitschinger
3431
* @author Mark Paluch
35-
* @author Michael Reiche
3632
*/
3733
public abstract class AbstractCouchbaseConverter implements CouchbaseConverter, InitializingBean {
3834

@@ -97,36 +93,6 @@ public void afterPropertiesSet() {
9793
conversions.registerConvertersIn(conversionService);
9894
}
9995

100-
/**
101-
* This convertForWriteIfNeeded takes a property and accessor so that the annotations can be accessed (ie. @Encrypted)
102-
*
103-
* @param prop the property to be converted to the class that would actually be stored.
104-
* @param accessor the property accessor
105-
* @return
106-
*/
107-
@Override
108-
public Object convertForWriteIfNeeded(CouchbasePersistentProperty prop, ConvertingPropertyAccessor<Object> accessor) {
109-
Object value = accessor.getProperty(prop, prop.getType());
110-
if (value == null) {
111-
return null;
112-
}
113-
114-
Object result = this.conversions.getCustomWriteTarget(prop.getType()) //
115-
.map(it -> this.conversionService.convert(value, new TypeDescriptor(prop.getField()),
116-
TypeDescriptor.valueOf(it))) //
117-
.orElseGet(() -> Enum.class.isAssignableFrom(value.getClass()) ? ((Enum<?>) value).name() : value);
118-
119-
return result;
120-
121-
}
122-
123-
/**
124-
* This convertForWriteIfNeed takes only the value to convert. It cannot access the annotations of the Field being
125-
* converted.
126-
*
127-
* @param value the value to be converted to the class that would actually be stored.
128-
* @return
129-
*/
13096
@Override
13197
public Object convertForWriteIfNeeded(Object value) {
13298
if (value == null) {

spring-data-couchbase/src/main/java/org/springframework/data/couchbase/core/convert/CouchbaseConverter.java

+1-13
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import org.springframework.data.couchbase.core.mapping.CouchbasePersistentEntity;
2323
import org.springframework.data.couchbase.core.mapping.CouchbasePersistentProperty;
2424
import org.springframework.data.mapping.Alias;
25-
import org.springframework.data.mapping.model.ConvertingPropertyAccessor;
2625
import org.springframework.data.util.TypeInformation;
2726

2827
/**
@@ -38,24 +37,13 @@ public interface CouchbaseConverter
3837

3938
/**
4039
* Convert the value if necessary to the class that would actually be stored, or leave it as is if no conversion
41-
* needed. This method cannot access the annotations of the field.
40+
* needed.
4241
*
4342
* @param value the value to be converted to the class that would actually be stored.
4443
* @return the converted value (or the same value if no conversion necessary).
4544
*/
4645
Object convertForWriteIfNeeded(Object value);
4746

48-
/**
49-
* Convert the value if necessary to the class that would actually be stored, or leave it as is if no conversion
50-
* needed. This method can access the annotations of the field.
51-
*
52-
* @param source the property to be converted to the class that would actually be stored.
53-
* @param accessor the property accessor
54-
* @return the converted value (or the same value if no conversion necessary).
55-
*/
56-
Object convertForWriteIfNeeded(final CouchbasePersistentProperty source,
57-
final ConvertingPropertyAccessor<Object> accessor);
58-
5947
/**
6048
* Return the Class that would actually be stored for a given Class.
6149
*

spring-data-couchbase/src/main/java/org/springframework/data/couchbase/core/convert/CouchbaseCustomConversions.java

-41
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222

2323
import org.springframework.data.mapping.model.SimpleTypeHolder;
2424

25-
import com.couchbase.client.core.encryption.CryptoManager;
26-
2725
/**
2826
* Value object to capture custom conversion.
2927
* <p>
@@ -34,7 +32,6 @@
3432
* @author Oliver Gierke
3533
* @author Mark Paluch
3634
* @author Subhashni Balakrishnan
37-
* @Michael Reiche
3835
* @see org.springframework.data.convert.CustomConversions
3936
* @see SimpleTypeHolder
4037
* @since 2.0
@@ -45,18 +42,6 @@ public class CouchbaseCustomConversions extends org.springframework.data.convert
4542

4643
private static final List<Object> STORE_CONVERTERS;
4744

48-
private CryptoManager cryptoManager;
49-
50-
/**
51-
* Expose the CryptoManager used by a DecryptingReadingConverter or EncryptingWritingConverter, if any. There can only
52-
* be one. MappingCouchbaseConverter needs it.
53-
*
54-
* @return cryptoManager
55-
*/
56-
public CryptoManager getCryptoManager() {
57-
return cryptoManager;
58-
}
59-
6045
static {
6146

6247
List<Object> converters = new ArrayList<>();
@@ -76,31 +61,5 @@ public CryptoManager getCryptoManager() {
7661
*/
7762
public CouchbaseCustomConversions(final List<?> converters) {
7863
super(STORE_CONVERSIONS, converters);
79-
for (Object c : converters) {
80-
if (c instanceof DecryptingReadingConverter) {
81-
CryptoManager foundCryptoManager = ((DecryptingReadingConverter) c).cryptoManager;
82-
if (foundCryptoManager == null) {
83-
throw new RuntimeException(("DecryptingReadingConverter must have a cryptoManager"));
84-
} else {
85-
if (cryptoManager != null && this.cryptoManager != cryptoManager) {
86-
throw new RuntimeException(
87-
"all DecryptingReadingConverters and EncryptingWringConverters must use " + " a single CryptoManager");
88-
}
89-
}
90-
cryptoManager = foundCryptoManager;
91-
}
92-
if (c instanceof EncryptingWritingConverter) {
93-
CryptoManager foundCryptoManager = ((EncryptingWritingConverter) c).cryptoManager;
94-
if (foundCryptoManager == null) {
95-
throw new RuntimeException(("EncryptingWritingConverter must have a cryptoManager"));
96-
} else {
97-
if (cryptoManager != null && this.cryptoManager != cryptoManager) {
98-
throw new RuntimeException(
99-
"all DecryptingReadingConverters and EncryptingWringConverters must use " + " a single CryptoManager");
100-
}
101-
}
102-
cryptoManager = foundCryptoManager;
103-
}
104-
}
10564
}
10665
}

spring-data-couchbase/src/main/java/org/springframework/data/couchbase/core/convert/DecryptingReadingConverter.java

-69
This file was deleted.

0 commit comments

Comments
 (0)