Skip to content

Commit bc6a1ba

Browse files
committed
Add more transport types to the denied list for JMX
Add on more types to the list of denied transports through JMX Follow on to #1918
1 parent 2b91f01 commit bc6a1ba

3 files changed

Lines changed: 32 additions & 26 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",
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: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717
package org.apache.activemq.broker.jmx;
1818

19+
import static org.apache.activemq.broker.jmx.BrokerView.DENIED_TRANSPORT_SCHEMES;
1920
import static org.junit.Assert.assertEquals;
2021
import static org.junit.Assert.fail;
2122

@@ -2058,16 +2059,18 @@ public void testSubscriptionViewProperties() throws Exception {
20582059
assertTrue(subscription.isExclusive());
20592060
}
20602061

2061-
// Test to verify http transport is not allowed to be added as a connector
2062+
// Test to verify blocked transport schemes are not allowed to be added as a connector
20622063
// 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");
2064+
public void testAddConnectorBlockedBrokerView() throws Exception {
2065+
for (String deniedScheme : DENIED_TRANSPORT_SCHEMES) {
2066+
try {
2067+
LOG.info("verify testAddConnectorBlockedBrokerView scheme: {}", deniedScheme);
2068+
testAddTransportConnectorBlockedBrokerView(deniedScheme);
2069+
} catch (Exception e) {
2070+
LOG.warn("testAddConnectorBlockedBrokerView failed for scheme: {}", deniedScheme);
2071+
throw e;
2072+
}
2073+
}
20712074
}
20722075

20732076
protected void testAddTransportConnectorBlockedBrokerView(String scheme) throws Exception {

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

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,18 @@
1717
package org.apache.activemq.jmx;
1818

1919
import org.apache.activemq.broker.BrokerService;
20+
import org.apache.activemq.broker.jmx.BrokerView;
2021
import org.apache.activemq.broker.jmx.BrokerViewMBean;
2122
import org.apache.activemq.broker.jmx.NetworkConnectorViewMBean;
2223
import org.junit.After;
23-
import org.junit.AfterClass;
2424
import org.junit.Before;
2525
import org.junit.Test;
2626

2727
import javax.management.ObjectName;
28+
import org.slf4j.Logger;
29+
import org.slf4j.LoggerFactory;
2830

31+
import static org.apache.activemq.broker.jmx.BrokerView.DENIED_TRANSPORT_SCHEMES;
2932
import static org.junit.Assert.assertEquals;
3033
import static org.junit.Assert.assertNotNull;
3134
import static org.junit.Assert.fail;
@@ -36,6 +39,8 @@
3639
*/
3740
public class JmxCreateNCTest {
3841

42+
private static final Logger LOG = LoggerFactory.getLogger(JmxCreateNCTest.class);
43+
3944
private static final String BROKER_NAME = "jmx-broker";
4045

4146
private BrokerService broker;
@@ -79,16 +84,19 @@ public void testBridgeRegistration() throws Exception {
7984
}
8085

8186
@Test
82-
public void testVmBridgeBlocked() throws Exception {
83-
testDeniedBridgeBlocked("vm");
84-
}
85-
86-
@Test
87-
public void testHttpBridgeBlocked() throws Exception {
88-
testDeniedBridgeBlocked("http");
87+
public void testTransportSchemeBridgeBlocked() throws Exception {
88+
for (String deniedScheme : DENIED_TRANSPORT_SCHEMES) {
89+
try {
90+
LOG.info("verify testTransportSchemeBridgeBlocked scheme: {}", deniedScheme);
91+
testTransportSchemeBridgeBlocked(deniedScheme);
92+
} catch (Exception e) {
93+
LOG.warn("testTransportSchemeBridgeBlocked failed for scheme: {}", deniedScheme);
94+
throw e;
95+
}
96+
}
8997
}
9098

91-
protected void testDeniedBridgeBlocked(String scheme) throws Exception {
99+
protected void testTransportSchemeBridgeBlocked(String scheme) throws Exception {
92100
// Test composite network connector uri
93101
try {
94102
proxy.addNetworkConnector("static:(" + scheme + "://localhost)");
@@ -97,13 +105,6 @@ protected void testDeniedBridgeBlocked(String scheme) throws Exception {
97105
assertEquals("Transport scheme '" + scheme + "' is not allowed", e.getMessage());
98106
}
99107

100-
try {
101-
proxy.addNetworkConnector("multicast:(" + scheme + "://localhost)");
102-
fail("Should have failed trying to add connector bridge");
103-
} catch (IllegalArgumentException e) {
104-
assertEquals("Transport scheme '" + scheme + "' is not allowed", e.getMessage());
105-
}
106-
107108
// verify direct connector as well
108109
try {
109110
proxy.addNetworkConnector(scheme + "://localhost");

0 commit comments

Comments
 (0)