Commit efdb1618 authored by Daniel Henninger's avatar Daniel Henninger Committed by dhenninger

[JM-1500] Flash cross domain handler now behaves like a proper HTTP handler,...

[JM-1500] Flash cross domain handler now behaves like a proper HTTP handler, should solve a lot of flash related issues for things using port 5229.

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@10926 b35dd754-fafc-0310-a699-88a17e54d16e
parent 528119a6
...@@ -13,99 +13,117 @@ ...@@ -13,99 +13,117 @@
package org.jivesoftware.openfire; package org.jivesoftware.openfire;
import org.jivesoftware.openfire.container.BasicModule; import org.jivesoftware.openfire.container.BasicModule;
import org.jivesoftware.openfire.http.FlashCrossDomainServlet;
import org.jivesoftware.util.JiveGlobals; import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.util.Log; import org.jivesoftware.util.Log;
import org.mortbay.jetty.Connector;
import org.mortbay.jetty.Handler;
import org.mortbay.jetty.Server;
import org.mortbay.jetty.handler.ContextHandler;
import org.mortbay.jetty.handler.ContextHandlerCollection;
import org.mortbay.jetty.handler.DefaultHandler;
import org.mortbay.jetty.nio.SelectChannelConnector;
import org.mortbay.jetty.servlet.ServletHandler;
import java.io.IOException; /**
import java.io.PrintWriter; * Sets up the "legacy" flash cross domain servlet, served off port 5229.
import java.net.InetAddress; *
import java.net.ServerSocket; * @author Daniel Henninger
import java.net.Socket; *
*/
public class FlashCrossDomainHandler extends BasicModule { public class FlashCrossDomainHandler extends BasicModule {
private ServerSocket serverSocket;
public static String CROSS_DOMAIN_TEXT = "<?xml version=\"1.0\"?>" + private Server crossDomainServer;
"<!DOCTYPE cross-domain-policy SYSTEM \"http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd\">" + private Connector crossDomainConnector;
"<cross-domain-policy>" + private ContextHandlerCollection contexts;
"<allow-access-from domain=\"*\" to-ports=\""; private int servletPort = 5229;
public static String CROSS_DOMAIN_END_TEXT = "\" /></cross-domain-policy>";
public FlashCrossDomainHandler() { public FlashCrossDomainHandler() {
super("Flash CrossDomain Handler"); super("Flash CrossDomain Handler");
// Configure Jetty logging to a more reasonable default.
System.setProperty("org.mortbay.log.class", "org.jivesoftware.util.log.util.JettyLog");
// JSP 2.0 uses commons-logging, so also override that implementation.
System.setProperty("org.apache.commons.logging.LogFactory", "org.jivesoftware.util.log.util.CommonsLogFactory");
contexts = new ContextHandlerCollection();
}
public Integer getPort() {
if (crossDomainConnector != null) {
return crossDomainConnector.getLocalPort();
}
else {
return null;
}
} }
public void start() { public void start() {
Thread thread = new Thread(new Runnable() { configureCrossDomainServer(servletPort);
public void run() {
try {
startServer();
}
catch (Exception e) {
Log.error(e);
}
}
}, "Flash Cross Domain");
thread.start(); try {
crossDomainServer.start();
}
catch (Exception e) {
Log.error("Error starting cross domain service", e);
}
} }
public void stop() { public void stop() {
try { if (crossDomainServer != null) {
if (serverSocket != null) { try {
serverSocket.close(); crossDomainServer.stop();
}
catch (Exception e) {
Log.error("Error stoping cross domain service", e);
} }
}
catch (IOException e) {
Log.error(e);
} }
} }
public int getPort() { private String getBindInterface() {
return serverSocket != null ? serverSocket.getLocalPort() : 0; String interfaceName = JiveGlobals.getXMLProperty("network.interface");
String bindInterface = null;
if (interfaceName != null) {
if (interfaceName.trim().length() > 0) {
bindInterface = interfaceName;
}
}
return bindInterface;
} }
private void startServer() throws Exception { private void createConnector(int port) {
try { crossDomainConnector = null;
if (port > 0) {
SelectChannelConnector connector = new SelectChannelConnector();
// Listen on a specific network interface if it has been set. // Listen on a specific network interface if it has been set.
String interfaceName = JiveGlobals.getXMLProperty("network.interface"); connector.setHost(getBindInterface());
InetAddress bindInterface = null; connector.setPort(port);
int port = 5229; crossDomainConnector = connector;
if (interfaceName != null) {
if (interfaceName.trim().length() > 0) {
bindInterface = InetAddress.getByName(interfaceName);
}
}
serverSocket = new ServerSocket(port, -1, bindInterface);
Log.debug("Flash cross domain is listening on " + interfaceName + " on port " + port);
} }
catch (IOException e) { }
Log.error("Could not listen on port: 5229.", e);
private synchronized void configureCrossDomainServer(int port) {
crossDomainServer = new Server();
createConnector(port);
if (crossDomainConnector == null) {
crossDomainServer = null;
return; return;
} }
else {
crossDomainServer.addConnector(crossDomainConnector);
}
while (true) { createCrossDomainHandler(contexts, "/");
Socket clientSocket;
try {
clientSocket = serverSocket.accept();
// Validate that we have a license crossDomainServer.setHandlers(new Handler[]{contexts, new DefaultHandler()});
PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true); }
out.println(CROSS_DOMAIN_TEXT + private void createCrossDomainHandler(ContextHandlerCollection contexts, String crossPath) {
XMPPServer.getInstance().getConnectionManager().getClientListenerPort() + ServletHandler handler = new ServletHandler();
CROSS_DOMAIN_END_TEXT); handler.addServletWithMapping(FlashCrossDomainServlet.class, "/crossdomain.xml");
out.println("\n");
out.flush(); ContextHandler crossContextHandler = new ContextHandler(contexts, crossPath);
out.close(); crossContextHandler.setHandler(handler);
}
catch (IOException e) {
if (XMPPServer.getInstance().isShuttingDown()) {
break;
}
Log.error(e);
}
}
} }
} }
...@@ -28,14 +28,14 @@ import java.io.IOException; ...@@ -28,14 +28,14 @@ import java.io.IOException;
*/ */
public class FlashCrossDomainServlet extends HttpServlet { public class FlashCrossDomainServlet extends HttpServlet {
private static String CROSS_DOMAIN_TEXT = "<?xml version=\"1.0\"?>" + public static String CROSS_DOMAIN_TEXT = "<?xml version=\"1.0\"?>" +
"<!DOCTYPE cross-domain-policy SYSTEM \"http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd\">" + "<!DOCTYPE cross-domain-policy SYSTEM \"http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd\">" +
"<cross-domain-policy>" + "<cross-domain-policy>" +
"<site-control permitted-cross-domain-policies=\"all\"/>" + "<site-control permitted-cross-domain-policies=\"all\"/>" +
"<allow-access-from domain=\"*\" to-ports=\""; "<allow-access-from domain=\"*\" to-ports=\"";
private static String CROSS_DOMAIN_MIDDLE_TEXT = "\" secure=\""; public static String CROSS_DOMAIN_MIDDLE_TEXT = "\" secure=\"";
private static String CROSS_DOMAIN_END_TEXT = "\"/></cross-domain-policy>"; public static String CROSS_DOMAIN_END_TEXT = "\"/></cross-domain-policy>";
private static String CROSS_DOMAIN_SECURE_ENABLED = "httpbind.crossdomain.secure"; private static String CROSS_DOMAIN_SECURE_ENABLED = "httpbind.crossdomain.secure";
private static boolean CROSS_DOMAIN_SECURE_DEFAULT = true; private static boolean CROSS_DOMAIN_SECURE_DEFAULT = true;
......
...@@ -14,10 +14,10 @@ package org.jivesoftware.openfire.net; ...@@ -14,10 +14,10 @@ package org.jivesoftware.openfire.net;
import org.dom4j.Element; import org.dom4j.Element;
import org.dom4j.io.XMPPPacketReader; import org.dom4j.io.XMPPPacketReader;
import org.jivesoftware.openfire.Connection; import org.jivesoftware.openfire.Connection;
import org.jivesoftware.openfire.FlashCrossDomainHandler;
import org.jivesoftware.openfire.PacketRouter; import org.jivesoftware.openfire.PacketRouter;
import org.jivesoftware.openfire.XMPPServer; import org.jivesoftware.openfire.XMPPServer;
import org.jivesoftware.openfire.auth.UnauthorizedException; import org.jivesoftware.openfire.auth.UnauthorizedException;
import org.jivesoftware.openfire.http.FlashCrossDomainServlet;
import org.jivesoftware.openfire.session.LocalSession; import org.jivesoftware.openfire.session.LocalSession;
import org.jivesoftware.openfire.session.Session; import org.jivesoftware.openfire.session.Session;
import org.jivesoftware.util.JiveGlobals; import org.jivesoftware.util.JiveGlobals;
...@@ -95,9 +95,9 @@ public abstract class StanzaHandler { ...@@ -95,9 +95,9 @@ public abstract class StanzaHandler {
if (!initialStream) { if (!initialStream) {
// Allow requests for flash socket policy files directly on the client listener port // Allow requests for flash socket policy files directly on the client listener port
if (stanza.startsWith("<policy-file-request/>")) { if (stanza.startsWith("<policy-file-request/>")) {
String crossDomainText = FlashCrossDomainHandler.CROSS_DOMAIN_TEXT + String crossDomainText = FlashCrossDomainServlet.CROSS_DOMAIN_TEXT +
XMPPServer.getInstance().getConnectionManager().getClientListenerPort() + XMPPServer.getInstance().getConnectionManager().getClientListenerPort() +
FlashCrossDomainHandler.CROSS_DOMAIN_END_TEXT + '\0'; FlashCrossDomainServlet.CROSS_DOMAIN_END_TEXT + '\0';
connection.deliverRawText(crossDomainText); connection.deliverRawText(crossDomainText);
return; return;
} }
......
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