diff --git a/activemq-broker/src/main/java/org/apache/activemq/security/SimpleCachedLDAPAuthorizationMap.java b/activemq-broker/src/main/java/org/apache/activemq/security/SimpleCachedLDAPAuthorizationMap.java index 87a606934e0..16697f59613 100644 --- a/activemq-broker/src/main/java/org/apache/activemq/security/SimpleCachedLDAPAuthorizationMap.java +++ b/activemq-broker/src/main/java/org/apache/activemq/security/SimpleCachedLDAPAuthorizationMap.java @@ -936,7 +936,11 @@ public void namingExceptionThrown(NamingExceptionEvent namingExceptionEvent) { // Init / Destroy public void afterPropertiesSet() throws Exception { - query(); + try { + query(); + } catch (Exception e) { + LOG.error("Error updating authorization map. Partial policy may be applied until the next successful update.", e); + } } public void destroy() throws Exception { diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/security/LdapCachedLDAPAuthorizationMapTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/security/LdapCachedLDAPAuthorizationMapTest.java new file mode 100644 index 00000000000..ab373b2978f --- /dev/null +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/security/LdapCachedLDAPAuthorizationMapTest.java @@ -0,0 +1,41 @@ +/** + * 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 org.apache.activemq.broker.BrokerFactory; +import org.apache.activemq.broker.BrokerService; +import org.junit.After; +import org.junit.Test; + +public class LdapCachedLDAPAuthorizationMapTest { + + private BrokerService broker; + + @After + public void shutdown() throws Exception { + if (broker != null) { + broker.stop(); + broker.waitUntilStopped(); + } + } + @Test + public void testStartBrokerWhenLdapServerIsUnreachable() throws Exception { + broker = BrokerFactory.createBroker("xbean:org/apache/activemq/security/activemq-ldap-cached-map.xml"); + broker.start(); + broker.waitUntilStarted(); + } +} diff --git a/activemq-unit-tests/src/test/resources/login.config b/activemq-unit-tests/src/test/resources/login.config index 1f5f77c8059..ad9d05224fd 100644 --- a/activemq-unit-tests/src/test/resources/login.config +++ b/activemq-unit-tests/src/test/resources/login.config @@ -84,4 +84,23 @@ LDAPLogin { roleSearchMatching="(uid={1})" roleSearchSubtree=true ; +}; + +UnreachableLDAPLogin { + org.apache.activemq.jaas.LDAPLoginModule required + debug=true + initialContextFactory=com.sun.jndi.ldap.LdapCtxFactory + connectionURL="ldap://test.ldap:636" + connectionUsername="uid=admin,ou=system" + connectionPassword=secret + connectionProtocol=s + authentication=simple + userBase="ou=User,ou=ActiveMQ,ou=system" + userSearchMatching="(uid={0})" + userSearchSubtree=false + roleBase="ou=Group,ou=ActiveMQ,ou=system" + roleName=cn + roleSearchMatching="(uid={1})" + roleSearchSubtree=true + ; }; \ No newline at end of file diff --git a/activemq-unit-tests/src/test/resources/org/apache/activemq/security/activemq-ldap-cached-map.xml b/activemq-unit-tests/src/test/resources/org/apache/activemq/security/activemq-ldap-cached-map.xml new file mode 100644 index 00000000000..38b684c34f0 --- /dev/null +++ b/activemq-unit-tests/src/test/resources/org/apache/activemq/security/activemq-ldap-cached-map.xml @@ -0,0 +1,57 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +