Commit de5369f0 authored by Austen Rustrum's avatar Austen Rustrum Committed by austen.rustrum

JM-1327

Subscriptions not working when baseDN has a comma that is not a delimiter (unenclosed string).

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@10296 b35dd754-fafc-0310-a699-88a17e54d16e
parent 6b9d5c77
...@@ -42,6 +42,7 @@ import java.text.MessageFormat; ...@@ -42,6 +42,7 @@ import java.text.MessageFormat;
* <li>ldap.alternateBaseDN</li> * <li>ldap.alternateBaseDN</li>
* <li>ldap.adminDN</li> * <li>ldap.adminDN</li>
* <li>ldap.adminPassword</li> * <li>ldap.adminPassword</li>
* <li>ldap.encloseDNs</li>
* <li>ldap.usernameField -- default value is "uid".</li> * <li>ldap.usernameField -- default value is "uid".</li>
* <li>ldap.usernameSuffix -- default value is "".</li> * <li>ldap.usernameSuffix -- default value is "".</li>
* <li>ldap.nameField -- default value is "cn".</li> * <li>ldap.nameField -- default value is "cn".</li>
...@@ -141,6 +142,7 @@ public class LdapManager { ...@@ -141,6 +142,7 @@ public class LdapManager {
private String alternateBaseDN = null; private String alternateBaseDN = null;
private String adminDN = null; private String adminDN = null;
private String adminPassword; private String adminPassword;
private boolean encloseDNs;
private boolean ldapDebugEnabled = false; private boolean ldapDebugEnabled = false;
private boolean sslEnabled = false; private boolean sslEnabled = false;
private String initialContextFactory; private String initialContextFactory;
...@@ -158,8 +160,7 @@ public class LdapManager { ...@@ -158,8 +160,7 @@ public class LdapManager {
private boolean posixMode = false; private boolean posixMode = false;
private String groupSearchFilter = null; private String groupSearchFilter = null;
private Pattern userDNPattern; private Pattern dnPattern;
private Pattern groupDNPattern;
private Map<String, String> properties; private Map<String, String> properties;
...@@ -209,6 +210,7 @@ public class LdapManager { ...@@ -209,6 +210,7 @@ public class LdapManager {
JiveGlobals.migrateProperty("ldap.autoFollowAliasReferrals"); JiveGlobals.migrateProperty("ldap.autoFollowAliasReferrals");
JiveGlobals.migrateProperty("ldap.encloseUserDN"); JiveGlobals.migrateProperty("ldap.encloseUserDN");
JiveGlobals.migrateProperty("ldap.encloseGroupDN"); JiveGlobals.migrateProperty("ldap.encloseGroupDN");
JiveGlobals.migrateProperty("ldap.encloseDNs");
JiveGlobals.migrateProperty("ldap.initialContextFactory"); JiveGlobals.migrateProperty("ldap.initialContextFactory");
JiveGlobals.migrateProperty("ldap.pagedResultsSize"); JiveGlobals.migrateProperty("ldap.pagedResultsSize");
JiveGlobals.migrateProperty("ldap.clientSideSorting"); JiveGlobals.migrateProperty("ldap.clientSideSorting");
...@@ -251,11 +253,30 @@ public class LdapManager { ...@@ -251,11 +253,30 @@ public class LdapManager {
if (usernameSuffix == null) { if (usernameSuffix == null) {
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)
encloseDNs = true;
String encloseStr = properties.get("ldap.encloseDNs");
if (encloseStr != null) {
encloseDNs = Boolean.valueOf(encloseStr);
}
baseDN = properties.get("ldap.baseDN"); baseDN = properties.get("ldap.baseDN");
if (baseDN == null) { if (baseDN == null) {
baseDN = ""; baseDN = "";
} }
if (encloseDNs) {
baseDN = getEnclosedDN(baseDN);
}
alternateBaseDN = properties.get("ldap.alternateBaseDN"); alternateBaseDN = properties.get("ldap.alternateBaseDN");
if (encloseDNs && alternateBaseDN != null) {
alternateBaseDN = getEnclosedDN(alternateBaseDN);
}
nameField = properties.get("ldap.nameField"); nameField = properties.get("ldap.nameField");
if (nameField == null) { if (nameField == null) {
nameField = "cn"; nameField = "cn";
...@@ -298,6 +319,10 @@ public class LdapManager { ...@@ -298,6 +319,10 @@ public class LdapManager {
if (adminDN != null && adminDN.trim().equals("")) { if (adminDN != null && adminDN.trim().equals("")) {
adminDN = null; adminDN = null;
} }
if (encloseDNs && adminDN != null) {
adminDN = getEnclosedDN(adminDN);
}
adminPassword = properties.get("ldap.adminPassword"); adminPassword = properties.get("ldap.adminPassword");
ldapDebugEnabled = false; ldapDebugEnabled = false;
String ldapDebugStr = properties.get("ldap.debugEnabled"); String ldapDebugStr = properties.get("ldap.debugEnabled");
...@@ -319,20 +344,17 @@ public class LdapManager { ...@@ -319,20 +344,17 @@ public class LdapManager {
if (followAliasReferralsStr != null) { if (followAliasReferralsStr != null) {
followAliasReferrals = Boolean.valueOf(followAliasReferralsStr); followAliasReferrals = Boolean.valueOf(followAliasReferralsStr);
} }
// the following two properties have been deprecated by ldap.encloseDNs. keeping around for backwards compatibility
encloseUserDN = true; encloseUserDN = true;
String encloseUserStr = properties.get("ldap.encloseUserDN"); String encloseUserStr = properties.get("ldap.encloseUserDN");
if (encloseUserStr != null) { if (encloseUserStr != null) {
encloseUserDN = Boolean.valueOf(encloseUserStr); encloseUserDN = Boolean.valueOf(encloseUserStr) || encloseDNs;
} }
encloseGroupDN = true; encloseGroupDN = true;
String encloseGroupStr = properties.get("ldap.encloseGroupDN"); String encloseGroupStr = properties.get("ldap.encloseGroupDN");
if (encloseGroupStr != null) { if (encloseGroupStr != null) {
encloseGroupDN = Boolean.valueOf(encloseGroupStr); encloseGroupDN = Boolean.valueOf(encloseGroupStr) || encloseDNs;
} }
// Set the pattern to use to wrap userDNs values "
userDNPattern = Pattern.compile("(=)([^\\\"][^=]*[^\\\"])(?:,|$)");
// Set the pattern to use to wrap groupDNs values "
groupDNPattern = Pattern.compile("(=)([^\\\"][^=]*[^\\\"])(?:,|$)");
this.initialContextFactory = properties.get("ldap.initialContextFactory"); this.initialContextFactory = properties.get("ldap.initialContextFactory");
if (initialContextFactory != null) { if (initialContextFactory != null) {
try { try {
...@@ -718,13 +740,7 @@ public class LdapManager { ...@@ -718,13 +740,7 @@ public class LdapManager {
userDN = java.net.URLDecoder.decode(userDN, "UTF-8"); userDN = java.net.URLDecoder.decode(userDN, "UTF-8");
} }
if (encloseUserDN) { if (encloseUserDN) {
// Enclose userDN values between " userDN = getEnclosedDN(userDN);
// eg. cn=John\, Doe,ou=People --> cn="John\, Doe",ou="People"
Matcher matcher = userDNPattern.matcher(userDN);
userDN = matcher.replaceAll("$1\"$2\",");
if (userDN.endsWith(",")) {
userDN = userDN.substring(0, userDN.length() - 1);
}
} }
return userDN; return userDN;
} }
...@@ -868,13 +884,7 @@ public class LdapManager { ...@@ -868,13 +884,7 @@ public class LdapManager {
groupDN = java.net.URLDecoder.decode(groupDN, "UTF-8"); groupDN = java.net.URLDecoder.decode(groupDN, "UTF-8");
} }
if (encloseGroupDN) { if (encloseGroupDN) {
// Enclose groupDN values between " groupDN = getEnclosedDN(groupDN);
// eg. cn=Domain\, Users,ou=Administrators --> cn="Domain\, Users",ou="Administrators"
Matcher matcher = groupDNPattern.matcher(groupDN);
groupDN = matcher.replaceAll("$1\"$2\",");
if (groupDN.endsWith(",")) {
groupDN = groupDN.substring(0, groupDN.length() - 1);
}
} }
return groupDN; return groupDN;
} }
...@@ -1133,6 +1143,9 @@ public class LdapManager { ...@@ -1133,6 +1143,9 @@ public class LdapManager {
* @return the starting DN used for performing searches. * @return the starting DN used for performing searches.
*/ */
public String getBaseDN() { public String getBaseDN() {
if (encloseDNs)
return getEnclosedDN(baseDN);
else
return baseDN; return baseDN;
} }
...@@ -1156,7 +1169,7 @@ public class LdapManager { ...@@ -1156,7 +1169,7 @@ public class LdapManager {
* DN is set, this method will return <tt>null</tt>. * DN is set, this method will return <tt>null</tt>.
*/ */
public String getAlternateBaseDN() { public String getAlternateBaseDN() {
return alternateBaseDN; return getEnclosedDN(alternateBaseDN);
} }
/** /**
...@@ -1235,6 +1248,9 @@ public class LdapManager { ...@@ -1235,6 +1248,9 @@ public class LdapManager {
* @return the starting DN used for performing searches. * @return the starting DN used for performing searches.
*/ */
public String getAdminDN() { public String getAdminDN() {
if (encloseDNs)
return getEnclosedDN(adminDN);
else
return adminDN; return adminDN;
} }
...@@ -1842,4 +1858,22 @@ public class LdapManager { ...@@ -1842,4 +1858,22 @@ public class LdapManager {
} }
return count; return count;
} }
/**
* Encloses DN values with "
*
* @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")
*/
private String getEnclosedDN(String dnValue) {
if (dnValue == null || dnValue.equals("")) {
return dnValue;
}
Matcher matcher = dnPattern.matcher(dnValue);
dnValue = matcher.replaceAll("$1\"$2\"$3");
dnValue = dnValue.replace("\\,", ",");
return dnValue;
}
} }
\ No newline at end of file
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