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

Refactoring wortk. JM-924

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@6541 b35dd754-fafc-0310-a699-88a17e54d16e
parent 35ca2208
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* $Revision: 3135 $ * $Revision: 3135 $
* $Date: 2005-12-01 02:03:04 -0300 (Thu, 01 Dec 2005) $ * $Date: 2005-12-01 02:03:04 -0300 (Thu, 01 Dec 2005) $
* *
* Copyright (C) 2005 Jive Software. All rights reserved. * Copyright (C) 2007 Jive Software. All rights reserved.
* *
* This software is published under the terms of the GNU Public License (GPL), * This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution. * a copy of which is included in this distribution.
...@@ -17,11 +17,16 @@ import org.jivesoftware.util.Log; ...@@ -17,11 +17,16 @@ import org.jivesoftware.util.Log;
import org.jivesoftware.wildfire.auth.UnauthorizedException; import org.jivesoftware.wildfire.auth.UnauthorizedException;
import org.jivesoftware.wildfire.container.BasicModule; import org.jivesoftware.wildfire.container.BasicModule;
import org.jivesoftware.wildfire.handler.IQHandler; import org.jivesoftware.wildfire.handler.IQHandler;
import org.jivesoftware.wildfire.interceptor.InterceptorManager;
import org.jivesoftware.wildfire.interceptor.PacketRejectedException;
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.session.ClientSession;
import org.jivesoftware.wildfire.session.Session;
import org.jivesoftware.wildfire.user.UserManager; import org.jivesoftware.wildfire.user.UserManager;
import org.xmpp.packet.IQ; import org.xmpp.packet.IQ;
import org.xmpp.packet.JID; import org.xmpp.packet.JID;
import org.xmpp.packet.Message;
import org.xmpp.packet.PacketError; import org.xmpp.packet.PacketError;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -73,33 +78,60 @@ public class IQRouter extends BasicModule { ...@@ -73,33 +78,60 @@ public class IQRouter extends BasicModule {
if (packet == null) { if (packet == null) {
throw new NullPointerException(); throw new NullPointerException();
} }
Session session = sessionManager.getSession(packet.getFrom()); ClientSession session = sessionManager.getSession(packet.getFrom());
JID to = packet.getTo(); try {
if (session != null && to != null && session.getStatus() == Session.STATUS_CONNECTED && // Invoke the interceptors before we process the read packet
!serverName.equals(to.toString())) { InterceptorManager.getInstance().invokeInterceptors(packet, session, true, false);
// User is requesting this server to authenticate for another server. Return JID to = packet.getTo();
// a bad-request error if (session != null && to != null && session.getStatus() == Session.STATUS_CONNECTED &&
IQ reply = IQ.createResultIQ(packet); !serverName.equals(to.toString())) {
reply.setChildElement(packet.getChildElement().createCopy()); // User is requesting this server to authenticate for another server. Return
reply.setError(PacketError.Condition.bad_request); // a bad-request error
sessionManager.getSession(packet.getFrom()).process(reply); IQ reply = IQ.createResultIQ(packet);
Log.warn("User tried to authenticate with this server using an unknown receipient: " + reply.setChildElement(packet.getChildElement().createCopy());
packet); reply.setError(PacketError.Condition.bad_request);
} sessionManager.getSession(packet.getFrom()).process(reply);
else if (session == null || session.getStatus() == Session.STATUS_AUTHENTICATED || ( Log.warn("User tried to authenticate with this server using an unknown receipient: " +
isLocalServer(to) && ( packet);
"jabber:iq:auth".equals(packet.getChildElement().getNamespaceURI()) || }
"jabber:iq:register" else if (session == null || session.getStatus() == Session.STATUS_AUTHENTICATED || (
.equals(packet.getChildElement().getNamespaceURI()) || isLocalServer(to) && (
"urn:ietf:params:xml:ns:xmpp-bind" "jabber:iq:auth".equals(packet.getChildElement().getNamespaceURI()) ||
.equals(packet.getChildElement().getNamespaceURI())))) { "jabber:iq:register"
handle(packet); .equals(packet.getChildElement().getNamespaceURI()) ||
"urn:ietf:params:xml:ns:xmpp-bind"
.equals(packet.getChildElement().getNamespaceURI())))) {
handle(packet);
}
else {
IQ reply = IQ.createResultIQ(packet);
reply.setChildElement(packet.getChildElement().createCopy());
reply.setError(PacketError.Condition.not_authorized);
sessionManager.getSession(packet.getFrom()).process(reply);
}
// Invoke the interceptors after we have processed the read packet
InterceptorManager.getInstance().invokeInterceptors(packet, session, true, true);
} }
else { catch (PacketRejectedException e) {
IQ reply = IQ.createResultIQ(packet); if (session != null) {
reply.setChildElement(packet.getChildElement().createCopy()); // An interceptor rejected this packet so answer a not_allowed error
reply.setError(PacketError.Condition.not_authorized); IQ reply = new IQ();
sessionManager.getSession(packet.getFrom()).process(reply); reply.setChildElement(packet.getChildElement().createCopy());
reply.setID(packet.getID());
reply.setTo(session.getAddress());
reply.setFrom(packet.getTo());
reply.setError(PacketError.Condition.not_allowed);
session.process(reply);
// Check if a message notifying the rejection should be sent
if (e.getRejectionMessage() != null && e.getRejectionMessage().trim().length() > 0) {
// A message for the rejection will be sent to the sender of the rejected packet
Message notification = new Message();
notification.setTo(session.getAddress());
notification.setFrom(packet.getTo());
notification.setBody(e.getRejectionMessage());
session.process(notification);
}
}
} }
} }
...@@ -279,7 +311,7 @@ public class IQRouter extends BasicModule { ...@@ -279,7 +311,7 @@ public class IQRouter extends BasicModule {
if (XMPPServer.getInstance().isLocal(recipientJID)) { if (XMPPServer.getInstance().isLocal(recipientJID)) {
ClientSession session = sessionManager.getBestRoute(recipientJID); ClientSession session = sessionManager.getBestRoute(recipientJID);
if (session != null) { if (session != null) {
if (!session.shouldBlockPacket(packet)) { if (session.canProcess(packet)) {
session.process(packet); session.process(packet);
handlerFound = true; handlerFound = true;
} }
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* $Revision: 3007 $ * $Revision: 3007 $
* $Date: 2005-10-31 13:29:25 -0300 (Mon, 31 Oct 2005) $ * $Date: 2005-10-31 13:29:25 -0300 (Mon, 31 Oct 2005) $
* *
* Copyright (C) 2004 Jive Software. All rights reserved. * Copyright (C) 2007 Jive Software. All rights reserved.
* *
* This software is published under the terms of the GNU Public License (GPL), * This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution. * a copy of which is included in this distribution.
...@@ -11,10 +11,13 @@ ...@@ -11,10 +11,13 @@
package org.jivesoftware.wildfire; package org.jivesoftware.wildfire;
import org.jivesoftware.wildfire.auth.UnauthorizedException;
import org.jivesoftware.wildfire.container.BasicModule;
import org.jivesoftware.util.JiveGlobals; import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.util.Log; import org.jivesoftware.util.Log;
import org.jivesoftware.wildfire.container.BasicModule;
import org.jivesoftware.wildfire.interceptor.InterceptorManager;
import org.jivesoftware.wildfire.interceptor.PacketRejectedException;
import org.jivesoftware.wildfire.session.ClientSession;
import org.jivesoftware.wildfire.session.Session;
import org.xmpp.packet.JID; import org.xmpp.packet.JID;
import org.xmpp.packet.Message; import org.xmpp.packet.Message;
import org.xmpp.packet.PacketError; import org.xmpp.packet.PacketError;
...@@ -63,51 +66,65 @@ public class MessageRouter extends BasicModule { ...@@ -63,51 +66,65 @@ public class MessageRouter extends BasicModule {
if (packet == null) { if (packet == null) {
throw new NullPointerException(); throw new NullPointerException();
} }
Session session = sessionManager.getSession(packet.getFrom()); ClientSession session = sessionManager.getSession(packet.getFrom());
if (session == null try {
|| session.getStatus() == Session.STATUS_AUTHENTICATED) // Invoke the interceptors before we process the read packet
{ InterceptorManager.getInstance().invokeInterceptors(packet, session, true, false);
JID recipientJID = packet.getTo(); if (session == null
|| session.getStatus() == Session.STATUS_AUTHENTICATED)
{
JID recipientJID = packet.getTo();
// Check if the message was sent to the server hostname // Check if the message was sent to the server hostname
if (recipientJID != null && recipientJID.getNode() == null && if (recipientJID != null && recipientJID.getNode() == null &&
recipientJID.getResource() == null && recipientJID.getResource() == null &&
serverName.equals(recipientJID.getDomain())) { serverName.equals(recipientJID.getDomain())) {
if (packet.getElement().element("addresses") != null) { if (packet.getElement().element("addresses") != null) {
// Message includes multicast processing instructions. Ask the multicastRouter // Message includes multicast processing instructions. Ask the multicastRouter
// to route this packet // to route this packet
multicastRouter.route(packet); multicastRouter.route(packet);
}
else {
// Message was sent to the server hostname so forward it to a configurable
// set of JID's (probably admin users)
sendMessageToAdmins(packet);
}
return;
} }
else {
// Message was sent to the server hostname so forward it to a configurable
// set of JID's (probably admin users)
sendMessageToAdmins(packet);
}
return;
}
try {
routingTable.getBestRoute(recipientJID).process(packet);
}
catch (Exception e) {
try { try {
messageStrategy.storeOffline(packet); routingTable.getBestRoute(recipientJID).process(packet);
} }
catch (Exception e1) { catch (Exception e) {
Log.error(e1); try {
messageStrategy.storeOffline(packet);
}
catch (Exception e1) {
Log.error(e1);
}
} }
}
} }
else { else {
packet.setTo(session.getAddress()); packet.setTo(session.getAddress());
packet.setFrom((JID)null); packet.setFrom((JID)null);
packet.setError(PacketError.Condition.not_authorized); packet.setError(PacketError.Condition.not_authorized);
try {
session.process(packet); session.process(packet);
} }
catch (UnauthorizedException ue) { // Invoke the interceptors after we have processed the read packet
Log.error(ue); InterceptorManager.getInstance().invokeInterceptors(packet, session, true, true);
} catch (PacketRejectedException e) {
// An interceptor rejected this packet
if (session != null && e.getRejectionMessage() != null && e.getRejectionMessage().trim().length() > 0) {
// A message for the rejection will be sent to the sender of the rejected packet
Message reply = new Message();
reply.setID(packet.getID());
reply.setTo(session.getAddress());
reply.setFrom(packet.getTo());
reply.setType(packet.getType());
reply.setThread(packet.getThread());
reply.setBody(e.getRejectionMessage());
session.process(reply);
} }
} }
} }
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* $Revision: $ * $Revision: $
* $Date: $ * $Date: $
* *
* Copyright (C) 2006 Jive Software. All rights reserved. * Copyright (C) 2007 Jive Software. All rights reserved.
* *
* This software is published under the terms of the GNU Public License (GPL), * This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution. * a copy of which is included in this distribution.
...@@ -44,7 +44,7 @@ public class Route extends Packet { ...@@ -44,7 +44,7 @@ public class Route extends Packet {
* @param element the route Element. * @param element the route Element.
*/ */
public Route(Element element) { public Route(Element element) {
super(element); super(element, true);
} }
public Route(Route route) { public Route(Route route) {
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* $Revision: 3174 $ * $Revision: 3174 $
* $Date: 2005-12-08 17:41:00 -0300 (Thu, 08 Dec 2005) $ * $Date: 2005-12-08 17:41:00 -0300 (Thu, 08 Dec 2005) $
* *
* Copyright (C) 2004 Jive Software. All rights reserved. * Copyright (C) 2007 Jive Software. All rights reserved.
* *
* This software is published under the terms of the GNU Public License (GPL), * This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution. * a copy of which is included in this distribution.
...@@ -13,10 +13,10 @@ package org.jivesoftware.wildfire.net; ...@@ -13,10 +13,10 @@ package org.jivesoftware.wildfire.net;
import org.dom4j.Element; import org.dom4j.Element;
import org.jivesoftware.util.JiveGlobals; import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.wildfire.ClientSession;
import org.jivesoftware.wildfire.PacketRouter; import org.jivesoftware.wildfire.PacketRouter;
import org.jivesoftware.wildfire.RoutingTable; import org.jivesoftware.wildfire.RoutingTable;
import org.jivesoftware.wildfire.auth.UnauthorizedException; import org.jivesoftware.wildfire.auth.UnauthorizedException;
import org.jivesoftware.wildfire.session.ClientSession;
import org.xmlpull.v1.XmlPullParserException; import org.xmlpull.v1.XmlPullParserException;
import org.xmpp.packet.IQ; import org.xmpp.packet.IQ;
import org.xmpp.packet.Message; import org.xmpp.packet.Message;
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* $Revision: 3174 $ * $Revision: 3174 $
* $Date: 2005-12-08 17:41:00 -0300 (Thu, 08 Dec 2005) $ * $Date: 2005-12-08 17:41:00 -0300 (Thu, 08 Dec 2005) $
* *
* Copyright (C) 2004 Jive Software. All rights reserved. * Copyright (C) 2007 Jive Software. All rights reserved.
* *
* This software is published under the terms of the GNU Public License (GPL), * This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution. * a copy of which is included in this distribution.
...@@ -16,8 +16,8 @@ import org.jivesoftware.util.Log; ...@@ -16,8 +16,8 @@ import org.jivesoftware.util.Log;
import org.jivesoftware.wildfire.PacketRouter; import org.jivesoftware.wildfire.PacketRouter;
import org.jivesoftware.wildfire.RoutingTable; import org.jivesoftware.wildfire.RoutingTable;
import org.jivesoftware.wildfire.auth.UnauthorizedException; import org.jivesoftware.wildfire.auth.UnauthorizedException;
import org.jivesoftware.wildfire.component.ComponentSession;
import org.jivesoftware.wildfire.component.InternalComponentManager; import org.jivesoftware.wildfire.component.InternalComponentManager;
import org.jivesoftware.wildfire.session.ComponentSession;
import org.xmlpull.v1.XmlPullParserException; import org.xmlpull.v1.XmlPullParserException;
import org.xmpp.component.ComponentException; import org.xmpp.component.ComponentException;
import org.xmpp.packet.PacketError; import org.xmpp.packet.PacketError;
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* $Revision: $ * $Revision: $
* $Date: $ * $Date: $
* *
* Copyright (C) 2005 Jive Software. All rights reserved. * Copyright (C) 2007 Jive Software. All rights reserved.
* *
* This software is published under the terms of the GNU Public License (GPL), * This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution. * a copy of which is included in this distribution.
...@@ -19,13 +19,13 @@ import org.jivesoftware.util.CertificateManager; ...@@ -19,13 +19,13 @@ import org.jivesoftware.util.CertificateManager;
import org.jivesoftware.util.JiveGlobals; import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.util.Log; import org.jivesoftware.util.Log;
import org.jivesoftware.util.StringUtils; import org.jivesoftware.util.StringUtils;
import org.jivesoftware.wildfire.ClientSession;
import org.jivesoftware.wildfire.Session;
import org.jivesoftware.wildfire.XMPPServer; import org.jivesoftware.wildfire.XMPPServer;
import org.jivesoftware.wildfire.auth.AuthFactory; import org.jivesoftware.wildfire.auth.AuthFactory;
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.server.IncomingServerSession; import org.jivesoftware.wildfire.session.ClientSession;
import org.jivesoftware.wildfire.session.IncomingServerSession;
import org.jivesoftware.wildfire.session.Session;
import org.xmpp.packet.JID; import org.xmpp.packet.JID;
import javax.net.ssl.SSLPeerUnverifiedException; import javax.net.ssl.SSLPeerUnverifiedException;
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* $Revision: 3174 $ * $Revision: 3174 $
* $Date: 2005-12-08 17:41:00 -0300 (Thu, 08 Dec 2005) $ * $Date: 2005-12-08 17:41:00 -0300 (Thu, 08 Dec 2005) $
* *
* Copyright (C) 2004 Jive Software. All rights reserved. * Copyright (C) 2007 Jive Software. All rights reserved.
* *
* This software is published under the terms of the GNU Public License (GPL), * This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution. * a copy of which is included in this distribution.
...@@ -18,7 +18,7 @@ import org.jivesoftware.wildfire.PacketRouter; ...@@ -18,7 +18,7 @@ import org.jivesoftware.wildfire.PacketRouter;
import org.jivesoftware.wildfire.RoutingTable; import org.jivesoftware.wildfire.RoutingTable;
import org.jivesoftware.wildfire.auth.UnauthorizedException; import org.jivesoftware.wildfire.auth.UnauthorizedException;
import org.jivesoftware.wildfire.interceptor.PacketRejectedException; import org.jivesoftware.wildfire.interceptor.PacketRejectedException;
import org.jivesoftware.wildfire.server.IncomingServerSession; import org.jivesoftware.wildfire.session.IncomingServerSession;
import org.xmlpull.v1.XmlPullParserException; import org.xmlpull.v1.XmlPullParserException;
import org.xmpp.packet.*; import org.xmpp.packet.*;
......
...@@ -29,7 +29,7 @@ import java.util.List; ...@@ -29,7 +29,7 @@ import java.util.List;
* *
* @author Gaston Dombiak * @author Gaston Dombiak
*/ */
class ServerTrustManager implements X509TrustManager { public class ServerTrustManager implements X509TrustManager {
/** /**
* KeyStore that holds the trusted CA * KeyStore that holds the trusted CA
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* $Revision: 1583 $ * $Revision: 1583 $
* $Date: 2005-07-03 17:55:39 -0300 (Sun, 03 Jul 2005) $ * $Date: 2005-07-03 17:55:39 -0300 (Sun, 03 Jul 2005) $
* *
* Copyright (C) 2004 Jive Software. All rights reserved. * Copyright (C) 2007 Jive Software. All rights reserved.
* *
* This software is published under the terms of the GNU Public License (GPL), * This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution. * a copy of which is included in this distribution.
...@@ -73,13 +73,7 @@ public class SocketAcceptThread extends Thread { ...@@ -73,13 +73,7 @@ public class SocketAcceptThread extends Thread {
} }
this.serverPort = serverPort; this.serverPort = serverPort;
// Set the blocking reading mode to use // Set the blocking reading mode to use
boolean useBlockingMode = JiveGlobals.getBooleanProperty("xmpp.socket.blocking", true); acceptingMode = new BlockingAcceptingMode(connManager, serverPort, bindInterface);
if (useBlockingMode) {
acceptingMode = new BlockingAcceptingMode(connManager, serverPort, bindInterface);
}
else {
acceptingMode = new NonBlockingAcceptingMode(connManager, serverPort, bindInterface);
}
} }
/** /**
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* $Revision: $ * $Revision: $
* $Date: $ * $Date: $
* *
* Copyright (C) 2006 Jive Software. All rights reserved. * Copyright (C) 2007 Jive Software. All rights reserved.
* *
* This software is published under the terms of the GNU Public License (GPL), * This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution. * a copy of which is included in this distribution.
...@@ -18,7 +18,7 @@ import java.io.IOException; ...@@ -18,7 +18,7 @@ import java.io.IOException;
import java.net.ServerSocket; import java.net.ServerSocket;
/** /**
* Abstract class for {@link BlockingAcceptingMode} and {@link NonBlockingAcceptingMode}. * Abstract class for {@link BlockingAcceptingMode}.
* *
* @author Gaston Dombiak * @author Gaston Dombiak
*/ */
......
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