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
This commit is contained in:
parent
9303efd435
commit
8543a3ca91
|
@ -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(
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue