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
pull/3807/head
Stephane Nicoll 9 years ago
parent 9303efd435
commit 8543a3ca91

@ -16,9 +16,6 @@
package org.springframework.boot.autoconfigure.amqp; package org.springframework.boot.autoconfigure.amqp;
import java.io.ByteArrayOutputStream;
import java.util.Properties;
import org.springframework.amqp.core.AmqpAdmin; import org.springframework.amqp.core.AmqpAdmin;
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory; import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
import org.springframework.amqp.rabbit.connection.ConnectionFactory; 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.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import; import org.springframework.context.annotation.Import;
import org.springframework.core.io.ByteArrayResource;
import com.rabbitmq.client.Channel; import com.rabbitmq.client.Channel;
@ -128,13 +124,10 @@ public class RabbitAutoConfiguration {
RabbitProperties.Ssl ssl = config.getSsl(); RabbitProperties.Ssl ssl = config.getSsl();
if (ssl.isEnabled()) { if (ssl.isEnabled()) {
factory.setUseSSL(true); factory.setUseSSL(true);
if (ssl.getKeyStore() != null || ssl.getTrustStore() != null) { factory.setKeyStore(ssl.getKeyStore());
Properties properties = ssl.createSslProperties(); factory.setKeyStorePassphrase(ssl.getKeyStorePassword());
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); factory.setTrustStore(ssl.getTrustStore());
properties.store(outputStream, "SSL config"); factory.setTrustStorePassphrase(ssl.getTrustStorePassword());
factory.setSslPropertiesLocation(new ByteArrayResource(outputStream
.toByteArray()));
}
} }
factory.afterPropertiesSet(); factory.afterPropertiesSet();
CachingConnectionFactory connectionFactory = new CachingConnectionFactory( CachingConnectionFactory connectionFactory = new CachingConnectionFactory(

@ -17,7 +17,6 @@
package org.springframework.boot.autoconfigure.amqp; package org.springframework.boot.autoconfigure.amqp;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.Properties;
import java.util.Set; import java.util.Set;
import org.springframework.amqp.core.AcknowledgeMode; import org.springframework.amqp.core.AcknowledgeMode;
@ -258,29 +257,6 @@ public class RabbitProperties {
this.trustStorePassword = trustStorePassword; 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 { public static class Listener {

Loading…
Cancel
Save