Skip to content

Commit 0ef9542

Browse files
AMQ-9627 Don't fail on start if cachedLDAPAuthorizationMap is used and the LDAP server is not available.
1 parent bd91d97 commit 0ef9542

File tree

4 files changed

+122
-1
lines changed

4 files changed

+122
-1
lines changed

activemq-broker/src/main/java/org/apache/activemq/security/SimpleCachedLDAPAuthorizationMap.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -936,7 +936,11 @@ public void namingExceptionThrown(NamingExceptionEvent namingExceptionEvent) {
936936

937937
// Init / Destroy
938938
public void afterPropertiesSet() throws Exception {
939-
query();
939+
try {
940+
query();
941+
} catch (Exception e) {
942+
LOG.error("Error updating authorization map. Partial policy may be applied until the next successful update.", e);
943+
}
940944
}
941945

942946
public void destroy() throws Exception {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.activemq.security;
18+
19+
import org.apache.activemq.broker.BrokerFactory;
20+
import org.apache.activemq.broker.BrokerService;
21+
import org.junit.After;
22+
import org.junit.Test;
23+
24+
public class LdapCachedLDAPAuthorizationMapTest {
25+
26+
private BrokerService broker;
27+
28+
@After
29+
public void shutdown() throws Exception {
30+
if (broker != null) {
31+
broker.stop();
32+
broker.waitUntilStopped();
33+
}
34+
}
35+
@Test
36+
public void testStartBrokerWhenLdapServerIsUnreachable() throws Exception {
37+
broker = BrokerFactory.createBroker("xbean:org/apache/activemq/security/activemq-ldap-cached-map.xml");
38+
broker.start();
39+
broker.waitUntilStarted();
40+
}
41+
}

activemq-unit-tests/src/test/resources/login.config

+19
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,23 @@ LDAPLogin {
8484
roleSearchMatching="(uid={1})"
8585
roleSearchSubtree=true
8686
;
87+
};
88+
89+
UnreachableLDAPLogin {
90+
org.apache.activemq.jaas.LDAPLoginModule required
91+
debug=true
92+
initialContextFactory=com.sun.jndi.ldap.LdapCtxFactory
93+
connectionURL="ldap://test.ldap:636"
94+
connectionUsername="uid=admin,ou=system"
95+
connectionPassword=secret
96+
connectionProtocol=s
97+
authentication=simple
98+
userBase="ou=User,ou=ActiveMQ,ou=system"
99+
userSearchMatching="(uid={0})"
100+
userSearchSubtree=false
101+
roleBase="ou=Group,ou=ActiveMQ,ou=system"
102+
roleName=cn
103+
roleSearchMatching="(uid={1})"
104+
roleSearchSubtree=true
105+
;
87106
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Licensed to the Apache Software Foundation (ASF) under one or more
4+
contributor license agreements. See the NOTICE file distributed with
5+
this work for additional information regarding copyright ownership.
6+
The ASF licenses this file to You under the Apache License, Version 2.0
7+
(the "License"); you may not use this file except in compliance with
8+
the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
-->
18+
<!-- START SNIPPET: xbean -->
19+
<beans
20+
xmlns="http://www.springframework.org/schema/beans"
21+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
22+
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
23+
http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd">
24+
25+
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"/>
26+
27+
<broker useJmx="false" xmlns="http://activemq.apache.org/schema/core" persistent="false">
28+
29+
<destinations>
30+
<queue physicalName="ADMIN.FOO" />
31+
</destinations>
32+
33+
<plugins>
34+
<jaasAuthenticationPlugin configuration="UnreachableLDAPLogin"/>
35+
<authorizationPlugin>
36+
<map>
37+
<cachedLDAPAuthorizationMap
38+
queueSearchBase="ou=Queue,ou=Destination,ou=corp,dc=corp,dc=example,dc=com"
39+
topicSearchBase="ou=Topic,ou=Destination,ou=corp,dc=corp,dc=example,dc=com"
40+
tempSearchBase="ou=Temp,ou=Destination,ou=corp,dc=corp,dc=example,dc=com"
41+
refreshInterval="300000"
42+
legacyGroupMapping="false"
43+
connectionPassword="test"
44+
/>
45+
</map>
46+
</authorizationPlugin>
47+
</plugins>
48+
49+
50+
<transportConnectors>
51+
<transportConnector uri="tcp://localhost:61616"/>
52+
</transportConnectors>
53+
54+
</broker>
55+
56+
</beans>
57+
<!-- END SNIPPET: xbean -->

0 commit comments

Comments
 (0)