diff --git a/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/BrokerView.java b/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/BrokerView.java index 56383883893..619912c01a0 100644 --- a/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/BrokerView.java +++ b/activemq-broker/src/main/java/org/apache/activemq/broker/jmx/BrokerView.java @@ -610,7 +610,8 @@ private static void validateAllowedUrl(String uriString) throws URISyntaxExcepti // Validate the URI does not contain VM transport private static void validateAllowedUri(URI uri, int depth) throws URISyntaxException { // Don't allow more than 5 nested URIs to prevent blowing the stack - if (depth > 5) { + // If we are greater than 4 then this is the 5th level of composite + if (depth > 4) { throw new IllegalArgumentException("URI can't contain more than 5 nested composite URIs"); } @@ -625,10 +626,10 @@ private static void validateAllowedUri(URI uri, int depth) throws URISyntaxExcep // Each URI could be a nested composite URI so call validateAllowedUri() // to validate it. This check if composite first so we don't add to // the recursive stack depth if there's a lot of URIs that are not composite - if (URISupport.isCompositeURI(uri)) { + if (URISupport.isCompositeURI(component)) { validateAllowedUri(component, depth); } else { - validateAllowedScheme(uri.getScheme()); + validateAllowedScheme(component.getScheme()); } } } diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/jmx/JmxCreateNCTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/jmx/JmxCreateNCTest.java index 141e5c0ee82..1b3548432bc 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/jmx/JmxCreateNCTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/jmx/JmxCreateNCTest.java @@ -116,11 +116,16 @@ public void testVmBridgeBlocked() throws Exception { @Test public void testAddNetworkConnectorMaxComposite() throws Exception { + // Should allow 5 nested (excludes first wrapper) so no exception thrown + assertNotNull(proxy.addNetworkConnector( + "static:(static:(static:(static:(static:(bad://localhost)))))")); + try { - // verify nested composite URI with more than 5 levels is blocked + // verify nested composite URI with more than 5 levels is blocked. This has 6 nested + // (not including first wrapper url proxy.addNetworkConnector( "static:(failover:(failover:(failover:(failover:(failover:(tcp://localhost:0))))))"); - fail("Should have failed trying to add vm connector bridge"); + fail("Should have failed trying to add more than 5 connector bridges"); } catch (IllegalArgumentException e) { assertEquals("URI can't contain more than 5 nested composite URIs", e.getMessage()); }