From 8543a3ca912e48e553690dded72dcd14c7f4d5ef Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Fri, 21 Aug 2015 09:49:59 +0200 Subject: [PATCH] Improve use of SSL config in RabbitConnectionFactory Previously we had to create a fake Properties object as the factory did not provide individual setters for the SSL configuration. This has been added as part of Spring AMQP 1.5.0.RC1 so we're using those instead. Closes gh-3754 --- .../amqp/RabbitAutoConfiguration.java | 15 ++++-------- .../autoconfigure/amqp/RabbitProperties.java | 24 ------------------- 2 files changed, 4 insertions(+), 35 deletions(-) diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoConfiguration.java index 6fc51731e07..1ba8aaf1a93 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoConfiguration.java @@ -16,9 +16,6 @@ package org.springframework.boot.autoconfigure.amqp; -import java.io.ByteArrayOutputStream; -import java.util.Properties; - import org.springframework.amqp.core.AmqpAdmin; import org.springframework.amqp.rabbit.connection.CachingConnectionFactory; import org.springframework.amqp.rabbit.connection.ConnectionFactory; @@ -35,7 +32,6 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; -import org.springframework.core.io.ByteArrayResource; import com.rabbitmq.client.Channel; @@ -128,13 +124,10 @@ public class RabbitAutoConfiguration { RabbitProperties.Ssl ssl = config.getSsl(); if (ssl.isEnabled()) { factory.setUseSSL(true); - if (ssl.getKeyStore() != null || ssl.getTrustStore() != null) { - Properties properties = ssl.createSslProperties(); - ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - properties.store(outputStream, "SSL config"); - factory.setSslPropertiesLocation(new ByteArrayResource(outputStream - .toByteArray())); - } + factory.setKeyStore(ssl.getKeyStore()); + factory.setKeyStorePassphrase(ssl.getKeyStorePassword()); + factory.setTrustStore(ssl.getTrustStore()); + factory.setTrustStorePassphrase(ssl.getTrustStorePassword()); } factory.afterPropertiesSet(); CachingConnectionFactory connectionFactory = new CachingConnectionFactory( diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitProperties.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitProperties.java index 06b8d587085..170ee294491 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitProperties.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitProperties.java @@ -17,7 +17,6 @@ package org.springframework.boot.autoconfigure.amqp; import java.util.LinkedHashSet; -import java.util.Properties; import java.util.Set; import org.springframework.amqp.core.AcknowledgeMode; @@ -258,29 +257,6 @@ public class RabbitProperties { this.trustStorePassword = trustStorePassword; } - /** - * Create the ssl configuration as expected by the - * {@link org.springframework.amqp.rabbit.connection.RabbitConnectionFactoryBean - * RabbitConnectionFactoryBean}. - * @return the ssl configuration - */ - public Properties createSslProperties() { - Properties properties = new Properties(); - if (getKeyStore() != null) { - properties.put("keyStore", getKeyStore()); - } - if (getKeyStorePassword() != null) { - properties.put("keyStore.passPhrase", getKeyStorePassword()); - } - if (getTrustStore() != null) { - properties.put("trustStore", getTrustStore()); - } - if (getTrustStorePassword() != null) { - properties.put("trustStore.passPhrase", getTrustStorePassword()); - } - return properties; - } - } public static class Listener {