Commit cd238b8b authored by Jonathan CLARKE's avatar Jonathan CLARKE
Browse files

Parse config for several LDAP URLs to allow for redundancy, while fixing #209....

Parse config for several LDAP URLs to allow for redundancy, while fixing #209. Adds a test for this scenario. Fixes #209.
parent b6f14584
......@@ -54,6 +54,8 @@ import java.util.Hashtable;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.naming.CommunicationException;
import javax.naming.CompositeName;
......@@ -143,7 +145,13 @@ public final class JndiServices {
// rewrite connection URI
try {
connProps.setProperty(Context.PROVIDER_URL, new LDAPURL((String) connProps.get(Context.PROVIDER_URL)).toNormalizedString());
String uriString = "";
Matcher uriMatcher = Pattern.compile("ldaps?://[^/]+/.*?(?=( ldaps?://)|$)", Pattern.CASE_INSENSITIVE).matcher(connProps.getProperty(Context.PROVIDER_URL));
while (uriMatcher.find()) {
uriString += new LDAPURL(uriMatcher.group()).toNormalizedString() + " ";
}
connProps.setProperty(Context.PROVIDER_URL, uriString);
LOGGER.debug("Using JNDI URL setting of \"" + connProps.getProperty(Context.PROVIDER_URL) + "\"");
} catch (LDAPException e) {
LOGGER.error(e.toString());
LOGGER.debug(e.toString(), e);
......
......@@ -531,5 +531,29 @@ public class JndiServicesTest {
assertNotNull(sr);
assertEquals("o=Père,dc=lsc-project,dc=org", sr.getNameInNamespace());
}
/**
* testGetInstanceUrlWithMultipleURLs()
*/
@Test
public final void testGetInstanceUrlWithMultipleURLs() throws NamingException, IOException {
Properties props = (Properties) Configuration.getDstProperties().clone();
JndiServices jndiServices;
List<String> sr;
props.put("java.naming.provider.url", Configuration.getString("dst.java.naming.provider.url.multiple.simple"));
jndiServices = JndiServices.getInstance(props);
sr = jndiServices.getDnList("", "cn=test", SearchControls.SUBTREE_SCOPE);
assertNotNull(sr);
assertEquals(1, sr.size());
assertEquals("cn=test,o=bla bla", sr.get(0));
props.put("java.naming.provider.url", Configuration.getString("dst.java.naming.provider.url.multiple.spaces"));
jndiServices = JndiServices.getInstance(props);
sr = jndiServices.getDnList("", "cn=test", SearchControls.SUBTREE_SCOPE);
assertNotNull(sr);
assertEquals(1, sr.size());
assertEquals("cn=test", sr.get(0));
}
}
......@@ -22,6 +22,8 @@ dst.java.naming.provider.url.spaces.new = ldap://localhost:33389/o=bla bla,dc=ls
dst.java.naming.provider.url.spaces.old = ldap://localhost:33389/o=bla\\20bla,dc=lsc-project,dc=org
dst.java.naming.provider.url.accents.new = ldap://localhost:33389/o=Père,dc=lsc-project,dc=org
dst.java.naming.provider.url.accents.old = ldap://localhost:33389/o=P\\c3\\a8re,dc=lsc-project,dc=org
dst.java.naming.provider.url.multiple.simple = ldap://host.that.doesnt.exist/dc=lsc-project,dc=org ldap://localhost:33389/dc=lsc-project,dc=org
dst.java.naming.provider.url.multiple.spaces = ldap://host.that.doesnt.exist/o=bla bla,dc=lsc-project,dc=org ldap://localhost:33389/o=bla bla,dc=lsc-project,dc=org
###################
# Source database #
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment