Commit 75e0dd64 authored by Tom Evans's avatar Tom Evans Committed by tevans

OF-657: Handle JID escaping; group cache optimization

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@13623 b35dd754-fafc-0310-a699-88a17e54d16e
parent fd6696b5
...@@ -83,18 +83,14 @@ public class CrowdAuthProvider implements AuthProvider { ...@@ -83,18 +83,14 @@ public class CrowdAuthProvider implements AuthProvider {
} else { } else {
// Unknown domain. Return authentication failed. // Unknown domain. Return authentication failed.
throw new UnauthorizedException(); throw new UnauthorizedException();
} }
} }
// Un-escape username. try {
username = JID.unescapeNode(username); manager.authenticate(username, password);
} catch (RemoteException re) {
try { throw new UnauthorizedException();
manager.authenticate(username, password); }
LOG.info("authenticated user:" + username);
} catch (RemoteException re) {
throw new UnauthorizedException();
}
} }
public void authenticate(String username, String token, String digest) throws UnauthorizedException, ConnectionException, InternalUnauthenticatedException { public void authenticate(String username, String token, String digest) throws UnauthorizedException, ConnectionException, InternalUnauthenticatedException {
......
...@@ -78,14 +78,14 @@ public class CrowdGroupProvider extends AbstractGroupProvider { ...@@ -78,14 +78,14 @@ public class CrowdGroupProvider extends AbstractGroupProvider {
Cache<JID, Collection<String>> userMembershipCache = CacheFactory.createLocalCache(USER_MEMBERSHIP_CACHE_NAME); Cache<JID, Collection<String>> userMembershipCache = CacheFactory.createLocalCache(USER_MEMBERSHIP_CACHE_NAME);
userMembershipCache.setMaxCacheSize(-1); userMembershipCache.setMaxCacheSize(-1);
userMembershipCache.setMaxLifetime(ttl * 1000); // msecs instead of sec - see Cache API userMembershipCache.setMaxLifetime(ttl * 1000); // msecs instead of sec - see Cache API
Cache<String, org.jivesoftware.openfire.crowd.jaxb.Group> groupCache = CacheFactory.createLocalCache(GROUP_CACHE_NAME); Cache<String, org.jivesoftware.openfire.crowd.jaxb.Group> groupCache = CacheFactory.createLocalCache(GROUP_CACHE_NAME);
userMembershipCache.setMaxCacheSize(-1); groupCache.setMaxCacheSize(-1);
userMembershipCache.setMaxLifetime(ttl * 1000); // msecs instead of sec - see Cache API groupCache.setMaxLifetime(ttl * 1000); // msecs instead of sec - see Cache API
} }
public Group getGroup(String name) throws GroupNotFoundException { public Group getGroup(String name) throws GroupNotFoundException {
try { try {
Cache<String, org.jivesoftware.openfire.crowd.jaxb.Group> groupCache = CacheFactory.createLocalCache(GROUP_CACHE_NAME); Cache<String, org.jivesoftware.openfire.crowd.jaxb.Group> groupCache = CacheFactory.createLocalCache(GROUP_CACHE_NAME);
org.jivesoftware.openfire.crowd.jaxb.Group group = groupCache.get(name); org.jivesoftware.openfire.crowd.jaxb.Group group = groupCache.get(name);
...@@ -113,13 +113,13 @@ public class CrowdGroupProvider extends AbstractGroupProvider { ...@@ -113,13 +113,13 @@ public class CrowdGroupProvider extends AbstractGroupProvider {
try { try {
List<String> users = manager.getGroupMembers(groupName); List<String> users = manager.getGroupMembers(groupName);
Collection<JID> results = new ArrayList<JID>(); Collection<JID> results = new ArrayList<JID>();
for (String username : users) { for (String username : users) {
results.add(server.createJID(JID.escapeNode(username), null)); results.add(server.createJID(username, null));
} }
groupMembershipCache.put(groupName, results); groupMembershipCache.put(groupName, results);
return results; return results;
} catch (RemoteException re) { } catch (RemoteException re) {
......
...@@ -25,12 +25,13 @@ import java.util.ArrayList; ...@@ -25,12 +25,13 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import javax.xml.bind.JAXB; import javax.xml.bind.JAXB;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.apache.commons.httpclient.Credentials; import org.xmpp.packet.JID;
import org.apache.commons.httpclient.Header; import org.apache.commons.httpclient.Credentials;
import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpMethod; import org.apache.commons.httpclient.HttpMethod;
import org.apache.commons.httpclient.HttpState; import org.apache.commons.httpclient.HttpState;
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager; import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
...@@ -133,12 +134,13 @@ public class CrowdManager { ...@@ -133,12 +134,13 @@ public class CrowdManager {
* @param username * @param username
* @param password * @param password
* @throws RemoteException * @throws RemoteException
* @throws UnsupportedEncodingException * @throws UnsupportedEncodingException
*/ */
public void authenticate(String username, String password) throws RemoteException { public void authenticate(String username, String password) throws RemoteException {
if (LOG.isDebugEnabled()) LOG.debug("authenticate '" + String.valueOf(username) + "'"); username = JID.unescapeNode(username);
if (LOG.isDebugEnabled()) LOG.debug("authenticate '" + String.valueOf(username) + "'");
PostMethod post = new PostMethod(crowdServer.resolve("authentication?username=" + urlEncode(username)).toString());
PostMethod post = new PostMethod(crowdServer.resolve("authentication?username=" + urlEncode(username)).toString());
AuthenticatePost creds = new AuthenticatePost(); AuthenticatePost creds = new AuthenticatePost();
creds.value = password; creds.value = password;
...@@ -154,12 +156,14 @@ public class CrowdManager { ...@@ -154,12 +156,14 @@ public class CrowdManager {
} catch (IOException ioe) { } catch (IOException ioe) {
handleError(ioe); handleError(ioe);
} finally { } finally {
post.releaseConnection(); post.releaseConnection();
} }
}
LOG.info("authenticated user:" + username);
}
/** /**
* Get all the users from Crowd * Get all the users from Crowd
* @return a List of User containing all the users stored in Crowd * @return a List of User containing all the users stored in Crowd
...@@ -189,12 +193,13 @@ public class CrowdManager { ...@@ -189,12 +193,13 @@ public class CrowdManager {
} finally { } finally {
get.releaseConnection(); get.releaseConnection();
} }
if (users != null && users.user != null) { if (users != null && users.user != null) {
for (User user : users.user) { for (User user : users.user) {
results.add(user); user.name = JID.escapeNode(user.name);
} results.add(user);
}
if (users.user.size() != maxResults) { if (users.user.size() != maxResults) {
break; break;
} else { } else {
...@@ -270,12 +275,13 @@ public class CrowdManager { ...@@ -270,12 +275,13 @@ public class CrowdManager {
* Get all the groups of a given username * Get all the groups of a given username
* @param username * @param username
* @return a List of groups name * @return a List of groups name
* @throws RemoteException * @throws RemoteException
*/ */
public List<String> getUserGroups(String username) throws RemoteException { public List<String> getUserGroups(String username) throws RemoteException {
if (LOG.isDebugEnabled()) LOG.debug("fetch all crowd groups for user:" + username); username = JID.unescapeNode(username);
if (LOG.isDebugEnabled()) LOG.debug("fetch all crowd groups for user:" + username);
int maxResults = 100;
int maxResults = 100;
int startIndex = 0; int startIndex = 0;
List<String> results = new ArrayList<String>(); List<String> results = new ArrayList<String>();
StringBuilder request = new StringBuilder("user/group/nested?username=").append(urlEncode(username)) StringBuilder request = new StringBuilder("user/group/nested?username=").append(urlEncode(username))
...@@ -380,13 +386,13 @@ public class CrowdManager { ...@@ -380,13 +386,13 @@ public class CrowdManager {
} finally { } finally {
get.releaseConnection(); get.releaseConnection();
} }
if (users != null && users.user != null) { if (users != null && users.user != null) {
for (org.jivesoftware.openfire.crowd.jaxb.User user : users.user) { for (org.jivesoftware.openfire.crowd.jaxb.User user : users.user) {
results.add(user.name); results.add(JID.escapeNode(user.name));
} }
if (users.user.size() != maxResults) { if (users.user.size() != maxResults) {
break; break;
} else { } else {
startIndex += maxResults; startIndex += maxResults;
......
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