Merge pull request #5644 from venilnoronha/issue-5631-fix
* issue-5631-fix: Polish contribution Support ActiveMQ trusted packages
This commit is contained in:
commit
e992d389e7
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2012-2014 the original author or authors.
|
* Copyright 2012-2016 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.
|
||||||
|
|
@ -18,6 +18,7 @@ package org.springframework.boot.autoconfigure.jms.activemq;
|
||||||
|
|
||||||
import org.apache.activemq.ActiveMQConnectionFactory;
|
import org.apache.activemq.ActiveMQConnectionFactory;
|
||||||
|
|
||||||
|
import org.springframework.boot.autoconfigure.jms.activemq.ActiveMQProperties.Packages;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
|
|
@ -26,6 +27,7 @@ import org.springframework.util.StringUtils;
|
||||||
* in {@link ActiveMQProperties}.
|
* in {@link ActiveMQProperties}.
|
||||||
*
|
*
|
||||||
* @author Phillip Webb
|
* @author Phillip Webb
|
||||||
|
* @author Venil Noronha
|
||||||
* @since 1.2.0
|
* @since 1.2.0
|
||||||
*/
|
*/
|
||||||
class ActiveMQConnectionFactoryFactory {
|
class ActiveMQConnectionFactoryFactory {
|
||||||
|
|
@ -57,11 +59,24 @@ class ActiveMQConnectionFactoryFactory {
|
||||||
String brokerUrl = determineBrokerUrl();
|
String brokerUrl = determineBrokerUrl();
|
||||||
String user = this.properties.getUser();
|
String user = this.properties.getUser();
|
||||||
String password = this.properties.getPassword();
|
String password = this.properties.getPassword();
|
||||||
|
T activeMqConnectionFactory;
|
||||||
if (StringUtils.hasLength(user) && StringUtils.hasLength(password)) {
|
if (StringUtils.hasLength(user) && StringUtils.hasLength(password)) {
|
||||||
return factoryClass.getConstructor(String.class, String.class, String.class)
|
activeMqConnectionFactory = factoryClass
|
||||||
|
.getConstructor(String.class, String.class, String.class)
|
||||||
.newInstance(user, password, brokerUrl);
|
.newInstance(user, password, brokerUrl);
|
||||||
}
|
}
|
||||||
return factoryClass.getConstructor(String.class).newInstance(brokerUrl);
|
else {
|
||||||
|
activeMqConnectionFactory = factoryClass.getConstructor(String.class)
|
||||||
|
.newInstance(brokerUrl);
|
||||||
|
}
|
||||||
|
Packages packages = this.properties.getPackages();
|
||||||
|
if (packages.getTrustAll() != null) {
|
||||||
|
activeMqConnectionFactory.setTrustAllPackages(packages.getTrustAll());
|
||||||
|
}
|
||||||
|
if (!packages.getTrusted().isEmpty()) {
|
||||||
|
activeMqConnectionFactory.setTrustedPackages(packages.getTrusted());
|
||||||
|
}
|
||||||
|
return activeMqConnectionFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
String determineBrokerUrl() {
|
String determineBrokerUrl() {
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,9 @@
|
||||||
|
|
||||||
package org.springframework.boot.autoconfigure.jms.activemq;
|
package org.springframework.boot.autoconfigure.jms.activemq;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
import org.springframework.boot.context.properties.DeprecatedConfigurationProperty;
|
import org.springframework.boot.context.properties.DeprecatedConfigurationProperty;
|
||||||
|
|
||||||
|
|
@ -25,6 +28,7 @@ import org.springframework.boot.context.properties.DeprecatedConfigurationProper
|
||||||
* @author Greg Turnquist
|
* @author Greg Turnquist
|
||||||
* @author Stephane Nicoll
|
* @author Stephane Nicoll
|
||||||
* @author Aurélien Leboulanger
|
* @author Aurélien Leboulanger
|
||||||
|
* @author Venil Noronha
|
||||||
*/
|
*/
|
||||||
@ConfigurationProperties(prefix = "spring.activemq")
|
@ConfigurationProperties(prefix = "spring.activemq")
|
||||||
public class ActiveMQProperties {
|
public class ActiveMQProperties {
|
||||||
|
|
@ -52,6 +56,8 @@ public class ActiveMQProperties {
|
||||||
|
|
||||||
private Pool pool = new Pool();
|
private Pool pool = new Pool();
|
||||||
|
|
||||||
|
private Packages packages = new Packages();
|
||||||
|
|
||||||
public String getBrokerUrl() {
|
public String getBrokerUrl() {
|
||||||
return this.brokerUrl;
|
return this.brokerUrl;
|
||||||
}
|
}
|
||||||
|
|
@ -113,6 +119,10 @@ public class ActiveMQProperties {
|
||||||
this.pool = pool;
|
this.pool = pool;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Packages getPackages() {
|
||||||
|
return this.packages;
|
||||||
|
}
|
||||||
|
|
||||||
public static class Pool {
|
public static class Pool {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -170,4 +180,34 @@ public class ActiveMQProperties {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class Packages {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Trust all packages.
|
||||||
|
*/
|
||||||
|
private Boolean trustAll;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The specific packages to trust (when not trusting all packages).
|
||||||
|
*/
|
||||||
|
private List<String> trusted = new ArrayList<String>();
|
||||||
|
|
||||||
|
public Boolean getTrustAll() {
|
||||||
|
return this.trustAll;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTrustAll(Boolean trustAll) {
|
||||||
|
this.trustAll = trustAll;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getTrusted() {
|
||||||
|
return this.trusted;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTrusted(List<String> trusted) {
|
||||||
|
this.trusted = trusted;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
package org.springframework.boot.autoconfigure.jms.activemq;
|
package org.springframework.boot.autoconfigure.jms.activemq;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
@ -25,6 +26,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
*
|
*
|
||||||
* @author Stephane Nicoll
|
* @author Stephane Nicoll
|
||||||
* @author Aurélien Leboulanger
|
* @author Aurélien Leboulanger
|
||||||
|
* @author Venil Noronha
|
||||||
*/
|
*/
|
||||||
public class ActiveMQPropertiesTests {
|
public class ActiveMQPropertiesTests {
|
||||||
|
|
||||||
|
|
@ -62,4 +64,23 @@ public class ActiveMQPropertiesTests {
|
||||||
.determineBrokerUrl()).isEqualTo("vm://foo-bar");
|
.determineBrokerUrl()).isEqualTo("vm://foo-bar");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void setTrustAllPackages() {
|
||||||
|
this.properties.getPackages().setTrustAll(true);
|
||||||
|
assertThat(new ActiveMQConnectionFactoryFactory(this.properties)
|
||||||
|
.createConnectionFactory(ActiveMQConnectionFactory.class)
|
||||||
|
.isTrustAllPackages()).isEqualTo(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void setTrustedPackages() {
|
||||||
|
this.properties.getPackages().setTrustAll(false);
|
||||||
|
this.properties.getPackages().getTrusted().add("trusted.package");
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue