Commit 37c43c81 authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gato

Optimization - do not load User when not needed.

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@6364 b35dd754-fafc-0310-a699-88a17e54d16e
parent ec5e51fa
...@@ -23,8 +23,6 @@ import org.jivesoftware.wildfire.net.SocketConnection; ...@@ -23,8 +23,6 @@ import org.jivesoftware.wildfire.net.SocketConnection;
import org.jivesoftware.wildfire.privacy.PrivacyList; import org.jivesoftware.wildfire.privacy.PrivacyList;
import org.jivesoftware.wildfire.privacy.PrivacyListManager; import org.jivesoftware.wildfire.privacy.PrivacyListManager;
import org.jivesoftware.wildfire.user.PresenceEventDispatcher; import org.jivesoftware.wildfire.user.PresenceEventDispatcher;
import org.jivesoftware.wildfire.user.User;
import org.jivesoftware.wildfire.user.UserManager;
import org.jivesoftware.wildfire.user.UserNotFoundException; import org.jivesoftware.wildfire.user.UserNotFoundException;
import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException; import org.xmlpull.v1.XmlPullParserException;
...@@ -526,20 +524,16 @@ public class ClientSession extends Session { ...@@ -526,20 +524,16 @@ public class ClientSession extends Session {
* *
* @param auth the authentication token obtained from the AuthFactory. * @param auth the authentication token obtained from the AuthFactory.
* @param resource the resource this session authenticated under. * @param resource the resource this session authenticated under.
* @param userManager the user manager this authentication occured under.
*/ */
public void setAuthToken(AuthToken auth, UserManager userManager, String resource) public void setAuthToken(AuthToken auth, String resource) {
throws UserNotFoundException setAddress(new JID(auth.getUsername(), getServerName(), resource));
{
User user = userManager.getUser(auth.getUsername());
setAddress(new JID(user.getUsername(), getServerName(), resource));
authToken = auth; authToken = auth;
sessionManager.addSession(this); sessionManager.addSession(this);
setStatus(Session.STATUS_AUTHENTICATED); setStatus(Session.STATUS_AUTHENTICATED);
// Set default privacy list for this session // Set default privacy list for this session
setDefaultList(PrivacyListManager.getInstance().getDefaultPrivacyList(user.getUsername())); setDefaultList(PrivacyListManager.getInstance().getDefaultPrivacyList(auth.getUsername()));
} }
/** /**
......
...@@ -222,7 +222,7 @@ public class IQAuthHandler extends IQHandler implements IQAuthInfo { ...@@ -222,7 +222,7 @@ public class IQAuthHandler extends IQHandler implements IQAuthInfo {
} }
} }
// Set that the new session has been authenticated successfully // Set that the new session has been authenticated successfully
session.setAuthToken(token, userManager, resource); session.setAuthToken(token, resource);
packet.setFrom(session.getAddress()); packet.setFrom(session.getAddress());
return IQ.createResultIQ(packet); return IQ.createResultIQ(packet);
} }
......
...@@ -18,8 +18,6 @@ import org.jivesoftware.util.Log; ...@@ -18,8 +18,6 @@ import org.jivesoftware.util.Log;
import org.jivesoftware.wildfire.*; import org.jivesoftware.wildfire.*;
import org.jivesoftware.wildfire.auth.AuthToken; import org.jivesoftware.wildfire.auth.AuthToken;
import org.jivesoftware.wildfire.auth.UnauthorizedException; import org.jivesoftware.wildfire.auth.UnauthorizedException;
import org.jivesoftware.wildfire.user.UserManager;
import org.jivesoftware.wildfire.user.UserNotFoundException;
import org.xmpp.packet.IQ; import org.xmpp.packet.IQ;
import org.xmpp.packet.PacketError; import org.xmpp.packet.PacketError;
import org.xmpp.packet.StreamError; import org.xmpp.packet.StreamError;
...@@ -39,7 +37,6 @@ import org.xmpp.packet.StreamError; ...@@ -39,7 +37,6 @@ import org.xmpp.packet.StreamError;
public class IQBindHandler extends IQHandler { public class IQBindHandler extends IQHandler {
private IQHandlerInfo info; private IQHandlerInfo info;
private UserManager userManager;
private XMPPServer localServer; private XMPPServer localServer;
public IQBindHandler() { public IQBindHandler() {
...@@ -83,58 +80,48 @@ public class IQBindHandler extends IQHandler { ...@@ -83,58 +80,48 @@ public class IQBindHandler extends IQHandler {
return null; return null;
} }
} }
try { // Get the token that was generated during the SASL authentication
// Get the token that was generated during the SASL authentication AuthToken authToken = session.getAuthToken();
AuthToken authToken = session.getAuthToken(); if (authToken.isAnonymous()) {
if (authToken.isAnonymous()) { // User used ANONYMOUS SASL so initialize the session as an anonymous login
// User used ANONYMOUS SASL so initialize the session as an anonymous login session.setAnonymousAuth();
session.setAnonymousAuth(); }
} else {
else { String username = authToken.getUsername().toLowerCase();
String username = authToken.getUsername().toLowerCase(); // If a session already exists with the requested JID, then check to see
// If a session already exists with the requested JID, then check to see // if we should kick it off or refuse the new connection
// if we should kick it off or refuse the new connection if (sessionManager.isActiveRoute(username, resource)) {
if (sessionManager.isActiveRoute(username, resource)) { ClientSession oldSession;
ClientSession oldSession; try {
try { String domain = localServer.getServerInfo().getName();
String domain = localServer.getServerInfo().getName(); oldSession = sessionManager.getSession(username, domain, resource);
oldSession = sessionManager.getSession(username, domain, resource); oldSession.incrementConflictCount();
oldSession.incrementConflictCount(); int conflictLimit = sessionManager.getConflictKickLimit();
int conflictLimit = sessionManager.getConflictKickLimit(); if (conflictLimit != SessionManager.NEVER_KICK &&
if (conflictLimit != SessionManager.NEVER_KICK && oldSession.getConflictCount() > conflictLimit) {
oldSession.getConflictCount() > conflictLimit) { Connection conn = oldSession.getConnection();
Connection conn = oldSession.getConnection(); if (conn != null) {
if (conn != null) { // Kick out the old connection that is conflicting with the new one
// Kick out the old connection that is conflicting with the new one StreamError error = new StreamError(StreamError.Condition.conflict);
StreamError error = new StreamError(StreamError.Condition.conflict); conn.deliverRawText(error.toXML());
conn.deliverRawText(error.toXML()); conn.close();
conn.close();
}
}
else {
reply.setChildElement(packet.getChildElement().createCopy());
reply.setError(PacketError.Condition.conflict);
// Send the error directly since a route does not exist at this point.
session.process(reply);
return null;
} }
} }
catch (Exception e) { else {
Log.error("Error during login", e); reply.setChildElement(packet.getChildElement().createCopy());
reply.setError(PacketError.Condition.conflict);
// Send the error directly since a route does not exist at this point.
session.process(reply);
return null;
} }
} }
// If the connection was not refused due to conflict, log the user in catch (Exception e) {
session.setAuthToken(authToken, userManager, resource); Log.error("Error during login", e);
}
} }
// If the connection was not refused due to conflict, log the user in
session.setAuthToken(authToken, resource);
} }
catch (UserNotFoundException e) {
reply.setChildElement(packet.getChildElement().createCopy());
reply.setError(PacketError.Condition.not_authorized);
// Send the error directly since a route does not exist at this point.
session.process(reply);
return null;
}
child.addElement("jid").setText(session.getAddress().toString()); child.addElement("jid").setText(session.getAddress().toString());
// Send the response directly since a route does not exist at this point. // Send the response directly since a route does not exist at this point.
...@@ -145,7 +132,6 @@ public class IQBindHandler extends IQHandler { ...@@ -145,7 +132,6 @@ public class IQBindHandler extends IQHandler {
public void initialize(XMPPServer server) { public void initialize(XMPPServer server) {
super.initialize(server); super.initialize(server);
localServer = server; localServer = server;
userManager = server.getUserManager();
} }
public IQHandlerInfo getInfo() { public IQHandlerInfo getInfo() {
......
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