Commit fd4033f6 authored by Matt Tucker's avatar Matt Tucker Committed by matt

Initial support for JID escaping (JM-230).


git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/trunk@1302 b35dd754-fafc-0310-a699-88a17e54d16e
parent bf11ac8f
...@@ -15,6 +15,7 @@ import org.jivesoftware.messenger.user.*; ...@@ -15,6 +15,7 @@ import org.jivesoftware.messenger.user.*;
import org.jivesoftware.util.JiveConstants; import org.jivesoftware.util.JiveConstants;
import org.jivesoftware.util.JiveGlobals; import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.util.Log; import org.jivesoftware.util.Log;
import org.xmpp.packet.JID;
import javax.naming.NamingEnumeration; import javax.naming.NamingEnumeration;
import javax.naming.directory.*; import javax.naming.directory.*;
...@@ -61,6 +62,8 @@ public class LdapUserProvider implements UserProvider { ...@@ -61,6 +62,8 @@ public class LdapUserProvider implements UserProvider {
} }
public User loadUser(String username) throws UserNotFoundException { public User loadUser(String username) throws UserNotFoundException {
// Un-escape username.
username = JID.unescapeNode(username);
DirContext ctx = null; DirContext ctx = null;
try { try {
String userDN = manager.findUserDN(username); String userDN = manager.findUserDN(username);
...@@ -153,10 +156,10 @@ public class LdapUserProvider implements UserProvider { ...@@ -153,10 +156,10 @@ public class LdapUserProvider implements UserProvider {
NamingEnumeration answer = ctx.search("", filter, constraints); NamingEnumeration answer = ctx.search("", filter, constraints);
while (answer.hasMoreElements()) { while (answer.hasMoreElements()) {
// Get the next userID. // Get the next userID.
usernames.add( String username = (String)((SearchResult)answer.next()).getAttributes().get(
(String)((SearchResult)answer.next()).getAttributes().get( manager.getUsernameField()).get();
manager.getUsernameField()).get() // Escape username and add to results.
); usernames.add(JID.escapeNode(username));
} }
} }
catch (Exception e) { catch (Exception e) {
...@@ -207,11 +210,11 @@ public class LdapUserProvider implements UserProvider { ...@@ -207,11 +210,11 @@ public class LdapUserProvider implements UserProvider {
"ldap.clientSideSorting")).booleanValue()) "ldap.clientSideSorting")).booleanValue())
{ {
while (answer.hasMoreElements()) { while (answer.hasMoreElements()) {
// Get the next userID. // Get the next userID.
usernames.add( String username = (String)((SearchResult)answer.next()).getAttributes().get(
(String)((SearchResult)answer.next()).getAttributes().get( manager.getUsernameField()).get();
manager.getUsernameField()).get() // Escape username and add to results.
); usernames.add(JID.escapeNode(username));
} }
Collections.sort(usernames); Collections.sort(usernames);
usernames = usernames.subList(startIndex, startIndex+numResults); usernames = usernames.subList(startIndex, startIndex+numResults);
...@@ -230,10 +233,10 @@ public class LdapUserProvider implements UserProvider { ...@@ -230,10 +233,10 @@ public class LdapUserProvider implements UserProvider {
for (int i = 0; i < numResults; i++) { for (int i = 0; i < numResults; i++) {
if (answer.hasMoreElements()) { if (answer.hasMoreElements()) {
// Get the next userID. // Get the next userID.
usernames.add( String username = (String)((SearchResult)answer.next()).getAttributes().get(
(String)((SearchResult)answer.next()).getAttributes().get( manager.getUsernameField()).get();
manager.getUsernameField()).get() // Escape username and add to results.
); usernames.add(JID.escapeNode(username));
} }
else { else {
break; break;
...@@ -323,10 +326,10 @@ public class LdapUserProvider implements UserProvider { ...@@ -323,10 +326,10 @@ public class LdapUserProvider implements UserProvider {
NamingEnumeration answer = ctx.search("", filter.toString(), constraints); NamingEnumeration answer = ctx.search("", filter.toString(), constraints);
while (answer.hasMoreElements()) { while (answer.hasMoreElements()) {
// Get the next userID. // Get the next userID.
usernames.add( String username = (String)((SearchResult)answer.next()).getAttributes().get(
(String)((SearchResult)answer.next()).getAttributes().get( manager.getUsernameField()).get();
manager.getUsernameField()).get() // Escape username and add to results.
); usernames.add(JID.escapeNode(username));
} }
// If client-side sorting is enabled, sort. // If client-side sorting is enabled, sort.
if (Boolean.valueOf(JiveGlobals.getXMLProperty( if (Boolean.valueOf(JiveGlobals.getXMLProperty(
...@@ -398,10 +401,10 @@ public class LdapUserProvider implements UserProvider { ...@@ -398,10 +401,10 @@ public class LdapUserProvider implements UserProvider {
for (int i = 0; i < numResults; i++) { for (int i = 0; i < numResults; i++) {
if (answer.hasMoreElements()) { if (answer.hasMoreElements()) {
// Get the next userID. // Get the next userID.
usernames.add( String username = (String)((SearchResult)answer.next()).getAttributes().get(
(String)((SearchResult)answer.next()).getAttributes().get( manager.getUsernameField()).get();
manager.getUsernameField()).get() // Escape username and add to results.
); usernames.add(JID.escapeNode(username));
} }
else { else {
break; break;
......
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