From 0c0be1e6266d4b4b7510341fafcb5206ec090532 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Sun, 10 Apr 2016 07:33:56 -0700 Subject: [PATCH] Polish contribution --- .../ActiveMQConnectionFactoryFactory.java | 16 ++++++++++------ .../jms/activemq/ActiveMQProperties.java | 18 +++++++++--------- .../jms/activemq/ActiveMQPropertiesTests.java | 11 ++++------- .../appendix-application-properties.adoc | 2 ++ 4 files changed, 25 insertions(+), 22 deletions(-) diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQConnectionFactoryFactory.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQConnectionFactoryFactory.java index 43da9f4e06..4a29b1a661 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQConnectionFactoryFactory.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQConnectionFactoryFactory.java @@ -61,17 +61,21 @@ class ActiveMQConnectionFactoryFactory { String password = this.properties.getPassword(); T activeMqConnectionFactory; if (StringUtils.hasLength(user) && StringUtils.hasLength(password)) { - activeMqConnectionFactory = - factoryClass.getConstructor(String.class, String.class, String.class) + activeMqConnectionFactory = factoryClass + .getConstructor(String.class, String.class, String.class) .newInstance(user, password, brokerUrl); } else { - activeMqConnectionFactory = - factoryClass.getConstructor(String.class).newInstance(brokerUrl); + activeMqConnectionFactory = factoryClass.getConstructor(String.class) + .newInstance(brokerUrl); } Packages packages = this.properties.getPackages(); - activeMqConnectionFactory.setTrustAllPackages(packages.isTrustAll()); - activeMqConnectionFactory.setTrustedPackages(packages.getTrusted()); + if (packages.getTrustAll() != null) { + activeMqConnectionFactory.setTrustAllPackages(packages.getTrustAll()); + } + if (!packages.getTrusted().isEmpty()) { + activeMqConnectionFactory.setTrustedPackages(packages.getTrusted()); + } return activeMqConnectionFactory; } diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQProperties.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQProperties.java index a56f5ad0ad..bd448c831a 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQProperties.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQProperties.java @@ -123,10 +123,6 @@ public class ActiveMQProperties { return this.packages; } - public void setPackages(Packages packages) { - this.packages = packages; - } - public static class Pool { /** @@ -186,17 +182,21 @@ public class ActiveMQProperties { 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 trusted = new ArrayList(); - public boolean isTrustAll() { + public Boolean getTrustAll() { return this.trustAll; } - public void setTrustAll(boolean trustAll) { + public void setTrustAll(Boolean trustAll) { this.trustAll = trustAll; } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQPropertiesTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQPropertiesTests.java index fa5553e6fc..00f9071da0 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQPropertiesTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jms/activemq/ActiveMQPropertiesTests.java @@ -17,12 +17,10 @@ package org.springframework.boot.autoconfigure.jms.activemq; import org.apache.activemq.ActiveMQConnectionFactory; - import org.junit.Test; import static org.assertj.core.api.Assertions.assertThat; - /** * Tests for {@link ActiveMQProperties} and {@link ActiveMQConnectionFactoryFactory}. * @@ -67,7 +65,7 @@ public class ActiveMQPropertiesTests { } @Test - public void testPackagesTrustAllSetToTrue() { + public void setTrustAllPackages() { this.properties.getPackages().setTrustAll(true); assertThat(new ActiveMQConnectionFactoryFactory(this.properties) .createConnectionFactory(ActiveMQConnectionFactory.class) @@ -75,12 +73,11 @@ public class ActiveMQPropertiesTests { } @Test - public void testPackagesToTrust() { + public void setTrustedPackages() { this.properties.getPackages().setTrustAll(false); this.properties.getPackages().getTrusted().add("trusted.package"); - ActiveMQConnectionFactory factory = - new ActiveMQConnectionFactoryFactory(this.properties) - .createConnectionFactory(ActiveMQConnectionFactory.class); + ActiveMQConnectionFactory factory = new ActiveMQConnectionFactoryFactory( + this.properties).createConnectionFactory(ActiveMQConnectionFactory.class); assertThat(factory.isTrustAllPackages()).isEqualTo(false); assertThat(factory.getTrustedPackages().size()).isEqualTo(1); assertThat(factory.getTrustedPackages().get(0)).isEqualTo("trusted.package"); diff --git a/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc b/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc index 3870314349..124f9711b9 100644 --- a/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc +++ b/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc @@ -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.idle-timeout=30000 # Connection idle timeout in milliseconds. 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]) spring.artemis.embedded.cluster-password= # Cluster password. Randomly generated on startup by default.