Skip to content

Commit e19cc3e

Browse files
authored
Add more transport types to the denied list for JMX (#1949) (#1952)
Add on more types to the list of denied transports through JMX Follow on to #1918 (cherry picked from commit fb9f86d)
1 parent 0982ba4 commit e19cc3e

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;
@@ -67,7 +66,6 @@
6766
import org.apache.activemq.util.JMXSupport;
6867
import org.apache.activemq.util.URISupport;
6968
import org.apache.activemq.util.Wait;
70-
import org.junit.Test;
7169
import org.slf4j.Logger;
7270
import org.slf4j.LoggerFactory;
7371

@@ -2060,16 +2058,13 @@ public void testSubscriptionViewProperties() throws Exception {
20602058
assertTrue(subscription.isExclusive());
20612059
}
20622060

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

20752070
protected void testAddTransportConnectorBlockedBrokerView(String scheme) throws Exception {
@@ -2078,23 +2073,23 @@ protected void testAddTransportConnectorBlockedBrokerView(String scheme) throws
20782073

20792074
try {
20802075
brokerView.addConnector(scheme + "://localhost");
2081-
fail("Should have failed trying to add connector");
2076+
fail("Should have failed trying to add connector with scheme: " + scheme);
20822077
} catch (IllegalArgumentException e) {
20832078
assertEquals("Transport scheme '" + scheme + "' is not allowed", e.getMessage());
20842079
}
20852080

20862081
try {
20872082
// verify any composite URI is blocked as well
2088-
brokerView.addConnector("failover:(tcp://0.0.0.0:0," + scheme + "://" + brokerName + ")");
2089-
fail("Should have failed trying to add connector");
2083+
brokerView.addConnector("static:(tcp://0.0.0.0:0," + scheme + "://" + brokerName + ")");
2084+
fail("Should have failed trying to add connector with scheme: " + scheme);
20902085
} catch (IllegalArgumentException e) {
20912086
assertEquals("Transport scheme '" + scheme + "' is not allowed", e.getMessage());
20922087
}
20932088

20942089
try {
20952090
// verify nested composite URI is blocked
2096-
brokerView.addConnector("failover:(failover:(failover:(" + scheme + "://localhost)))");
2097-
fail("Should have failed trying to add connector");
2091+
brokerView.addConnector("static:(static:(static:(" + scheme + "://localhost)))");
2092+
fail("Should have failed trying to add connector with scheme: " + scheme);
20982093
} catch (IllegalArgumentException e) {
20992094
assertEquals("Transport scheme '" + scheme + "' is not allowed", e.getMessage());
21002095
}
@@ -2108,7 +2103,7 @@ public void testNestedAddTransportConnector() throws Exception {
21082103
try {
21092104
// verify nested composite URI with more than 5 levels is blocked
21102105
brokerView.addConnector(
2111-
"static:(failover:(failover:(failover:(failover:(failover:(tcp://localhost:0))))))");
2106+
"static:(static:(static:(static:(static:(static:(tcp://localhost:0))))))");
21122107
fail("Should have failed trying to add vm connector bridge");
21132108
} catch (IllegalArgumentException e) {
21142109
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)