INT-4342: White List for Payload Deserializer
JIRA: https://jira.spring.io/browse/INT-4342 Use similar code to Spring AMQP to add white list support for Integration's use of the `DeserializingMessageConverter`; introduce the `WhiteListDeserializingMessageConverter`. Polishing Missed this change in PR. Fix XSD attribute
This commit is contained in:
committed by
Artem Bilan
parent
5749c5b237
commit
0d495294ed
@@ -38,7 +38,6 @@ import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.core.serializer.support.DeserializingConverter;
|
||||
import org.springframework.core.serializer.support.SerializingConverter;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.annotation.Transient;
|
||||
@@ -71,6 +70,7 @@ import org.springframework.integration.store.MessageStore;
|
||||
import org.springframework.integration.store.SimpleMessageGroup;
|
||||
import org.springframework.integration.support.MutableMessage;
|
||||
import org.springframework.integration.support.MutableMessageBuilder;
|
||||
import org.springframework.integration.support.converter.WhiteListDeserializingConverter;
|
||||
import org.springframework.jmx.export.annotation.ManagedAttribute;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageHeaders;
|
||||
@@ -144,6 +144,8 @@ public class MongoDbMessageStore extends AbstractMessageGroupStore
|
||||
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
private String[] whiteListPatterns;
|
||||
|
||||
|
||||
/**
|
||||
* Create a MongoDbMessageStore using the provided {@link MongoDbFactory}.and the default collection name.
|
||||
@@ -177,6 +179,16 @@ public class MongoDbMessageStore extends AbstractMessageGroupStore
|
||||
this.applicationContext = applicationContext;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add patterns for packages/classes that are allowed to be deserialized. A class can
|
||||
* be fully qualified or a wildcard '*' is allowed at the beginning or end of the
|
||||
* class name. Examples: {@code com.foo.*}, {@code *.MyClass}.
|
||||
* @param patterns the patterns.
|
||||
*/
|
||||
public void addWhiteListPatterns(String... patterns) {
|
||||
this.whiteListPatterns = patterns;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
if (this.applicationContext != null) {
|
||||
@@ -504,7 +516,12 @@ public class MongoDbMessageStore extends AbstractMessageGroupStore
|
||||
customConverters.add(new MessageHistoryToDocumentConverter());
|
||||
customConverters.add(new DocumentToGenericMessageConverter());
|
||||
customConverters.add(new DocumentToMutableMessageConverter());
|
||||
customConverters.add(new DocumentToErrorMessageConverter());
|
||||
DocumentToErrorMessageConverter docToErrorMessageConverter = new DocumentToErrorMessageConverter();
|
||||
if (MongoDbMessageStore.this.whiteListPatterns != null) {
|
||||
docToErrorMessageConverter.deserializingConverter
|
||||
.addWhiteListPatterns(MongoDbMessageStore.this.whiteListPatterns);
|
||||
}
|
||||
customConverters.add(docToErrorMessageConverter);
|
||||
customConverters.add(new DocumentToAdviceMessageConverter());
|
||||
customConverters.add(new ThrowableToBytesConverter());
|
||||
this.setCustomConversions(new MongoCustomConversions(customConverters));
|
||||
@@ -730,7 +747,7 @@ public class MongoDbMessageStore extends AbstractMessageGroupStore
|
||||
@ReadingConverter
|
||||
private class DocumentToErrorMessageConverter implements Converter<Document, ErrorMessage> {
|
||||
|
||||
private final Converter<byte[], Object> deserializingConverter = new DeserializingConverter();
|
||||
private final WhiteListDeserializingConverter deserializingConverter = new WhiteListDeserializingConverter();
|
||||
|
||||
DocumentToErrorMessageConverter() {
|
||||
super();
|
||||
|
||||
@@ -19,22 +19,33 @@ package org.springframework.integration.mongodb.support;
|
||||
import org.bson.types.Binary;
|
||||
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.core.serializer.support.DeserializingConverter;
|
||||
import org.springframework.data.convert.ReadingConverter;
|
||||
import org.springframework.integration.support.converter.WhiteListDeserializingConverter;
|
||||
import org.springframework.messaging.Message;
|
||||
|
||||
/**
|
||||
* @author Artem Bilan
|
||||
* @author Gary Russell
|
||||
* @since 5.0
|
||||
*/
|
||||
@ReadingConverter
|
||||
public class BinaryToMessageConverter implements Converter<Binary, Message<?>> {
|
||||
|
||||
private final Converter<byte[], Object> deserializingConverter = new DeserializingConverter();
|
||||
private final WhiteListDeserializingConverter deserializingConverter = new WhiteListDeserializingConverter();
|
||||
|
||||
@Override
|
||||
public Message<?> convert(Binary source) {
|
||||
return (Message<?>) this.deserializingConverter.convert(source.getData());
|
||||
}
|
||||
|
||||
/**
|
||||
* Add patterns for packages/classes that are allowed to be deserialized. A class can
|
||||
* be fully qualified or a wildcard '*' is allowed at the beginning or end of the
|
||||
* class name. Examples: {@code com.foo.*}, {@code *.MyClass}.
|
||||
* @param patterns the patterns.
|
||||
*/
|
||||
public void addWhiteListPatterns(String... patterns) {
|
||||
this.deserializingConverter.addWhiteListPatterns(patterns);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,10 +24,10 @@ import org.bson.types.Binary;
|
||||
import org.springframework.core.convert.TypeDescriptor;
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.core.convert.converter.GenericConverter;
|
||||
import org.springframework.core.serializer.support.DeserializingConverter;
|
||||
import org.springframework.core.serializer.support.SerializingConverter;
|
||||
import org.springframework.data.convert.ReadingConverter;
|
||||
import org.springframework.data.convert.WritingConverter;
|
||||
import org.springframework.integration.support.converter.WhiteListDeserializingConverter;
|
||||
import org.springframework.messaging.Message;
|
||||
|
||||
/**
|
||||
@@ -36,6 +36,7 @@ import org.springframework.messaging.Message;
|
||||
* And vice versa - to convert {@link byte[]} from the MongoDB to the {@link Message}.
|
||||
|
||||
* @author Artem Bilan
|
||||
* @author Gary Russell
|
||||
* @since 4.2.10
|
||||
* @deprecated since 5.0 in favor of {@link MessageToBinaryConverter} and {@link BinaryToMessageConverter}
|
||||
*/
|
||||
@@ -46,7 +47,7 @@ public class MongoDbMessageBytesConverter implements GenericConverter {
|
||||
|
||||
private final Converter<Object, byte[]> serializingConverter = new SerializingConverter();
|
||||
|
||||
private final Converter<byte[], Object> deserializingConverter = new DeserializingConverter();
|
||||
private final WhiteListDeserializingConverter deserializingConverter = new WhiteListDeserializingConverter();
|
||||
|
||||
@Override
|
||||
public Set<ConvertiblePair> getConvertibleTypes() {
|
||||
@@ -66,4 +67,14 @@ public class MongoDbMessageBytesConverter implements GenericConverter {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add patterns for packages/classes that are allowed to be deserialized. A class can
|
||||
* be fully qualified or a wildcard '*' is allowed at the beginning or end of the
|
||||
* class name. Examples: {@code com.foo.*}, {@code *.MyClass}.
|
||||
* @param patterns the patterns.
|
||||
*/
|
||||
public void addWhiteListPatterns(String... patterns) {
|
||||
this.deserializingConverter.addWhiteListPatterns(patterns);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user