Skip to content

WIP: AMQ-9627 Don't fail on start if cachedLDAPAuthorizationMap is used and the LDAP server is not available. #1358

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would also include a string that suggest ways for the user to mitigate it. Something like "The LDAP server might not be reachable, check ..." even tho the root cause can be many reason. Because "authorization map" is an internal concept, user might not get it and they don't know how to get themselves unstuck. However, It needs to be phrase in such a way that this is one possible root cause, but not necessarily THE root cause.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the error message will look something like:

ERROR | Error updating authorization map.  Partial policy may be applied until the next successful update.
javax.naming.CommunicationException: localhost:1024

which is exactly the same as the error users will see when the map is trying to update the cached values, but the ldap server is unreachable. in my opinion it has enough details about what went wrong(the communication exception).
my concern is more about Partial policy may be applied until the next successful update, because technically, there is no data, so nothing will be applied until the next successful update

}
}

public void destroy() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}
}
19 changes: 19 additions & 0 deletions activemq-unit-tests/src/test/resources/login.config
Original file line number Diff line number Diff line change
Expand Up @@ -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
;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<!-- START SNIPPET: xbean -->
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd">

<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"/>

<broker useJmx="false" xmlns="http://activemq.apache.org/schema/core" persistent="false">

<destinations>
<queue physicalName="ADMIN.FOO" />
</destinations>

<plugins>
<jaasAuthenticationPlugin configuration="UnreachableLDAPLogin"/>
<authorizationPlugin>
<map>
<cachedLDAPAuthorizationMap
queueSearchBase="ou=Queue,ou=Destination,ou=corp,dc=corp,dc=example,dc=com"
topicSearchBase="ou=Topic,ou=Destination,ou=corp,dc=corp,dc=example,dc=com"
tempSearchBase="ou=Temp,ou=Destination,ou=corp,dc=corp,dc=example,dc=com"
refreshInterval="300000"
legacyGroupMapping="false"
connectionPassword="test"
/>
</map>
</authorizationPlugin>
</plugins>


<transportConnectors>
<transportConnector uri="tcp://localhost:61616"/>
</transportConnectors>

</broker>

</beans>
<!-- END SNIPPET: xbean -->