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 @@ ...@@ -12,7 +12,6 @@
package org.jivesoftware.wildfire.ldap; package org.jivesoftware.wildfire.ldap;
import org.jivesoftware.util.JiveConstants; import org.jivesoftware.util.JiveConstants;
import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.util.Log; import org.jivesoftware.util.Log;
import org.jivesoftware.wildfire.XMPPServer; import org.jivesoftware.wildfire.XMPPServer;
import org.jivesoftware.wildfire.group.Group; import org.jivesoftware.wildfire.group.Group;
...@@ -44,7 +43,6 @@ public class LdapGroupProvider implements GroupProvider { ...@@ -44,7 +43,6 @@ public class LdapGroupProvider implements GroupProvider {
private int groupCount; private int groupCount;
private long expiresStamp; private long expiresStamp;
private String[] standardAttributes; private String[] standardAttributes;
private Pattern userDNPattern;
/** /**
* Constructor of the LdapGroupProvider class. Gets an LdapManager instance from the LdapManager class. * Constructor of the LdapGroupProvider class. Gets an LdapManager instance from the LdapManager class.
...@@ -58,8 +56,6 @@ public class LdapGroupProvider implements GroupProvider { ...@@ -58,8 +56,6 @@ public class LdapGroupProvider implements GroupProvider {
standardAttributes[0] = manager.getGroupNameField(); standardAttributes[0] = manager.getGroupNameField();
standardAttributes[1] = manager.getGroupDescriptionField(); standardAttributes[1] = manager.getGroupDescriptionField();
standardAttributes[2] = manager.getGroupMemberField(); 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 { ...@@ -266,18 +262,7 @@ public class LdapGroupProvider implements GroupProvider {
} }
username = JID.unescapeNode(user.getNode()); username = JID.unescapeNode(user.getNode());
try { try {
String userDN = manager.findUserDN(username); username = manager.findUserDN(username) + "," + manager.getBaseDN();
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();
} }
catch (Exception e) { catch (Exception e) {
Log.error("Could not find user in LDAP " + username); Log.error("Could not find user in LDAP " + username);
......
...@@ -29,6 +29,8 @@ import java.util.ArrayList; ...@@ -29,6 +29,8 @@ import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Hashtable; import java.util.Hashtable;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/** /**
* Centralized administration of LDAP connections. The getInstance() method * Centralized administration of LDAP connections. The getInstance() method
...@@ -79,6 +81,7 @@ public class LdapManager { ...@@ -79,6 +81,7 @@ public class LdapManager {
private boolean connectionPoolEnabled = true; private boolean connectionPoolEnabled = true;
private String searchFilter = null; private String searchFilter = null;
private boolean subTreeSearch; private boolean subTreeSearch;
private boolean encloseUserDN;
private String groupNameField = "cn"; private String groupNameField = "cn";
private String groupMemberField = "member"; private String groupMemberField = "member";
...@@ -86,6 +89,8 @@ public class LdapManager { ...@@ -86,6 +89,8 @@ public class LdapManager {
private boolean posixMode = false; private boolean posixMode = false;
private String groupSearchFilter = null; private String groupSearchFilter = null;
private Pattern userDNPattern;
private static LdapManager instance = new LdapManager(); private static LdapManager instance = new LdapManager();
/** /**
...@@ -176,6 +181,9 @@ public class LdapManager { ...@@ -176,6 +181,9 @@ public class LdapManager {
"ldap.sslEnabled")); "ldap.sslEnabled"));
this.followReferrals = Boolean.valueOf(JiveGlobals.getXMLProperty( this.followReferrals = Boolean.valueOf(JiveGlobals.getXMLProperty(
"ldap.autoFollowReferrals")); "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"); this.initialContextFactory = JiveGlobals.getXMLProperty("ldap.initialContextFactory");
if (initialContextFactory != null) { if (initialContextFactory != null) {
try { try {
...@@ -522,11 +530,17 @@ public class LdapManager { ...@@ -522,11 +530,17 @@ public class LdapManager {
if (userDN.startsWith("ldap://")) { if (userDN.startsWith("ldap://")) {
userDN = userDN.replace("," + baseDN, ""); userDN = userDN.replace("," + baseDN, "");
userDN = userDN.substring(userDN.lastIndexOf("/") + 1); userDN = userDN.substring(userDN.lastIndexOf("/") + 1);
return userDN;
} }
else { if (encloseUserDN) {
return userDN; // 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) { catch (Exception e) {
if (debug) { 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