Skip to content

Commit 8543a3c

Browse files
committed
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 spring-projectsgh-3754
1 parent 9303efd commit 8543a3c

File tree

2 files changed

+4
-35
lines changed

2 files changed

+4
-35
lines changed

spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitAutoConfiguration.java

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@
1616

1717
package org.springframework.boot.autoconfigure.amqp;
1818

19-
import java.io.ByteArrayOutputStream;
20-
import java.util.Properties;
21-
2219
import org.springframework.amqp.core.AmqpAdmin;
2320
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
2421
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
@@ -35,7 +32,6 @@
3532
import org.springframework.context.annotation.Bean;
3633
import org.springframework.context.annotation.Configuration;
3734
import org.springframework.context.annotation.Import;
38-
import org.springframework.core.io.ByteArrayResource;
3935

4036
import com.rabbitmq.client.Channel;
4137

@@ -128,13 +124,10 @@ public CachingConnectionFactory rabbitConnectionFactory(RabbitProperties config)
128124
RabbitProperties.Ssl ssl = config.getSsl();
129125
if (ssl.isEnabled()) {
130126
factory.setUseSSL(true);
131-
if (ssl.getKeyStore() != null || ssl.getTrustStore() != null) {
132-
Properties properties = ssl.createSslProperties();
133-
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
134-
properties.store(outputStream, "SSL config");
135-
factory.setSslPropertiesLocation(new ByteArrayResource(outputStream
136-
.toByteArray()));
137-
}
127+
factory.setKeyStore(ssl.getKeyStore());
128+
factory.setKeyStorePassphrase(ssl.getKeyStorePassword());
129+
factory.setTrustStore(ssl.getTrustStore());
130+
factory.setTrustStorePassphrase(ssl.getTrustStorePassword());
138131
}
139132
factory.afterPropertiesSet();
140133
CachingConnectionFactory connectionFactory = new CachingConnectionFactory(

spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/amqp/RabbitProperties.java

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package org.springframework.boot.autoconfigure.amqp;
1818

1919
import java.util.LinkedHashSet;
20-
import java.util.Properties;
2120
import java.util.Set;
2221

2322
import org.springframework.amqp.core.AcknowledgeMode;
@@ -258,29 +257,6 @@ public void setTrustStorePassword(String trustStorePassword) {
258257
this.trustStorePassword = trustStorePassword;
259258
}
260259

261-
/**
262-
* Create the ssl configuration as expected by the
263-
* {@link org.springframework.amqp.rabbit.connection.RabbitConnectionFactoryBean
264-
* RabbitConnectionFactoryBean}.
265-
* @return the ssl configuration
266-
*/
267-
public Properties createSslProperties() {
268-
Properties properties = new Properties();
269-
if (getKeyStore() != null) {
270-
properties.put("keyStore", getKeyStore());
271-
}
272-
if (getKeyStorePassword() != null) {
273-
properties.put("keyStore.passPhrase", getKeyStorePassword());
274-
}
275-
if (getTrustStore() != null) {
276-
properties.put("trustStore", getTrustStore());
277-
}
278-
if (getTrustStorePassword() != null) {
279-
properties.put("trustStore.passPhrase", getTrustStorePassword());
280-
}
281-
return properties;
282-
}
283-
284260
}
285261

286262
public static class Listener {

0 commit comments

Comments
 (0)