Commit 14df7a18 authored by Daniel Henninger's avatar Daniel Henninger Committed by dhenninger

Fixed enclosing of dns that have one character pieces in them. (dn=a for...

Fixed enclosing of dns that have one character pieces in them.  (dn=a for example)  Added a simple unit test for it.

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@10798 b35dd754-fafc-0310-a699-88a17e54d16e
parent 14b649a5
...@@ -160,8 +160,6 @@ public class LdapManager { ...@@ -160,8 +160,6 @@ public class LdapManager {
private boolean posixMode = false; private boolean posixMode = false;
private String groupSearchFilter = null; private String groupSearchFilter = null;
private Pattern dnPattern;
private Map<String, String> properties; private Map<String, String> properties;
/** /**
...@@ -254,9 +252,6 @@ public class LdapManager { ...@@ -254,9 +252,6 @@ public class LdapManager {
usernameSuffix = ""; usernameSuffix = "";
} }
// Set the pattern to use to wrap DN values with "
dnPattern = Pattern.compile("([^\\\\]=)([^\"].*?[^\\\\])(,|$)");
// are we going to enclose DN values with quotes? (needed when DNs contain non-delimiting commas) // are we going to enclose DN values with quotes? (needed when DNs contain non-delimiting commas)
encloseDNs = true; encloseDNs = true;
String encloseStr = properties.get("ldap.encloseDNs"); String encloseStr = properties.get("ldap.encloseDNs");
...@@ -1875,7 +1870,7 @@ public class LdapManager { ...@@ -1875,7 +1870,7 @@ public class LdapManager {
* @param dnValue the unenclosed value of a DN (e.g. ou=Jive Software\, Inc,dc=support,dc=jive,dc=com) * @param dnValue the unenclosed value of a DN (e.g. ou=Jive Software\, Inc,dc=support,dc=jive,dc=com)
* @return String the enclosed value of the DN (e.g. ou="Jive Software\, Inc",dc="support",dc="jive",dc="com") * @return String the enclosed value of the DN (e.g. ou="Jive Software\, Inc",dc="support",dc="jive",dc="com")
*/ */
private String getEnclosedDN(String dnValue) { public static String getEnclosedDN(String dnValue) {
if (dnValue == null || dnValue.equals("")) { if (dnValue == null || dnValue.equals("")) {
return dnValue; return dnValue;
} }
...@@ -1886,4 +1881,8 @@ public class LdapManager { ...@@ -1886,4 +1881,8 @@ public class LdapManager {
return dnValue; return dnValue;
} }
// Set the pattern to use to wrap DN values with "
private static Pattern dnPattern = Pattern.compile("([^\\\\]=)([^\"]*?[^\\\\])(,|$)");
} }
\ No newline at end of file
/**
* $Revision$
* $Date$
*
* Copyright (C) 2008 Daniel Henninger. All rights reserved.
*
* This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution.
*/
package org.jivesoftware.util;
import junit.framework.TestCase;
import org.jivesoftware.openfire.ldap.LdapManager;
/**
* @author Daniel Henninger
*/
public class LDAPTest extends TestCase {
public void testEncloseDN() {
String before = "ou=Jive Software\\, Inc,dc=support,dc=jive,dc=com";
String after = "ou=\"Jive Software, Inc\",dc=\"support\",dc=\"jive\",dc=\"com\"";
String converted = LdapManager.getEnclosedDN(before);
assertTrue("Conversion result "+before+" to "+converted, converted.equals(after));
before = "ou=Jive Software\\, Inc,dc=t,dc=jive,dc=com";
after = "ou=\"Jive Software, Inc\",dc=\"t\",dc=\"jive\",dc=\"com\"";
converted = LdapManager.getEnclosedDN(before);
assertTrue("Conversion result "+before+" to "+converted, converted.equals(after));
before = "ou=jive,dc=test,dc=jive,dc=com";
after = "ou=\"jive\",dc=\"test\",dc=\"jive\",dc=\"com\"";
converted = LdapManager.getEnclosedDN(before);
assertTrue("Conversion result "+before+" to "+converted, converted.equals(after));
}
}
Markdown is supported
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