Commit 0c0be1e6 authored by Phillip Webb's avatar Phillip Webb

Polish contribution

parent d0ccea1b
...@@ -61,17 +61,21 @@ class ActiveMQConnectionFactoryFactory { ...@@ -61,17 +61,21 @@ class ActiveMQConnectionFactoryFactory {
String password = this.properties.getPassword(); String password = this.properties.getPassword();
T activeMqConnectionFactory; T activeMqConnectionFactory;
if (StringUtils.hasLength(user) && StringUtils.hasLength(password)) { if (StringUtils.hasLength(user) && StringUtils.hasLength(password)) {
activeMqConnectionFactory = activeMqConnectionFactory = factoryClass
factoryClass.getConstructor(String.class, String.class, String.class) .getConstructor(String.class, String.class, String.class)
.newInstance(user, password, brokerUrl); .newInstance(user, password, brokerUrl);
} }
else { else {
activeMqConnectionFactory = activeMqConnectionFactory = factoryClass.getConstructor(String.class)
factoryClass.getConstructor(String.class).newInstance(brokerUrl); .newInstance(brokerUrl);
} }
Packages packages = this.properties.getPackages(); Packages packages = this.properties.getPackages();
activeMqConnectionFactory.setTrustAllPackages(packages.isTrustAll()); if (packages.getTrustAll() != null) {
activeMqConnectionFactory.setTrustedPackages(packages.getTrusted()); activeMqConnectionFactory.setTrustAllPackages(packages.getTrustAll());
}
if (!packages.getTrusted().isEmpty()) {
activeMqConnectionFactory.setTrustedPackages(packages.getTrusted());
}
return activeMqConnectionFactory; return activeMqConnectionFactory;
} }
......
...@@ -123,10 +123,6 @@ public class ActiveMQProperties { ...@@ -123,10 +123,6 @@ public class ActiveMQProperties {
return this.packages; return this.packages;
} }
public void setPackages(Packages packages) {
this.packages = packages;
}
public static class Pool { public static class Pool {
/** /**
...@@ -186,17 +182,21 @@ public class ActiveMQProperties { ...@@ -186,17 +182,21 @@ public class ActiveMQProperties {
public static class Packages { public static class Packages {
/** Whether security check for trusted packages should be turned off. */ /**
private boolean trustAll = false; * Trust all packages.
*/
private Boolean trustAll;
/** The packages to trust. */ /**
* The specific packages to trust (when not trusting all packages).
*/
private List<String> trusted = new ArrayList<String>(); private List<String> trusted = new ArrayList<String>();
public boolean isTrustAll() { public Boolean getTrustAll() {
return this.trustAll; return this.trustAll;
} }
public void setTrustAll(boolean trustAll) { public void setTrustAll(Boolean trustAll) {
this.trustAll = trustAll; this.trustAll = trustAll;
} }
......
...@@ -17,12 +17,10 @@ ...@@ -17,12 +17,10 @@
package org.springframework.boot.autoconfigure.jms.activemq; package org.springframework.boot.autoconfigure.jms.activemq;
import org.apache.activemq.ActiveMQConnectionFactory; import org.apache.activemq.ActiveMQConnectionFactory;
import org.junit.Test; import org.junit.Test;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
/** /**
* Tests for {@link ActiveMQProperties} and {@link ActiveMQConnectionFactoryFactory}. * Tests for {@link ActiveMQProperties} and {@link ActiveMQConnectionFactoryFactory}.
* *
...@@ -67,7 +65,7 @@ public class ActiveMQPropertiesTests { ...@@ -67,7 +65,7 @@ public class ActiveMQPropertiesTests {
} }
@Test @Test
public void testPackagesTrustAllSetToTrue() { public void setTrustAllPackages() {
this.properties.getPackages().setTrustAll(true); this.properties.getPackages().setTrustAll(true);
assertThat(new ActiveMQConnectionFactoryFactory(this.properties) assertThat(new ActiveMQConnectionFactoryFactory(this.properties)
.createConnectionFactory(ActiveMQConnectionFactory.class) .createConnectionFactory(ActiveMQConnectionFactory.class)
...@@ -75,12 +73,11 @@ public class ActiveMQPropertiesTests { ...@@ -75,12 +73,11 @@ public class ActiveMQPropertiesTests {
} }
@Test @Test
public void testPackagesToTrust() { public void setTrustedPackages() {
this.properties.getPackages().setTrustAll(false); this.properties.getPackages().setTrustAll(false);
this.properties.getPackages().getTrusted().add("trusted.package"); this.properties.getPackages().getTrusted().add("trusted.package");
ActiveMQConnectionFactory factory = ActiveMQConnectionFactory factory = new ActiveMQConnectionFactoryFactory(
new ActiveMQConnectionFactoryFactory(this.properties) this.properties).createConnectionFactory(ActiveMQConnectionFactory.class);
.createConnectionFactory(ActiveMQConnectionFactory.class);
assertThat(factory.isTrustAllPackages()).isEqualTo(false); assertThat(factory.isTrustAllPackages()).isEqualTo(false);
assertThat(factory.getTrustedPackages().size()).isEqualTo(1); assertThat(factory.getTrustedPackages().size()).isEqualTo(1);
assertThat(factory.getTrustedPackages().get(0)).isEqualTo("trusted.package"); assertThat(factory.getTrustedPackages().get(0)).isEqualTo("trusted.package");
......
...@@ -770,6 +770,8 @@ content into your application; rather pick only the properties that you need. ...@@ -770,6 +770,8 @@ content into your application; rather pick only the properties that you need.
spring.activemq.pool.expiry-timeout=0 # Connection expiration timeout in milliseconds. spring.activemq.pool.expiry-timeout=0 # Connection expiration timeout in milliseconds.
spring.activemq.pool.idle-timeout=30000 # Connection idle timeout in milliseconds. spring.activemq.pool.idle-timeout=30000 # Connection idle timeout in milliseconds.
spring.activemq.pool.max-connections=1 # Maximum number of pooled connections. spring.activemq.pool.max-connections=1 # Maximum number of pooled connections.
spring.activemq.packages.trust-all= # Trust all packages
spring.activemq.packages.trusted= # The specific packages to trust (when not trusting all packages).
# ARTEMIS ({sc-spring-boot-autoconfigure}/jms/artemis/ArtemisProperties.{sc-ext}[ArtemisProperties]) # ARTEMIS ({sc-spring-boot-autoconfigure}/jms/artemis/ArtemisProperties.{sc-ext}[ArtemisProperties])
spring.artemis.embedded.cluster-password= # Cluster password. Randomly generated on startup by default. spring.artemis.embedded.cluster-password= # Cluster password. Randomly generated on startup by default.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment