Commit aeaebc2b authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gato

Ported fix from TRUNK for JM-695.

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/branches/3_0_branch@4399 b35dd754-fafc-0310-a699-88a17e54d16e
parent 0005a006
......@@ -472,8 +472,9 @@ public class LdapGroupProvider implements GroupProvider {
// it passes the filter.
try {
JID userJID;
int position = username.indexOf("@" + serverName);
// Create JID of local user if JID does not match a component's JID
if (!username.contains(serverName)) {
if (position == -1) {
// In order to lookup a username from the manager, the username
// must be a properly escaped JID node.
String escapedUsername = JID.escapeNode(username);
......@@ -487,7 +488,9 @@ public class LdapGroupProvider implements GroupProvider {
}
else {
// This is a JID of a component or node of a server's component
userJID = new JID(username);
String node = username.substring(0, position);
String escapedUsername = JID.escapeNode(node);
userJID = new JID(escapedUsername + "@" + serverName);
}
members.add(userJID);
}
......
......@@ -29,6 +29,8 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.Hashtable;
import java.util.StringTokenizer;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Centralized administration of LDAP connections. The getInstance() method
......@@ -79,6 +81,7 @@ public class LdapManager {
private boolean connectionPoolEnabled = true;
private String searchFilter = null;
private boolean subTreeSearch;
private boolean encloseUserDN;
private String groupNameField = "cn";
private String groupMemberField = "member";
......@@ -86,6 +89,8 @@ public class LdapManager {
private boolean posixMode = false;
private String groupSearchFilter = null;
private Pattern userDNPattern;
private static LdapManager instance = new LdapManager();
/**
......@@ -176,6 +181,9 @@ public class LdapManager {
"ldap.sslEnabled"));
this.followReferrals = Boolean.valueOf(JiveGlobals.getXMLProperty(
"ldap.autoFollowReferrals"));
encloseUserDN = JiveGlobals.getXMLProperty("ldap.encloseUserDN", true);
// Set the pattern to use to wrap userDNs values "
userDNPattern = Pattern.compile("(=)([^\\\"][^=]*[^\\\"])(?:,|$)");
this.initialContextFactory = JiveGlobals.getXMLProperty("ldap.initialContextFactory");
if (initialContextFactory != null) {
try {
......@@ -522,11 +530,17 @@ public class LdapManager {
if (userDN.startsWith("ldap://")) {
userDN = userDN.replace("," + baseDN, "");
userDN = userDN.substring(userDN.lastIndexOf("/") + 1);
return userDN;
}
else {
return userDN;
if (encloseUserDN) {
// Enclose userDN values between "
// 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;
}
catch (Exception e) {
if (debug) {
......
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