Skip to content

Commit fb9f86d

Browse files
authored
Add more transport types to the denied list for JMX (#1949)
Add on more types to the list of denied transports through JMX Follow on to #1918
1 parent 0d4ed95 commit fb9f86d

3 files changed

Lines changed: 32 additions & 40 deletions

File tree

activemq-broker/src/main/java/org/apache/activemq/broker/jmx/BrokerView.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ public class BrokerView implements BrokerViewMBean {
4444

4545
private static final Logger LOG = LoggerFactory.getLogger(BrokerView.class);
4646

47-
private static final Set<String> DENIED_TRANSPORT_SCHEMES = Set.of("vm", "http");
47+
public static final Set<String> DENIED_TRANSPORT_SCHEMES = Set.of("vm", "http",
48+
"multicast", "zeroconf", "discovery", "fanout", "mock", "peer", "failover",
49+
"proxy", "reliable", "simple", "udp");
4850

4951
ManagedRegionBroker broker;
5052

activemq-unit-tests/src/test/java/org/apache/activemq/broker/jmx/MBeanTest.java

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616
*/
1717
package org.apache.activemq.broker.jmx;
1818

19-
import static org.junit.Assert.assertEquals;
20-
import static org.junit.Assert.fail;
19+
import static org.apache.activemq.broker.jmx.BrokerView.DENIED_TRANSPORT_SCHEMES;
2120

2221
import java.io.BufferedReader;
2322
import java.io.InputStreamReader;
@@ -68,7 +67,6 @@
6867
import org.apache.activemq.util.JMXSupport;
6968
import org.apache.activemq.util.URISupport;
7069
import org.apache.activemq.util.Wait;
71-
import org.junit.Test;
7270
import org.junit.experimental.categories.Category;
7371
import org.slf4j.Logger;
7472
import org.slf4j.LoggerFactory;
@@ -2058,16 +2056,13 @@ public void testSubscriptionViewProperties() throws Exception {
20582056
assertTrue(subscription.isExclusive());
20592057
}
20602058

2061-
// Test to verify http transport is not allowed to be added as a connector
2059+
// Test to verify blocked transport schemes are not allowed to be added as a connector
20622060
// through the Broker MBean
2063-
public void testAddHttpConnectorBlockedBrokerView() throws Exception {
2064-
testAddTransportConnectorBlockedBrokerView("http");
2065-
}
2066-
2067-
// Test to verify vm transport is not allowed to be added as a connector
2068-
// through the Broker MBean
2069-
public void testAddVmConnectorBlockedBrokerView() throws Exception {
2070-
testAddTransportConnectorBlockedBrokerView("vm");
2061+
public void testAddConnectorBlockedBrokerView() throws Exception {
2062+
for (String deniedScheme : DENIED_TRANSPORT_SCHEMES) {
2063+
LOG.info("verify testAddConnectorBlockedBrokerView scheme: {}", deniedScheme);
2064+
testAddTransportConnectorBlockedBrokerView(deniedScheme);
2065+
}
20712066
}
20722067

20732068
protected void testAddTransportConnectorBlockedBrokerView(String scheme) throws Exception {
@@ -2076,23 +2071,23 @@ protected void testAddTransportConnectorBlockedBrokerView(String scheme) throws
20762071

20772072
try {
20782073
brokerView.addConnector(scheme + "://localhost");
2079-
fail("Should have failed trying to add connector");
2074+
fail("Should have failed trying to add connector with scheme: " + scheme);
20802075
} catch (IllegalArgumentException e) {
20812076
assertEquals("Transport scheme '" + scheme + "' is not allowed", e.getMessage());
20822077
}
20832078

20842079
try {
20852080
// verify any composite URI is blocked as well
2086-
brokerView.addConnector("failover:(tcp://0.0.0.0:0," + scheme + "://" + brokerName + ")");
2087-
fail("Should have failed trying to add connector");
2081+
brokerView.addConnector("static:(tcp://0.0.0.0:0," + scheme + "://" + brokerName + ")");
2082+
fail("Should have failed trying to add connector with scheme: " + scheme);
20882083
} catch (IllegalArgumentException e) {
20892084
assertEquals("Transport scheme '" + scheme + "' is not allowed", e.getMessage());
20902085
}
20912086

20922087
try {
20932088
// verify nested composite URI is blocked
2094-
brokerView.addConnector("failover:(failover:(failover:(" + scheme + "://localhost)))");
2095-
fail("Should have failed trying to add connector");
2089+
brokerView.addConnector("static:(static:(static:(" + scheme + "://localhost)))");
2090+
fail("Should have failed trying to add connector with scheme: " + scheme);
20962091
} catch (IllegalArgumentException e) {
20972092
assertEquals("Transport scheme '" + scheme + "' is not allowed", e.getMessage());
20982093
}
@@ -2106,7 +2101,7 @@ public void testNestedAddTransportConnector() throws Exception {
21062101
try {
21072102
// verify nested composite URI with more than 5 levels is blocked
21082103
brokerView.addConnector(
2109-
"static:(failover:(failover:(failover:(failover:(failover:(tcp://localhost:0))))))");
2104+
"static:(static:(static:(static:(static:(static:(tcp://localhost:0))))))");
21102105
fail("Should have failed trying to add vm connector bridge");
21112106
} catch (IllegalArgumentException e) {
21122107
assertEquals("URI can't contain more than 5 nested composite URIs", e.getMessage());

activemq-unit-tests/src/test/java/org/apache/activemq/jmx/JmxCreateNCTest.java

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@
2020
import org.apache.activemq.broker.jmx.BrokerViewMBean;
2121
import org.apache.activemq.broker.jmx.NetworkConnectorViewMBean;
2222
import org.junit.After;
23-
import org.junit.AfterClass;
2423
import org.junit.Before;
2524
import org.junit.Test;
2625

2726
import javax.management.ObjectName;
27+
import org.slf4j.Logger;
28+
import org.slf4j.LoggerFactory;
2829

30+
import static org.apache.activemq.broker.jmx.BrokerView.DENIED_TRANSPORT_SCHEMES;
2931
import static org.junit.Assert.assertEquals;
3032
import static org.junit.Assert.assertNotNull;
3133
import static org.junit.Assert.fail;
@@ -36,6 +38,8 @@
3638
*/
3739
public class JmxCreateNCTest {
3840

41+
private static final Logger LOG = LoggerFactory.getLogger(JmxCreateNCTest.class);
42+
3943
private static final String BROKER_NAME = "jmx-broker";
4044

4145
private BrokerService broker;
@@ -79,43 +83,34 @@ public void testBridgeRegistration() throws Exception {
7983
}
8084

8185
@Test
82-
public void testVmBridgeBlocked() throws Exception {
83-
testDeniedBridgeBlocked("vm");
84-
}
85-
86-
@Test
87-
public void testHttpBridgeBlocked() throws Exception {
88-
testDeniedBridgeBlocked("http");
86+
public void testTransportSchemeBridgeBlocked() throws Exception {
87+
for (String deniedScheme : DENIED_TRANSPORT_SCHEMES) {
88+
LOG.info("verify testTransportSchemeBridgeBlocked scheme: {}", deniedScheme);
89+
testTransportSchemeBridgeBlocked(deniedScheme);
90+
}
8991
}
9092

91-
protected void testDeniedBridgeBlocked(String scheme) throws Exception {
93+
protected void testTransportSchemeBridgeBlocked(String scheme) throws Exception {
9294
// Test composite network connector uri
9395
try {
9496
proxy.addNetworkConnector("static:(" + scheme + "://localhost)");
95-
fail("Should have failed trying to add connector bridge");
96-
} catch (IllegalArgumentException e) {
97-
assertEquals("Transport scheme '" + scheme + "' is not allowed", e.getMessage());
98-
}
99-
100-
try {
101-
proxy.addNetworkConnector("multicast:(" + scheme + "://localhost)");
102-
fail("Should have failed trying to add connector bridge");
97+
fail("Should have failed trying to add connector bridge with scheme: " + scheme);
10398
} catch (IllegalArgumentException e) {
10499
assertEquals("Transport scheme '" + scheme + "' is not allowed", e.getMessage());
105100
}
106101

107102
// verify direct connector as well
108103
try {
109104
proxy.addNetworkConnector(scheme + "://localhost");
110-
fail("Should have failed trying to add connector bridge");
105+
fail("Should have failed trying to add connector bridge with scheme: " + scheme);
111106
} catch (IllegalArgumentException e) {
112107
assertEquals("Transport scheme '" + scheme + "' is not allowed", e.getMessage());
113108
}
114109

115110
try {
116111
// verify nested composite URI is blocked
117-
proxy.addNetworkConnector("static:(failover:(failover:(tcp://localhost:0," + scheme + "://localhost)))");
118-
fail("Should have failed trying to add connector bridge");
112+
proxy.addNetworkConnector("static:(static:(static:(tcp://localhost:0," + scheme + "://localhost)))");
113+
fail("Should have failed trying to add connector bridge with scheme: " + scheme);
119114
} catch (IllegalArgumentException e) {
120115
assertEquals("Transport scheme '" + scheme + "' is not allowed", e.getMessage());
121116
}
@@ -131,7 +126,7 @@ public void testAddNetworkConnectorMaxComposite() throws Exception {
131126
// verify nested composite URI with more than 5 levels is blocked. This has 6 nested
132127
// (not including first wrapper url
133128
proxy.addNetworkConnector(
134-
"static:(failover:(failover:(failover:(failover:(failover:(tcp://localhost:0))))))");
129+
"static:(static:(static:(static:(static:(static:(tcp://localhost:0))))))");
135130
fail("Should have failed trying to add more than 5 connector bridges");
136131
} catch (IllegalArgumentException e) {
137132
assertEquals("URI can't contain more than 5 nested composite URIs", e.getMessage());

0 commit comments

Comments
 (0)