AMQP-500: Configurable SSL Algo, No Properties

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

Enable algorithm selection when not using certificates.
This commit is contained in:
Gary Russell
2015-05-29 14:20:49 -04:00
parent b0af7984b6
commit 059057eb1d
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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -72,6 +72,8 @@ public class RabbitConnectionFactoryBean extends AbstractFactoryBean<ConnectionF
private volatile String sslAlgorithm = TLS_V1_1; private volatile String sslAlgorithm = TLS_V1_1;
private volatile boolean sslAlgorithmSet;
/** /**
* Whether or not the factory should be configured to use SSL. * Whether or not the factory should be configured to use SSL.
* @param useSSL true to use SSL. * @param useSSL true to use SSL.
@@ -94,6 +96,7 @@ public class RabbitConnectionFactoryBean extends AbstractFactoryBean<ConnectionF
*/ */
public void setSslAlgorithm(String sslAlgorithm) { public void setSslAlgorithm(String sslAlgorithm) {
this.sslAlgorithm = sslAlgorithm; this.sslAlgorithm = sslAlgorithm;
this.sslAlgorithmSet = true;
} }
/** /**
@@ -297,7 +300,12 @@ public class RabbitConnectionFactoryBean extends AbstractFactoryBean<ConnectionF
*/ */
protected void setUpSSL() throws Exception { protected void setUpSSL() throws Exception {
if (this.sslPropertiesLocation == null) { if (this.sslPropertiesLocation == null) {
this.connectionFactory.useSslProtocol(); if (this.sslAlgorithmSet) {
this.connectionFactory.useSslProtocol(this.sslAlgorithm);
}
else {
this.connectionFactory.useSslProtocol();
}
} }
else { else {
Properties sslProperties = new Properties(); 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -15,9 +15,14 @@
*/ */
package org.springframework.amqp.rabbit.connection; 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.Ignore;
import org.junit.Test; import org.junit.Test;
import org.springframework.amqp.utils.test.TestUtils;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.ClassPathResource;
import com.rabbitmq.client.Channel; import com.rabbitmq.client.Channel;
@@ -44,4 +49,27 @@ public class SSLConnectionTests {
conn.close(); 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();
}
} }