AMQP-500: Configurable SSL Algo, No Properties

JIRA: https://jira.spring.io/browse/AMQP-500

Enable algorithm selection when not using certificates.
(cherry picked from commit 059057e)
This commit is contained in:
Gary Russell
2015-05-29 20:20:49 -04:00
committed by Artem Bilan
parent 436ffcd758
commit 75187b8df5
2 changed files with 39 additions and 3 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014 the original author or authors.
* Copyright 2014-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -70,6 +70,8 @@ public class RabbitConnectionFactoryBean extends AbstractFactoryBean<ConnectionF
private volatile String sslAlgorithm = "SSLv3";
private volatile boolean sslAlgorithmSet;
/**
* Whether or not the factory should be configured to use SSL.
* @param useSSL true to use SSL.
@@ -92,6 +94,7 @@ public class RabbitConnectionFactoryBean extends AbstractFactoryBean<ConnectionF
*/
public void setSslAlgorithm(String sslAlgorithm) {
this.sslAlgorithm = sslAlgorithm;
this.sslAlgorithmSet = true;
}
/**
@@ -295,7 +298,12 @@ public class RabbitConnectionFactoryBean extends AbstractFactoryBean<ConnectionF
*/
protected void setUpSSL() throws Exception {
if (this.sslPropertiesLocation == null) {
this.connectionFactory.useSslProtocol();
if (this.sslAlgorithmSet) {
this.connectionFactory.useSslProtocol(this.sslAlgorithm);
}
else {
this.connectionFactory.useSslProtocol();
}
}
else {
Properties sslProperties = new Properties();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014 the original author or authors.
* Copyright 2014-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,9 +15,14 @@
*/
package org.springframework.amqp.rabbit.connection;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import org.junit.Ignore;
import org.junit.Test;
import org.springframework.amqp.utils.test.TestUtils;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.core.io.ClassPathResource;
import com.rabbitmq.client.Channel;
@@ -44,4 +49,27 @@ public class SSLConnectionTests {
conn.close();
}
@Test
public void testAlgNoProps() throws Exception {
RabbitConnectionFactoryBean fb = new RabbitConnectionFactoryBean();
ConnectionFactory rabbitCf = spy(TestUtils.getPropertyValue(fb, "connectionFactory", ConnectionFactory.class));
new DirectFieldAccessor(fb).setPropertyValue("connectionFactory", rabbitCf);
fb.setUseSSL(true);
fb.setSslAlgorithm("TLSv1.2");
fb.afterPropertiesSet();
fb.getObject();
verify(rabbitCf).useSslProtocol("TLSv1.2");
}
@Test
public void testNoAlgNoProps() throws Exception {
RabbitConnectionFactoryBean fb = new RabbitConnectionFactoryBean();
ConnectionFactory rabbitCf = spy(TestUtils.getPropertyValue(fb, "connectionFactory", ConnectionFactory.class));
new DirectFieldAccessor(fb).setPropertyValue("connectionFactory", rabbitCf);
fb.setUseSSL(true);
fb.afterPropertiesSet();
fb.getObject();
verify(rabbitCf).useSslProtocol();
}
}