Commit b369394d authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gato

Refactoring to use NIO for c2s.

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@6576 b35dd754-fafc-0310-a699-88a17e54d16e
parent 8485752d
...@@ -509,9 +509,8 @@ public class SessionManager extends BasicModule { ...@@ -509,9 +509,8 @@ public class SessionManager extends BasicModule {
* *
* @param conn the connection to create the session from. * @param conn the connection to create the session from.
* @return a newly created session. * @return a newly created session.
* @throws UnauthorizedException
*/ */
public ClientSession createClientSession(Connection conn) throws UnauthorizedException { public ClientSession createClientSession(Connection conn) {
return createClientSession(conn, nextStreamID()); return createClientSession(conn, nextStreamID());
} }
...@@ -523,10 +522,9 @@ public class SessionManager extends BasicModule { ...@@ -523,10 +522,9 @@ public class SessionManager extends BasicModule {
* @return a newly created session. * @return a newly created session.
* @throws UnauthorizedException * @throws UnauthorizedException
*/ */
public ClientSession createClientSession(Connection conn, StreamID id) public ClientSession createClientSession(Connection conn, StreamID id) {
throws UnauthorizedException {
if (serverName == null) { if (serverName == null) {
throw new UnauthorizedException("Server not initialized"); throw new IllegalStateException("Server not initialized");
} }
ClientSession session = new ClientSession(serverName, conn, id); ClientSession session = new ClientSession(serverName, conn, id);
conn.init(session); conn.init(session);
......
...@@ -19,7 +19,6 @@ import org.jivesoftware.wildfire.Connection; ...@@ -19,7 +19,6 @@ import org.jivesoftware.wildfire.Connection;
import org.jivesoftware.wildfire.SessionManager; import org.jivesoftware.wildfire.SessionManager;
import org.jivesoftware.wildfire.StreamID; import org.jivesoftware.wildfire.StreamID;
import org.jivesoftware.wildfire.XMPPServer; import org.jivesoftware.wildfire.XMPPServer;
import org.jivesoftware.wildfire.auth.UnauthorizedException;
import org.jivesoftware.wildfire.event.SessionEventDispatcher; import org.jivesoftware.wildfire.event.SessionEventDispatcher;
import org.jivesoftware.wildfire.event.SessionEventListener; import org.jivesoftware.wildfire.event.SessionEventListener;
import org.jivesoftware.wildfire.session.ClientSession; import org.jivesoftware.wildfire.session.ClientSession;
...@@ -128,7 +127,7 @@ public class ConnectionMultiplexerManager implements SessionEventListener { ...@@ -128,7 +127,7 @@ public class ConnectionMultiplexerManager implements SessionEventListener {
* @param streamID the stream ID created by the connection manager for the new session. * @param streamID the stream ID created by the connection manager for the new session.
*/ */
public void createClientSession(String connectionManagerDomain, String streamID) { public void createClientSession(String connectionManagerDomain, String streamID) {
try { // TODO Consider that client session may return null when IP address is forbidden
Connection connection = new ClientSessionConnection(connectionManagerDomain); Connection connection = new ClientSessionConnection(connectionManagerDomain);
ClientSession session = SessionManager.getInstance() ClientSession session = SessionManager.getInstance()
.createClientSession(connection, new BasicStreamID(streamID)); .createClientSession(connection, new BasicStreamID(streamID));
...@@ -147,10 +146,6 @@ public class ConnectionMultiplexerManager implements SessionEventListener { ...@@ -147,10 +146,6 @@ public class ConnectionMultiplexerManager implements SessionEventListener {
} }
sessions.put(streamID, session); sessions.put(streamID, session);
} }
catch (UnauthorizedException e) {
Log.error("Error creating virtual client session", e);
}
}
/** /**
* Closes an existing client session that was established through a connection manager. * Closes an existing client session that was established through a connection manager.
......
...@@ -53,6 +53,10 @@ public abstract class StanzaHandler { ...@@ -53,6 +53,10 @@ public abstract class StanzaHandler {
// Flag that indicates that the client requested to be authenticated. Once the // Flag that indicates that the client requested to be authenticated. Once the
// authentication process is over the value will return to false. // authentication process is over the value will return to false.
private boolean startedSASL = false; private boolean startedSASL = false;
/**
* SASL status based on the last SASL interaction
*/
private SASLAuthentication.Status saslStatus;
// DANIELE: Indicate if a stream:stream is arrived to complete compression // DANIELE: Indicate if a stream:stream is arrived to complete compression
private boolean waitingCompressionACK = false; private boolean waitingCompressionACK = false;
...@@ -113,7 +117,7 @@ public abstract class StanzaHandler { ...@@ -113,7 +117,7 @@ public abstract class StanzaHandler {
MXParser parser = (MXParser) factory.newPullParser(); MXParser parser = (MXParser) factory.newPullParser();
parser.setInput(new StringReader(stanza)); parser.setInput(new StringReader(stanza));
createSession(parser); createSession(parser);
} else if (startedSASL && session.getStatus() == Session.STATUS_AUTHENTICATED) { } else if (startedSASL && saslStatus == SASLAuthentication.Status.authenticated) {
startedSASL = false; startedSASL = false;
saslSuccessful(); saslSuccessful();
} else if (waitingCompressionACK) { } else if (waitingCompressionACK) {
...@@ -151,8 +155,11 @@ public abstract class StanzaHandler { ...@@ -151,8 +155,11 @@ public abstract class StanzaHandler {
} else if ("auth".equals(tag)) { } else if ("auth".equals(tag)) {
// User is trying to authenticate using SASL // User is trying to authenticate using SASL
startedSASL = true; startedSASL = true;
// Forward packet to the server // Process authentication stanza
process(doc); saslStatus = SASLAuthentication.handle(session, doc);
} else if (startedSASL && "response".equals(tag)) {
// User is responding to SASL challenge. Process response
saslStatus = SASLAuthentication.handle(session, doc);
} else if ("compress".equals(tag)) { } else if ("compress".equals(tag)) {
// Client is trying to initiate compression // Client is trying to initiate compression
if (compressClient(doc)) { if (compressClient(doc)) {
......
...@@ -13,8 +13,8 @@ package org.jivesoftware.wildfire.server; ...@@ -13,8 +13,8 @@ package org.jivesoftware.wildfire.server;
import org.jivesoftware.database.DbConnectionManager; import org.jivesoftware.database.DbConnectionManager;
import org.jivesoftware.util.JiveGlobals; import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.util.Log; import org.jivesoftware.util.Log;
import org.jivesoftware.wildfire.ConnectionManager;
import org.jivesoftware.wildfire.SessionManager; import org.jivesoftware.wildfire.SessionManager;
import org.jivesoftware.wildfire.net.SocketAcceptThread;
import org.jivesoftware.wildfire.server.RemoteServerConfiguration.Permission; import org.jivesoftware.wildfire.server.RemoteServerConfiguration.Permission;
import org.jivesoftware.wildfire.session.Session; import org.jivesoftware.wildfire.session.Session;
...@@ -283,15 +283,13 @@ public class RemoteServerManager { ...@@ -283,15 +283,13 @@ public class RemoteServerManager {
* @return the remote port to connect for the specified remote server. * @return the remote port to connect for the specified remote server.
*/ */
public static int getPortForServer(String domain) { public static int getPortForServer(String domain) {
int port = JiveGlobals.getIntProperty("xmpp.server.socket.remotePort", int port = JiveGlobals.getIntProperty("xmpp.server.socket.remotePort", ConnectionManager.DEFAULT_SERVER_PORT);
SocketAcceptThread.DEFAULT_SERVER_PORT);
RemoteServerConfiguration config = getConfiguration(domain); RemoteServerConfiguration config = getConfiguration(domain);
if (config != null) { if (config != null) {
port = config.getRemotePort(); port = config.getRemotePort();
if (port == 0) { if (port == 0) {
port = port = JiveGlobals
JiveGlobals.getIntProperty("xmpp.server.socket.remotePort", .getIntProperty("xmpp.server.socket.remotePort", ConnectionManager.DEFAULT_SERVER_PORT);
SocketAcceptThread.DEFAULT_SERVER_PORT);
} }
} }
return port; return port;
......
...@@ -8,16 +8,14 @@ ...@@ -8,16 +8,14 @@
- a copy of which is included in this distribution. - a copy of which is included in this distribution.
--%> --%>
<%@ page import="org.jivesoftware.util.*, <%@ page import="org.jivesoftware.util.JiveGlobals,
org.jivesoftware.admin.AdminPageBean, org.jivesoftware.util.ParamUtils,
java.util.*, org.jivesoftware.wildfire.ConnectionManager,
org.jivesoftware.wildfire.XMPPServer, org.jivesoftware.wildfire.XMPPServer,
java.net.InetAddress, java.net.InetAddress,
org.jivesoftware.util.JiveGlobals, java.util.HashMap"
org.jivesoftware.wildfire.net.SSLSocketAcceptThread,
org.jivesoftware.wildfire.net.SocketAcceptThread,
org.jivesoftware.wildfire.ConnectionManager"
%> %>
<%@ page import="java.util.Map" %>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %> <%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt" %> <%@ taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt" %>
...@@ -30,14 +28,14 @@ ...@@ -30,14 +28,14 @@
<% <%
// Get parameters // Get parameters
String serverName = ParamUtils.getParameter(request,"serverName"); String serverName = ParamUtils.getParameter(request, "serverName");
int port = ParamUtils.getIntParameter(request,"port",-1); int port = ParamUtils.getIntParameter(request, "port", -1);
int sslPort = ParamUtils.getIntParameter(request,"sslPort",-1); int sslPort = ParamUtils.getIntParameter(request, "sslPort", -1);
int embeddedPort = ParamUtils.getIntParameter(request,"embeddedPort",-1); int embeddedPort = ParamUtils.getIntParameter(request, "embeddedPort", -1);
int embeddedSecurePort = ParamUtils.getIntParameter(request,"embeddedSecurePort",-1); int embeddedSecurePort = ParamUtils.getIntParameter(request, "embeddedSecurePort", -1);
boolean sslEnabled = ParamUtils.getBooleanParameter(request,"sslEnabled"); boolean sslEnabled = ParamUtils.getBooleanParameter(request, "sslEnabled");
int componentPort = ParamUtils.getIntParameter(request,"componentPort",-1); int componentPort = ParamUtils.getIntParameter(request, "componentPort", -1);
int serverPort = ParamUtils.getIntParameter(request,"serverPort",-1); int serverPort = ParamUtils.getIntParameter(request, "serverPort", -1);
boolean save = request.getParameter("save") != null; boolean save = request.getParameter("save") != null;
boolean defaults = request.getParameter("defaults") != null; boolean defaults = request.getParameter("defaults") != null;
boolean cancel = request.getParameter("cancel") != null; boolean cancel = request.getParameter("cancel") != null;
...@@ -49,10 +47,10 @@ ...@@ -49,10 +47,10 @@
if (defaults) { if (defaults) {
serverName = InetAddress.getLocalHost().getHostName(); serverName = InetAddress.getLocalHost().getHostName();
port = SocketAcceptThread.DEFAULT_PORT; port = ConnectionManager.DEFAULT_PORT;
sslPort = SSLSocketAcceptThread.DEFAULT_PORT; sslPort = ConnectionManager.DEFAULT_SSL_PORT;
componentPort = SocketAcceptThread.DEFAULT_COMPONENT_PORT; componentPort = ConnectionManager.DEFAULT_COMPONENT_PORT;
serverPort = SocketAcceptThread.DEFAULT_SERVER_PORT; serverPort = ConnectionManager.DEFAULT_SERVER_PORT;
embeddedPort = 9090; embeddedPort = 9090;
embeddedSecurePort = 9091; embeddedSecurePort = 9091;
sslEnabled = true; sslEnabled = true;
...@@ -64,40 +62,39 @@ ...@@ -64,40 +62,39 @@
Map<String, String> errors = new HashMap<String, String>(); Map<String, String> errors = new HashMap<String, String>();
if (save) { if (save) {
if (serverName == null) { if (serverName == null) {
errors.put("serverName",""); errors.put("serverName", "");
} }
if (port < 1) { if (port < 1) {
errors.put("port",""); errors.put("port", "");
} }
if (sslPort < 1 && sslEnabled) { if (sslPort < 1 && sslEnabled) {
errors.put("sslPort",""); errors.put("sslPort", "");
} }
if (componentPort < 1) { if (componentPort < 1) {
errors.put("componentPort",""); errors.put("componentPort", "");
} }
if (serverPort < 1) { if (serverPort < 1) {
errors.put("serverPort",""); errors.put("serverPort", "");
} }
if (XMPPServer.getInstance().isStandAlone()) { if (XMPPServer.getInstance().isStandAlone()) {
if (embeddedPort < 1) { if (embeddedPort < 1) {
errors.put("embeddedPort",""); errors.put("embeddedPort", "");
} }
if (embeddedSecurePort < 1) { if (embeddedSecurePort < 1) {
errors.put("embeddedSecurePort",""); errors.put("embeddedSecurePort", "");
} }
if (embeddedPort > 0 && embeddedSecurePort > 0) { if (embeddedPort > 0 && embeddedSecurePort > 0) {
if (embeddedPort == embeddedSecurePort) { if (embeddedPort == embeddedSecurePort) {
errors.put("embeddedPortsEqual",""); errors.put("embeddedPortsEqual", "");
} }
} }
} } else {
else {
embeddedPort = -1; embeddedPort = -1;
embeddedSecurePort = -1; embeddedSecurePort = -1;
} }
if (port > 0 && sslPort > 0) { if (port > 0 && sslPort > 0) {
if (port == sslPort) { if (port == sslPort) {
errors.put("portsEqual",""); errors.put("portsEqual", "");
} }
} }
if (errors.size() == 0) { if (errors.size() == 0) {
...@@ -121,22 +118,26 @@ ...@@ -121,22 +118,26 @@
} }
if (needRestart) { if (needRestart) {
response.sendRedirect("server-props.jsp?success=true&restart=true"); response.sendRedirect("server-props.jsp?success=true&restart=true");
} } else {
else {
response.sendRedirect("server-props.jsp?success=true"); response.sendRedirect("server-props.jsp?success=true");
} }
return; return;
} }
} } else {
else {
serverName = server.getServerInfo().getName(); serverName = server.getServerInfo().getName();
sslEnabled = connectionManager.isClientSSLListenerEnabled(); sslEnabled = connectionManager.isClientSSLListenerEnabled();
port = connectionManager.getClientListenerPort(); port = connectionManager.getClientListenerPort();
sslPort = connectionManager.getClientSSLListenerPort(); sslPort = connectionManager.getClientSSLListenerPort();
componentPort = connectionManager.getComponentListenerPort(); componentPort = connectionManager.getComponentListenerPort();
serverPort = connectionManager.getServerListenerPort(); serverPort = connectionManager.getServerListenerPort();
try { embeddedPort = Integer.parseInt(JiveGlobals.getXMLProperty("adminConsole.port")); } catch (Exception ignored) {} try {
try { embeddedSecurePort = Integer.parseInt(JiveGlobals.getXMLProperty("adminConsole.securePort")); } catch (Exception ignored) {} embeddedPort = Integer.parseInt(JiveGlobals.getXMLProperty("adminConsole.port"));
} catch (Exception ignored) {
}
try {
embeddedSecurePort = Integer.parseInt(JiveGlobals.getXMLProperty("adminConsole.securePort"));
} catch (Exception ignored) {
}
} }
%> %>
...@@ -216,7 +217,7 @@ ...@@ -216,7 +217,7 @@
<br> <br>
<span class="jive-error-text"> <span class="jive-error-text">
<fmt:message key="server.props.valid_port" /> <fmt:message key="server.props.valid_port" />
<a href="#" onclick="document.editform.serverPort.value='<%=SocketAcceptThread.DEFAULT_SERVER_PORT%>';" <a href="#" onclick="document.editform.serverPort.value='<%=ConnectionManager.DEFAULT_SERVER_PORT%>';"
><fmt:message key="server.props.valid_port1" /></a>. ><fmt:message key="server.props.valid_port1" /></a>.
</span> </span>
<% } %> <% } %>
...@@ -233,7 +234,7 @@ ...@@ -233,7 +234,7 @@
<br> <br>
<span class="jive-error-text"> <span class="jive-error-text">
<fmt:message key="server.props.valid_port" /> <fmt:message key="server.props.valid_port" />
<a href="#" onclick="document.editform.componentPort.value='<%=SocketAcceptThread.DEFAULT_COMPONENT_PORT%>';" <a href="#" onclick="document.editform.componentPort.value='<%=ConnectionManager.DEFAULT_COMPONENT_PORT%>';"
><fmt:message key="server.props.valid_port1" /></a>. ><fmt:message key="server.props.valid_port1" /></a>.
</span> </span>
<% } %> <% } %>
...@@ -250,7 +251,7 @@ ...@@ -250,7 +251,7 @@
<br> <br>
<span class="jive-error-text"> <span class="jive-error-text">
<fmt:message key="server.props.valid_port" /> <fmt:message key="server.props.valid_port" />
<a href="#" onclick="document.editform.port.value='<%=SocketAcceptThread.DEFAULT_PORT%>';" <a href="#" onclick="document.editform.port.value='<%=ConnectionManager.DEFAULT_PORT%>';"
><fmt:message key="server.props.valid_port1" /></a>. ><fmt:message key="server.props.valid_port1" /></a>.
</span> </span>
<% } else if (errors.containsKey("portsEqual")) { %> <% } else if (errors.containsKey("portsEqual")) { %>
...@@ -297,7 +298,7 @@ ...@@ -297,7 +298,7 @@
<br> <br>
<span class="jive-error-text"> <span class="jive-error-text">
<fmt:message key="server.props.ssl_valid" /> <fmt:message key="server.props.ssl_valid" />
<a href="#" onclick="document.editform.sslPort.value='<%=SSLSocketAcceptThread.DEFAULT_PORT%>';" <a href="#" onclick="document.editform.sslPort.value='<%=ConnectionManager.DEFAULT_SSL_PORT%>';"
><fmt:message key="server.props.ssl_valid1" /></a>. ><fmt:message key="server.props.ssl_valid1" /></a>.
</span> </span>
<% } %> <% } %>
......
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