Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
* @author Rafael Carvalho
* @author Scott Frederick
* @author Lasse Wulff
* @author Yanming Zhou
* @since 1.0.0
*/
@ConfigurationProperties(prefix = "spring.rabbitmq")
Expand Down Expand Up @@ -1015,6 +1016,11 @@ public static class Template {
*/
private boolean observationEnabled;

/**
* Simple patterns for allowable packages/classes for deserialization.
*/
private List<String> allowedListPatterns;

public Retry getRetry() {
return this.retry;
}
Expand Down Expand Up @@ -1075,6 +1081,14 @@ public void setObservationEnabled(boolean observationEnabled) {
this.observationEnabled = observationEnabled;
}

public List<String> getAllowedListPatterns() {
return this.allowedListPatterns;
}

public void setAllowedListPatterns(List<String> allowedListPatterns) {
this.allowedListPatterns = allowedListPatterns;
}

}

public static class Retry {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.support.converter.AllowedListDeserializingMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.boot.context.properties.PropertyMapper;
import org.springframework.util.Assert;
Expand All @@ -29,6 +30,7 @@
* Configure {@link RabbitTemplate} with sensible defaults.
*
* @author Stephane Nicoll
* @author Yanming Zhou
* @since 2.3.0
*/
public class RabbitTemplateConfigurer {
Expand Down Expand Up @@ -102,6 +104,12 @@ public void configure(RabbitTemplate template, ConnectionFactory connectionFacto
map.from(templateProperties::getRoutingKey).to(template::setRoutingKey);
map.from(templateProperties::getDefaultReceiveQueue).whenNonNull().to(template::setDefaultReceiveQueue);
map.from(templateProperties::isObservationEnabled).to(template::setObservationEnabled);
if (templateProperties.getAllowedListPatterns() != null) {
MessageConverter messageConverter = template.getMessageConverter();
if (messageConverter instanceof AllowedListDeserializingMessageConverter mc) {
mc.setAllowedListPatterns(templateProperties.getAllowedListPatterns());
}
}
}

private boolean determineMandatoryFlag() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.springframework.boot.autoconfigure.amqp;

import java.security.NoSuchAlgorithmException;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;
Expand All @@ -35,6 +36,8 @@
import org.junit.jupiter.api.condition.EnabledForJreRange;
import org.junit.jupiter.api.condition.JRE;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.mockito.InOrder;

import org.springframework.amqp.core.AcknowledgeMode;
Expand All @@ -59,7 +62,9 @@
import org.springframework.amqp.rabbit.listener.RabbitListenerContainerFactory;
import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer;
import org.springframework.amqp.rabbit.retry.MessageRecoverer;
import org.springframework.amqp.support.converter.AllowedListDeserializingMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.amqp.support.converter.SerializerMessageConverter;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.autoconfigure.ssl.SslAutoConfiguration;
Expand Down Expand Up @@ -107,6 +112,7 @@
* @author Andy Wilkinson
* @author Phillip Webb
* @author Scott Frederick
* @author Yanming Zhou
*/
@ExtendWith(OutputCaptureExtension.class)
class RabbitAutoConfigurationTests {
Expand Down Expand Up @@ -796,6 +802,20 @@ void customizeRequestedChannelMax() {
});
}

@SuppressWarnings("unchecked")
@ParameterizedTest
@ValueSource(classes = { TestConfiguration.class, TestConfiguration6.class })
void customizeAllowedListPatterns(Class<?> configuration) {
this.contextRunner.withUserConfiguration(configuration)
.withPropertyValues("spring.rabbitmq.template.allowed-list-patterns:*")
.run((context) -> {
MessageConverter messageConverter = context.getBean(RabbitTemplate.class).getMessageConverter();
assertThat(messageConverter).isInstanceOfSatisfying(AllowedListDeserializingMessageConverter.class,
(mc) -> assertThat(mc).extracting("allowedListPatterns")
.isInstanceOfSatisfying(Collection.class, (set) -> assertThat(set).contains("*")));
});
}

@Test
void noSslByDefault() {
this.contextRunner.withUserConfiguration(TestConfiguration.class).run((context) -> {
Expand Down Expand Up @@ -1113,6 +1133,16 @@ RabbitListenerContainerFactory<?> rabbitListenerContainerFactory() {

}

@Configuration(proxyBeanMethods = false)
static class TestConfiguration6 {

@Bean
MessageConverter messageConverter() {
return new SerializerMessageConverter();
}

}

@Configuration(proxyBeanMethods = false)
static class MessageConvertersConfiguration {

Expand Down