You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ma...@apache.org on 2026/10/20 08:16:01 UTC

(activemq) branch activemq-6.3.x updated: LDAP hardening (#2695) (#2703)

This is an automated email from the ASF dual-hosted git repository.

mattrpav pushed a commit to branch activemq-6.3.x
in repository https://gitbox.apache.org/repos/asf/activemq.git


The following commit(s) were added to refs/heads/activemq-6.3.x by this push:
     new 2f9bbf7db2 LDAP hardening (#2695) (#2703)
2f9bbf7db2 is described below

commit 2f9bbf7db23ab17f9d52f8e2e690034bb9cefd72
Author: Matt Pavlovich <ma...@apache.org>
AuthorDate: Tue Oct 20 04:15:55 2026 -0400

    LDAP hardening (#2695) (#2703)
    
    * Test LDAPAuthorizationMap escapes special characters in destination names
    * Escape special characters in destination names when building the LDAP search base
    * Test LDAPLoginModule role name encoding and empty password handling
    * Encode role names and reject empty passwords in LDAPLoginModule
    * Test LdapNetworkConnector validates LDAP-derived URI components
    * Validate LDAP-derived URI components when building the network connector URI
    
    (cherry picked from commit 750da9f036fe5a480667370971a346ecda1b5a1a)
---
 .../activemq/network/LdapNetworkConnector.java     |  20 +++
 .../activemq/security/LDAPAuthorizationMap.java    |   4 +-
 .../activemq/network/LdapNetworkConnectorTest.java |  81 ++++++++++--
 .../org/apache/activemq/jaas/LDAPLoginModule.java  |   8 +-
 .../jaas/LDAPLoginModuleEmptyPasswordTest.java     |  94 ++++++++++++++
 .../LDAPLoginModuleExpandRolesEncodingTest.java    | 144 +++++++++++++++++++++
 .../LDAPAuthorizationMapDestinationNameTest.java   |  93 +++++++++++++
 7 files changed, 433 insertions(+), 11 deletions(-)

diff --git a/activemq-broker/src/main/java/org/apache/activemq/network/LdapNetworkConnector.java b/activemq-broker/src/main/java/org/apache/activemq/network/LdapNetworkConnector.java
index 293091f293..ad61dbccb0 100644
--- a/activemq-broker/src/main/java/org/apache/activemq/network/LdapNetworkConnector.java
+++ b/activemq-broker/src/main/java/org/apache/activemq/network/LdapNetworkConnector.java
@@ -20,6 +20,7 @@ import java.net.URI;
 import java.util.Hashtable;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
+import java.util.regex.Pattern;
 
 import javax.naming.CommunicationException;
 import javax.naming.Context;
@@ -59,6 +60,11 @@ public class LdapNetworkConnector extends NetworkConnector implements NamespaceC
     private static final String REQUIRED_OBJECT_CLASS_FILTER =
             "(&(objectClass=ipHost)(objectClass=ipService))";
 
+    // allowed shapes for the directory attributes used to build the connector URI
+    private static final Pattern PROTOCOL_PATTERN = Pattern.compile("[A-Za-z][A-Za-z0-9+.-]*");
+    private static final Pattern ADDRESS_PATTERN = Pattern.compile("[A-Za-z0-9._\\-\\[\\]:%]+");
+    private static final Pattern PORT_PATTERN = Pattern.compile("\\d{1,5}");
+
     // connection
     private URI[] availableURIs = null;
     private int availableURIsIndex = 0;
@@ -384,11 +390,25 @@ public class LdapNetworkConnector extends NetworkConnector implements NamespaceC
         String address = (String) attributes.get("iphostnumber").get();
         String port = (String) attributes.get("ipserviceport").get();
         String protocol = (String) attributes.get("ipserviceprotocol").get();
+
+        // Reject attribute values that would not form a valid protocol, host, or port so
+        // the assembled connector URI is well formed.
+        validateComponent("ipserviceprotocol", protocol, PROTOCOL_PATTERN);
+        validateComponent("iphostnumber", address, ADDRESS_PATTERN);
+        validateComponent("ipserviceport", port, PORT_PATTERN);
+
         URI connectorURI = new URI("static:(" + protocol + "://" + address + ":" + port + ")");
         LOG.debug("retrieved URI from SearchResult [{}]", connectorURI);
         return connectorURI;
     }
 
+    private static void validateComponent(String name, String value, Pattern allowed) {
+        if (value == null || !allowed.matcher(value).matches()) {
+            throw new IllegalArgumentException(
+                    "Illegal value for LDAP attribute '" + name + "': [" + value + "]");
+        }
+    }
+
     /**
      * convert search result into URI
      *
diff --git a/activemq-broker/src/main/java/org/apache/activemq/security/LDAPAuthorizationMap.java b/activemq-broker/src/main/java/org/apache/activemq/security/LDAPAuthorizationMap.java
index 3e86f7c714..fdce83444a 100644
--- a/activemq-broker/src/main/java/org/apache/activemq/security/LDAPAuthorizationMap.java
+++ b/activemq-broker/src/main/java/org/apache/activemq/security/LDAPAuthorizationMap.java
@@ -392,7 +392,7 @@ public class LDAPAuthorizationMap implements AuthorizationMap {
             destinationBase = advisorySearchBase;
         } else {
             if ((destination.getDestinationType() & ActiveMQDestination.QUEUE_TYPE) == ActiveMQDestination.QUEUE_TYPE) {
-                destinationBase = queueSearchMatchingFormat.format(new String[]{destination.getPhysicalName()});
+                destinationBase = queueSearchMatchingFormat.format(new String[]{Rdn.escapeValue(destination.getPhysicalName())});
                 if (queueSearchSubtreeBool) {
                     constraints.setSearchScope(SearchControls.SUBTREE_SCOPE);
                 } else {
@@ -400,7 +400,7 @@ public class LDAPAuthorizationMap implements AuthorizationMap {
                 }
             }
             if ((destination.getDestinationType() & ActiveMQDestination.TOPIC_TYPE) == ActiveMQDestination.TOPIC_TYPE) {
-                destinationBase = topicSearchMatchingFormat.format(new String[]{destination.getPhysicalName()});
+                destinationBase = topicSearchMatchingFormat.format(new String[]{Rdn.escapeValue(destination.getPhysicalName())});
                 if (topicSearchSubtreeBool) {
                     constraints.setSearchScope(SearchControls.SUBTREE_SCOPE);
                 } else {
diff --git a/activemq-broker/src/test/java/org/apache/activemq/network/LdapNetworkConnectorTest.java b/activemq-broker/src/test/java/org/apache/activemq/network/LdapNetworkConnectorTest.java
index 660860d493..1b74d2aa80 100644
--- a/activemq-broker/src/test/java/org/apache/activemq/network/LdapNetworkConnectorTest.java
+++ b/activemq-broker/src/test/java/org/apache/activemq/network/LdapNetworkConnectorTest.java
@@ -19,8 +19,11 @@ package org.apache.activemq.network;
 
 import static org.apache.activemq.util.TransportValidationUtils.DENIED_TRANSPORT_SCHEMES;
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
+import java.net.URI;
+
 import javax.naming.directory.BasicAttributes;
 import javax.naming.directory.SearchResult;
 import org.apache.activemq.broker.BrokerService;
@@ -44,26 +47,88 @@ public class LdapNetworkConnectorTest {
     }
 
     @Test
-    public void testCompositeValidation() throws Exception {
+    public void testCompositeHostRejected() throws Exception {
         LdapNetworkConnector connector = new LdapNetworkConnector();
-        connector.setBrokerService(new BrokerService());
 
-        for (String deniedScheme : DENIED_TRANSPORT_SCHEMES) {
+        // A host attribute that itself contains a composite URI is not a valid host value
+        // and must be rejected before the URI is assembled.
+        for (String scheme : DENIED_TRANSPORT_SCHEMES) {
             try {
-                connector.addConnector(newSearchResult("tcp", "static:(tcp://localhost," +
-                                deniedScheme + "://localhost)"));
-                fail("Should have failed trying to add connector with scheme: " + deniedScheme);
+                connector.toURI(newSearchResult("tcp", "static:(tcp://localhost," +
+                                scheme + "://localhost)"));
+                fail("Should have failed with host containing: " + scheme);
             } catch (IllegalArgumentException e) {
-                assertEquals("Transport scheme '" + deniedScheme + "' is not allowed", e.getMessage());
+                assertTrue(e.getMessage().contains("iphostnumber"));
             }
         }
     }
 
+    @Test
+    public void testInvalidHostRejected() throws Exception {
+        LdapNetworkConnector connector = new LdapNetworkConnector();
+
+        String[] invalidHosts = {
+            "host.example.com)?x=y",
+            "localhost,tcp://other",
+            "localhost)",
+            "localhost?soTimeout=1",
+            "local host",
+        };
+        for (String host : invalidHosts) {
+            try {
+                connector.toURI(newSearchResult("tcp", host));
+                fail("expected rejection for host [" + host + "]");
+            } catch (IllegalArgumentException e) {
+                assertTrue(e.getMessage().contains("iphostnumber"));
+            }
+        }
+    }
+
+    @Test
+    public void testInvalidProtocolRejected() throws Exception {
+        LdapNetworkConnector connector = new LdapNetworkConnector();
+
+        try {
+            connector.toURI(newSearchResult("tcp://x:1)?a=b&(ssl", "localhost"));
+            fail("expected rejection for invalid protocol");
+        } catch (IllegalArgumentException e) {
+            assertTrue(e.getMessage().contains("ipserviceprotocol"));
+        }
+    }
+
+    @Test
+    public void testInvalidPortRejected() throws Exception {
+        LdapNetworkConnector connector = new LdapNetworkConnector();
+
+        try {
+            connector.toURI(newSearchResult("tcp", "localhost", "61616)?x=y"));
+            fail("expected rejection for invalid port");
+        } catch (IllegalArgumentException e) {
+            assertTrue(e.getMessage().contains("ipserviceport"));
+        }
+    }
+
+    @Test
+    public void testValidComponentsAccepted() throws Exception {
+        LdapNetworkConnector connector = new LdapNetworkConnector();
+
+        assertEquals("static:(tcp://broker.example.com:61616)",
+                connector.toURI(newSearchResult("tcp", "broker.example.com", "61616")).toString());
+        assertEquals("static:(nio+ssl://10.0.0.1:61617)",
+                connector.toURI(newSearchResult("nio+ssl", "10.0.0.1", "61617")).toString());
+        assertEquals("static:(ssl://[::1]:61618)",
+                connector.toURI(newSearchResult("ssl", "[::1]", "61618")).toString());
+    }
+
     private SearchResult newSearchResult(String protocol, String host) {
+        return newSearchResult(protocol, host, "0");
+    }
+
+    private SearchResult newSearchResult(String protocol, String host, String port) {
         BasicAttributes attrs = new BasicAttributes();
         attrs.put("ipserviceprotocol", protocol);
         attrs.put("iphostnumber", host);
-        attrs.put("ipserviceport", "0");
+        attrs.put("ipserviceport", port);
         SearchResult result = new SearchResult("name", null, attrs);
         result.setNameInNamespace("fullname");
         return result;
diff --git a/activemq-jaas/src/main/java/org/apache/activemq/jaas/LDAPLoginModule.java b/activemq-jaas/src/main/java/org/apache/activemq/jaas/LDAPLoginModule.java
index 82462eeb86..c7c12cbf65 100644
--- a/activemq-jaas/src/main/java/org/apache/activemq/jaas/LDAPLoginModule.java
+++ b/activemq-jaas/src/main/java/org/apache/activemq/jaas/LDAPLoginModule.java
@@ -380,7 +380,7 @@ public class LDAPLoginModule implements LoginModule {
             MessageFormat expandRolesMatchingFormat = new MessageFormat(getLDAPPropertyValue(EXPAND_ROLES_MATCHING));
             while (!pendingNameExpansion.isEmpty()) {
                 String name = pendingNameExpansion.remove();
-                filter = expandRolesMatchingFormat.format(new String[]{name});
+                filter = expandRolesMatchingFormat.format(new String[]{doRFC2254Encoding(name)});
                 results = context.search(getLDAPPropertyValue(ROLE_BASE), filter, constraints);
                 while (results.hasMore()) {
                     SearchResult result = results.next();
@@ -430,6 +430,12 @@ public class LDAPLoginModule implements LoginModule {
         if (log.isDebugEnabled()) {
             log.debug("Binding the user.");
         }
+        // An empty or null password is not a valid credential, so fail authentication here
+        // instead of attempting a bind that some directories would accept as anonymous.
+        if (password == null || password.isEmpty()) {
+            log.debug("No password supplied for dn={}, failing authentication", dn);
+            return false;
+        }
         context.addToEnvironment(Context.SECURITY_AUTHENTICATION, "simple");
         context.addToEnvironment(Context.SECURITY_PRINCIPAL, dn);
         context.addToEnvironment(Context.SECURITY_CREDENTIALS, password);
diff --git a/activemq-jaas/src/test/java/org/apache/activemq/jaas/LDAPLoginModuleEmptyPasswordTest.java b/activemq-jaas/src/test/java/org/apache/activemq/jaas/LDAPLoginModuleEmptyPasswordTest.java
new file mode 100644
index 0000000000..5ea7f36ccc
--- /dev/null
+++ b/activemq-jaas/src/test/java/org/apache/activemq/jaas/LDAPLoginModuleEmptyPasswordTest.java
@@ -0,0 +1,94 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.jaas;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.util.HashMap;
+
+import javax.naming.directory.BasicAttributes;
+import javax.naming.directory.DirContext;
+import javax.security.auth.Subject;
+
+import org.junit.Test;
+
+/**
+ * An empty or null password is not a valid credential, so bindUser must report a failed
+ * bind for such input rather than treating the directory's response as a successful login.
+ * Some directories answer a bind that carries a DN and an empty password as an anonymous
+ * bind that does not check credentials, so the check belongs in bindUser itself.
+ */
+public class LDAPLoginModuleEmptyPasswordTest {
+
+    private static final String USER_DN = "uid=jdoe,ou=users,ou=system";
+
+    @Test
+    public void emptyPasswordDoesNotBind() throws Exception {
+        var module = newInitializedModule();
+        assertFalse("empty password must not produce a successful bind",
+                module.bindUser(acceptingContext(), USER_DN, ""));
+    }
+
+    @Test
+    public void nullPasswordDoesNotBind() throws Exception {
+        var module = newInitializedModule();
+        assertFalse("null password must not produce a successful bind",
+                module.bindUser(acceptingContext(), USER_DN, null));
+    }
+
+    @Test
+    public void nonEmptyPasswordStillBinds() throws Exception {
+        var module = newInitializedModule();
+        assertTrue("a non-empty password must still bind when the directory accepts it",
+                module.bindUser(acceptingContext(), USER_DN, "secret"));
+    }
+
+    private static LDAPLoginModule newInitializedModule() {
+        var module = new LDAPLoginModule();
+        module.initialize(new Subject(), null, null, new HashMap<String, String>());
+        return module;
+    }
+
+    // A DirContext whose bind attempt (getAttributes) always succeeds, so the test
+    // exercises bindUser's own handling of the password value.
+    private static DirContext acceptingContext() {
+        InvocationHandler handler = new InvocationHandler() {
+            @Override
+            public Object invoke(Object proxy, Method method, Object[] args) {
+                switch (method.getName()) {
+                case "getAttributes":
+                    return new BasicAttributes();
+                case "toString":
+                    return "acceptingContext";
+                case "hashCode":
+                    return System.identityHashCode(proxy);
+                case "equals":
+                    return proxy == args[0];
+                default:
+                    return null;
+                }
+            }
+        };
+        return (DirContext) Proxy.newProxyInstance(
+                LDAPLoginModule.class.getClassLoader(),
+                new Class[]{DirContext.class}, handler);
+    }
+}
diff --git a/activemq-jaas/src/test/java/org/apache/activemq/jaas/LDAPLoginModuleExpandRolesEncodingTest.java b/activemq-jaas/src/test/java/org/apache/activemq/jaas/LDAPLoginModuleExpandRolesEncodingTest.java
new file mode 100644
index 0000000000..2fb1265e14
--- /dev/null
+++ b/activemq-jaas/src/test/java/org/apache/activemq/jaas/LDAPLoginModuleExpandRolesEncodingTest.java
@@ -0,0 +1,144 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.jaas;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.naming.NamingEnumeration;
+import javax.naming.directory.BasicAttributes;
+import javax.naming.directory.DirContext;
+import javax.naming.directory.SearchResult;
+import javax.security.auth.Subject;
+
+import org.junit.Test;
+
+/**
+ * Verifies that role expansion encodes the role name before it is placed into the LDAP
+ * search filter. The role name used for expansion is the DN reported by the directory
+ * (getNameInNamespace) and can contain characters that are special in an LDAP filter, so
+ * it is encoded per RFC 2254 to keep the filter well formed.
+ */
+public class LDAPLoginModuleExpandRolesEncodingTest {
+
+    // A role DN that contains characters that are special in an LDAP filter ( * ( ) ).
+    private static final String ROLE_DN_WITH_SPECIAL_CHARS = "cn=team (a*b),ou=groups,ou=system";
+
+    @Test
+    public void testExpandRolesFilterIsEncoded() throws Exception {
+        var capturedFilters = new ArrayList<String>();
+
+        var module = new LDAPLoginModule();
+        var options = new HashMap<String, String>();
+        options.put("roleBase", "ou=groups,ou=system");
+        options.put("roleName", "cn");
+        options.put("roleSearchMatching", "(member=uid={1})");
+        options.put("roleSearchSubtree", "true");
+        options.put("expandRoles", "true");
+        options.put("expandRolesMatching", "(member={0})");
+        module.initialize(new Subject(), null, null, options);
+
+        var context = capturingContext(capturedFilters, ROLE_DN_WITH_SPECIAL_CHARS);
+        module.getRoles(context, "uid=first,ou=users,ou=system", "first", null);
+
+        // First search is the role lookup, second is the expansion using the role DN.
+        assertEquals(2, capturedFilters.size());
+        var expandFilter = capturedFilters.get(1);
+
+        assertFalse("expansion filter must not contain the unencoded role name",
+                expandFilter.contains("a*b"));
+        assertEquals("(member=" + module.doRFC2254Encoding(ROLE_DN_WITH_SPECIAL_CHARS) + ")",
+                expandFilter);
+    }
+
+    // Returns a DirContext proxy that records the filter of every search call.
+    // The first search yields one result whose in-namespace name is the role
+    // DN, driving the expansion path; later searches return nothing.
+    private static DirContext capturingContext(List<String> capturedFilters, String roleDn) {
+        var attrs = new BasicAttributes();
+        attrs.put("cn", "role");
+        var result = new SearchResult("cn=role", null, attrs);
+        result.setNameInNamespace(roleDn);
+
+        int[] searchCount = {0};
+        var handler = new InvocationHandler() {
+            @Override
+            public Object invoke(Object proxy, Method method, Object[] args) {
+                switch (method.getName()) {
+                case "search":
+                    capturedFilters.add((String) args[1]);
+                    var results = searchCount[0]++ == 0
+                            ? Collections.singletonList(result)
+                            : Collections.<SearchResult>emptyList();
+                    return new ListNamingEnumeration(results);
+                case "toString":
+                    return "capturingContext";
+                case "hashCode":
+                    return System.identityHashCode(proxy);
+                case "equals":
+                    return proxy == args[0];
+                default:
+                    return null;
+                }
+            }
+        };
+        return (DirContext) Proxy.newProxyInstance(
+                LDAPLoginModule.class.getClassLoader(),
+                new Class[]{DirContext.class}, handler);
+    }
+
+    private static final class ListNamingEnumeration implements NamingEnumeration<SearchResult> {
+        private final Iterator<SearchResult> iterator;
+
+        ListNamingEnumeration(List<SearchResult> results) {
+            this.iterator = results.iterator();
+        }
+
+        @Override
+        public boolean hasMore() {
+            return iterator.hasNext();
+        }
+
+        @Override
+        public SearchResult next() {
+            return iterator.next();
+        }
+
+        @Override
+        public boolean hasMoreElements() {
+            return iterator.hasNext();
+        }
+
+        @Override
+        public SearchResult nextElement() {
+            return iterator.next();
+        }
+
+        @Override
+        public void close() {
+        }
+    }
+}
diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/security/LDAPAuthorizationMapDestinationNameTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/security/LDAPAuthorizationMapDestinationNameTest.java
new file mode 100644
index 0000000000..a690ce907b
--- /dev/null
+++ b/activemq-unit-tests/src/test/java/org/apache/activemq/security/LDAPAuthorizationMapDestinationNameTest.java
@@ -0,0 +1,93 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.security;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.text.MessageFormat;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.naming.directory.DirContext;
+import javax.naming.directory.SearchControls;
+import javax.naming.ldap.Rdn;
+
+import org.apache.activemq.command.ActiveMQQueue;
+import org.apache.activemq.command.ActiveMQTopic;
+import org.apache.activemq.jaas.GroupPrincipal;
+import org.apache.activemq.test.annotations.ParallelTest;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+/**
+ * LDAPAuthorizationMap builds the LDAP search base by substituting the destination physical
+ * name into a DN template. A name containing DN special characters (+, =, \, ", ;) must be
+ * escaped per RFC 4514 so the assembled DN keeps the intended structure and the ACL lookup
+ * resolves to the correct directory entry.
+ *
+ * Comma is the ActiveMQ composite-destination separator, so a comma splits the name into
+ * separate destinations before the DN is built. These tests use + (an LDAP multi-valued RDN
+ * separator) which reaches the DN construction intact.
+ */
+@Category(ParallelTest.class)
+public class LDAPAuthorizationMapDestinationNameTest {
+
+    static class CapturingLDAPAuthorizationMap extends LDAPAuthorizationMap {
+        String capturedBase;
+
+        @Override
+        protected DirContext open() {
+            return null; // no directory server needed; the search base is captured below
+        }
+
+        @Override
+        protected Set<GroupPrincipal> getACLs(String destinationBase, SearchControls constraints,
+                String roleBase, String roleAttribute) {
+            this.capturedBase = destinationBase;
+            return new HashSet<GroupPrincipal>();
+        }
+    }
+
+    @Test
+    public void queueDestinationNameIsEscapedInSearchBase() {
+        var map = new CapturingLDAPAuthorizationMap();
+        map.setQueueSearchMatchingFormat(
+                new MessageFormat("uid={0},ou=queues,ou=destinations,o=ActiveMQ,ou=system"));
+
+        var name = "orders+region=emea";
+        map.getReadACLs(new ActiveMQQueue(name));
+
+        assertNotNull(map.capturedBase);
+        assertEquals("uid=" + Rdn.escapeValue(name) + ",ou=queues,ou=destinations,o=ActiveMQ,ou=system",
+                map.capturedBase);
+    }
+
+    @Test
+    public void topicDestinationNameIsEscapedInSearchBase() {
+        var map = new CapturingLDAPAuthorizationMap();
+        map.setTopicSearchMatchingFormat(
+                new MessageFormat("uid={0},ou=topics,ou=destinations,o=ActiveMQ,ou=system"));
+
+        var name = "orders+region=emea";
+        map.getReadACLs(new ActiveMQTopic(name));
+
+        assertNotNull(map.capturedBase);
+        assertEquals("uid=" + Rdn.escapeValue(name) + ",ou=topics,ou=destinations,o=ActiveMQ,ou=system",
+                map.capturedBase);
+    }
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@activemq.apache.org
For additional commands, e-mail: commits-help@activemq.apache.org
For further information, visit: https://activemq.apache.org/contact