Commit 00a1e3b9 authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gato

Enclose userDN values between " if encloseUserDN property is true (by default). JM-695

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@4378 b35dd754-fafc-0310-a699-88a17e54d16e
parent 1b284e86
......@@ -12,7 +12,6 @@
package org.jivesoftware.wildfire.ldap;
import org.jivesoftware.util.JiveConstants;
import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.util.Log;
import org.jivesoftware.wildfire.XMPPServer;
import org.jivesoftware.wildfire.group.Group;
......@@ -44,7 +43,6 @@ public class LdapGroupProvider implements GroupProvider {
private int groupCount;
private long expiresStamp;
private String[] standardAttributes;
private Pattern userDNPattern;
/**
* Constructor of the LdapGroupProvider class. Gets an LdapManager instance from the LdapManager class.
......@@ -58,8 +56,6 @@ public class LdapGroupProvider implements GroupProvider {
standardAttributes[0] = manager.getGroupNameField();
standardAttributes[1] = manager.getGroupDescriptionField();
standardAttributes[2] = manager.getGroupMemberField();
// Set the pattern to use to figure out if we need to wrap userDNs between "
userDNPattern = Pattern.compile("(=)([\\w ]*[\\\\].[\\w ]*)");
}
/**
......@@ -266,18 +262,7 @@ public class LdapGroupProvider implements GroupProvider {
}
username = JID.unescapeNode(user.getNode());
try {
String userDN = manager.findUserDN(username);
if (JiveGlobals.getXMLProperty("ldap.wrapUserDN", true)) {
// Check if we need to wrap values between "
// eg. cn=John\, Doe,ou=People --> cn="John\, Doe",ou=People
Matcher matcher = userDNPattern.matcher(userDN);
while (matcher.find()) {
userDN = matcher.replaceFirst(
matcher.group(1) + "\"" + matcher.group(2) + "\"");
matcher.reset(userDN);
}
}
username = userDN + "," + manager.getBaseDN();
username = manager.findUserDN(username) + "," + manager.getBaseDN();
}
catch (Exception e) {
Log.error("Could not find user in LDAP " + username);
......
......@@ -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