Skip to content

Commit 178b1cc

Browse files
committed
Add more transport types to the denied list for JMX (apache#1949) (apache#1953)
Cherry-picked from 5.19.x: f7e4726
1 parent cebd975 commit 178b1cc

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

@@ -2033,16 +2031,13 @@ public void testSubscriptionViewProperties() throws Exception {
20332031
assertTrue(subscription.isExclusive());
20342032
}
20352033

2036-
// Test to verify http transport is not allowed to be added as a connector
2034+
// Test to verify blocked transport schemes are not allowed to be added as a connector
20372035
// through the Broker MBean
2038-
public void testAddHttpConnectorBlockedBrokerView() throws Exception {
2039-
testAddTransportConnectorBlockedBrokerView("http");
2040-
}
2041-
2042-
// Test to verify vm transport is not allowed to be added as a connector
2043-
// through the Broker MBean
2044-
public void testAddVmConnectorBlockedBrokerView() throws Exception {
2045-
testAddTransportConnectorBlockedBrokerView("vm");
2036+
public void testAddConnectorBlockedBrokerView() throws Exception {
2037+
for (String deniedScheme : DENIED_TRANSPORT_SCHEMES) {
2038+
LOG.info("verify testAddConnectorBlockedBrokerView scheme: {}", deniedScheme);
2039+
testAddTransportConnectorBlockedBrokerView(deniedScheme);
2040+
}
20462041
}
20472042

20482043
protected void testAddTransportConnectorBlockedBrokerView(String scheme) throws Exception {
@@ -2051,23 +2046,23 @@ protected void testAddTransportConnectorBlockedBrokerView(String scheme) throws
20512046

20522047
try {
20532048
brokerView.addConnector(scheme + "://localhost");
2054-
fail("Should have failed trying to add connector");
2049+
fail("Should have failed trying to add connector with scheme: " + scheme);
20552050
} catch (IllegalArgumentException e) {
20562051
assertEquals("Transport scheme '" + scheme + "' is not allowed", e.getMessage());
20572052
}
20582053

20592054
try {
20602055
// verify any composite URI is blocked as well
2061-
brokerView.addConnector("failover:(tcp://0.0.0.0:0," + scheme + "://" + brokerName + ")");
2062-
fail("Should have failed trying to add connector");
2056+
brokerView.addConnector("static:(tcp://0.0.0.0:0," + scheme + "://" + brokerName + ")");
2057+
fail("Should have failed trying to add connector with scheme: " + scheme);
20632058
} catch (IllegalArgumentException e) {
20642059
assertEquals("Transport scheme '" + scheme + "' is not allowed", e.getMessage());
20652060
}
20662061

20672062
try {
20682063
// verify nested composite URI is blocked
2069-
brokerView.addConnector("failover:(failover:(failover:(" + scheme + "://localhost)))");
2070-
fail("Should have failed trying to add connector");
2064+
brokerView.addConnector("static:(static:(static:(" + scheme + "://localhost)))");
2065+
fail("Should have failed trying to add connector with scheme: " + scheme);
20712066
} catch (IllegalArgumentException e) {
20722067
assertEquals("Transport scheme '" + scheme + "' is not allowed", e.getMessage());
20732068
}
@@ -2081,7 +2076,7 @@ public void testNestedAddTransportConnector() throws Exception {
20812076
try {
20822077
// verify nested composite URI with more than 5 levels is blocked
20832078
brokerView.addConnector(
2084-
"static:(failover:(failover:(failover:(failover:(failover:(tcp://localhost:0))))))");
2079+
"static:(static:(static:(static:(static:(static:(tcp://localhost:0))))))");
20852080
fail("Should have failed trying to add vm connector bridge");
20862081
} catch (IllegalArgumentException e) {
20872082
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)