Commit 325ca793 authored by Matt Tucker's avatar Matt Tucker Committed by matt

Code cleanup, removed synchronization.


git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/trunk@677 b35dd754-fafc-0310-a699-88a17e54d16e
parent 64b5ec41
...@@ -65,11 +65,6 @@ public class Permissions implements Cacheable { ...@@ -65,11 +65,6 @@ public class Permissions implements Cacheable {
*/ */
public static final long SYSTEM_ADMIN = 0x800000000000000L; public static final long SYSTEM_ADMIN = 0x800000000000000L;
/**
* Permission to modify a queue.
*/
public static final long QUEUE_ADMIN = 0x1000000000000000L;
/** /**
* A long holding permission values. We use the bits in the number to extract up to 63 * A long holding permission values. We use the bits in the number to extract up to 63
* different permissions. * different permissions.
......
...@@ -77,20 +77,20 @@ public class IQAuthHandler extends IQHandler implements IQAuthInfo { ...@@ -77,20 +77,20 @@ public class IQAuthHandler extends IQHandler implements IQAuthInfo {
anonymousAllowed = "true".equals(JiveGlobals.getProperty("xmpp.auth.anonymous")); anonymousAllowed = "true".equals(JiveGlobals.getProperty("xmpp.auth.anonymous"));
} }
public synchronized IQ handleIQ(IQ packet) throws UnauthorizedException, PacketException { public IQ handleIQ(IQ packet) throws UnauthorizedException, PacketException {
try { try {
Session session = sessionManager.getSession(packet.getFrom()); Session session = sessionManager.getSession(packet.getFrom());
IQ response = null; IQ response = null;
try { try {
Element iq = packet.getElement(); Element iq = packet.getElement();
Element query = iq.element("query"); Element query = iq.element("query");
Element queryResponse = probeResponse.createCopy();
if (IQ.Type.get == packet.getType()) { if (IQ.Type.get == packet.getType()) {
String username = query.elementTextTrim("username"); String username = query.elementTextTrim("username");
probeResponse.element("username").setText(username); queryResponse.element("username").setText(username);
response = IQ.createResultIQ(packet); response = IQ.createResultIQ(packet);
probeResponse.setParent(null); queryResponse.setParent(null);
response.setChildElement(probeResponse); response.setChildElement(queryResponse);
// This is a workaround. Since we don't want to have an incorrect TO attribute // This is a workaround. Since we don't want to have an incorrect TO attribute
// value we need to clean up the TO attribute and send directly the response. // value we need to clean up the TO attribute and send directly the response.
// The TO attribute will contain an incorrect value since we are setting a fake // The TO attribute will contain an incorrect value since we are setting a fake
...@@ -152,7 +152,6 @@ public class IQAuthHandler extends IQHandler implements IQAuthInfo { ...@@ -152,7 +152,6 @@ public class IQAuthHandler extends IQHandler implements IQAuthInfo {
{ {
JID jid = localServer.createJID(username, iq.elementTextTrim("resource")); JID jid = localServer.createJID(username, iq.elementTextTrim("resource"));
// 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(jid)) { if (sessionManager.isActiveRoute(jid)) {
......
...@@ -16,26 +16,22 @@ import org.jivesoftware.messenger.auth.UnauthorizedException; ...@@ -16,26 +16,22 @@ import org.jivesoftware.messenger.auth.UnauthorizedException;
import org.jivesoftware.messenger.container.BasicModule; import org.jivesoftware.messenger.container.BasicModule;
import org.jivesoftware.util.LocaleUtils; import org.jivesoftware.util.LocaleUtils;
import org.jivesoftware.util.Log; import org.jivesoftware.util.Log;
import org.xmlpull.v1.XmlPullParserException;
import org.xmpp.packet.IQ; import org.xmpp.packet.IQ;
import org.xmpp.packet.Packet; import org.xmpp.packet.Packet;
import org.xmpp.packet.PacketError; import org.xmpp.packet.PacketError;
/** /**
* <p>Base class whose main responsibility is to handle IQ packets. Subclasses may only need to * Base class whose main responsibility is to handle IQ packets. Subclasses may
* specify the IQHandlerInfo (i.e. name and namespace of the packets to handle) and actually handle * only need to specify the IQHandlerInfo (i.e. name and namespace of the packets
* the IQ packet.</p> * to handle) and actually handle the IQ packet. Simplifies creation of simple
* <p/> * TYPE_IQ message handlers.
* Simplifies creation of simple TYPE_IQ message handlers.
* *
* @author Gaston Dombiak * @author Gaston Dombiak
*/ */
public abstract class IQHandler extends BasicModule implements ChannelHandler { public abstract class IQHandler extends BasicModule implements ChannelHandler {
protected PacketDeliverer deliverer; protected PacketDeliverer deliverer;
protected IQRouter router; protected IQRouter router;
private SessionManager sessionManager; private SessionManager sessionManager;
/** /**
...@@ -85,18 +81,15 @@ public abstract class IQHandler extends BasicModule implements ChannelHandler { ...@@ -85,18 +81,15 @@ public abstract class IQHandler extends BasicModule implements ChannelHandler {
* *
* @param packet the IQ packet to handle. * @param packet the IQ packet to handle.
* @return the response to send back. * @return the response to send back.
* @throws UnauthorizedException If the user that sent the packet is not authorized to request * @throws UnauthorizedException if the user that sent the packet is not
* the given operation. * authorized to request the given operation.
* @throws org.xmlpull.v1.XmlPullParserException
* If there was trouble reading the stream.
*/ */
public abstract IQ handleIQ(IQ packet) throws UnauthorizedException, XmlPullParserException; public abstract IQ handleIQ(IQ packet) throws UnauthorizedException;
/** /**
* <p>Obtain the handler information to help generically handle IQ packets.</p> * Returns the handler information to help generically handle IQ packets.
* <p/> * IQHandlers that aren't local server iq handlers (e.g. chatbots, transports, etc)
* <p>IQHandlers that aren't local server iq handlers (e.g. chatbots, transports, etc) * return <tt>null</tt>.
* return a null.</p>
* *
* @return The IQHandlerInfo for this handler * @return The IQHandlerInfo for this handler
*/ */
......
...@@ -34,7 +34,6 @@ import org.xmpp.packet.IQ; ...@@ -34,7 +34,6 @@ import org.xmpp.packet.IQ;
import org.xmpp.packet.JID; import org.xmpp.packet.JID;
import org.xmpp.packet.PacketError; import org.xmpp.packet.PacketError;
import org.xmpp.packet.Presence; import org.xmpp.packet.Presence;
import org.xmlpull.v1.XmlPullParserException;
/** /**
* Implements the TYPE_IQ jabber:iq:register protocol (plain only). Clients * Implements the TYPE_IQ jabber:iq:register protocol (plain only). Clients
...@@ -63,6 +62,7 @@ import org.xmlpull.v1.XmlPullParserException; ...@@ -63,6 +62,7 @@ import org.xmlpull.v1.XmlPullParserException;
*/ */
public class IQRegisterHandler extends IQHandler implements ServerFeaturesProvider { public class IQRegisterHandler extends IQHandler implements ServerFeaturesProvider {
private static boolean enabled;
private static Element probeResult; private static Element probeResult;
private UserManager userManager; private UserManager userManager;
...@@ -71,8 +71,6 @@ public class IQRegisterHandler extends IQHandler implements ServerFeaturesProvid ...@@ -71,8 +71,6 @@ public class IQRegisterHandler extends IQHandler implements ServerFeaturesProvid
private SessionManager sessionManager; private SessionManager sessionManager;
private IQHandlerInfo info; private IQHandlerInfo info;
// TODO: this value needs to be shared across all instances but not across the entire jvm...
private static boolean enabled;
private Map delegates = new HashMap(); private Map delegates = new HashMap();
/** /**
...@@ -135,18 +133,11 @@ public class IQRegisterHandler extends IQHandler implements ServerFeaturesProvid ...@@ -135,18 +133,11 @@ public class IQRegisterHandler extends IQHandler implements ServerFeaturesProvid
// Add the registration form to the probe result. // Add the registration form to the probe result.
probeResult.add(registrationForm.asXMLElement()); probeResult.add(registrationForm.asXMLElement());
} }
// Check for the default case where no inband property is set and // See if in-band registration should be enabled (default is true).
// make the default true (allowing inband registration) enabled = JiveGlobals.getBooleanProperty("register.inband", true);
String inband = JiveGlobals.getProperty("register.inband");
if (inband == null || "".equals(inband)) {
setInbandRegEnabled(true);
}
else {
enabled = "true".equals(inband);
}
} }
public synchronized IQ handleIQ(IQ packet) throws PacketException, UnauthorizedException, XmlPullParserException { public IQ handleIQ(IQ packet) throws PacketException, UnauthorizedException {
// Look for a delegate for this packet // Look for a delegate for this packet
IQHandler delegate = getDelegate(packet.getTo()); IQHandler delegate = getDelegate(packet.getTo());
// We assume that the registration packet was meant to the server if delegate is // We assume that the registration packet was meant to the server if delegate is
...@@ -158,13 +149,13 @@ public class IQRegisterHandler extends IQHandler implements ServerFeaturesProvid ...@@ -158,13 +149,13 @@ public class IQRegisterHandler extends IQHandler implements ServerFeaturesProvid
Session session = sessionManager.getSession(packet.getFrom()); Session session = sessionManager.getSession(packet.getFrom());
IQ reply = null; IQ reply = null;
// If inband registration is not allowed, return an error.
if (!enabled) { if (!enabled) {
reply = IQ.createResultIQ(packet); reply = IQ.createResultIQ(packet);
reply.setError(PacketError.Condition.forbidden); reply.setError(PacketError.Condition.forbidden);
} }
else if (IQ.Type.get.equals(packet.getType())) { else if (IQ.Type.get.equals(packet.getType())) {
reply = IQ.createResultIQ(packet); reply = IQ.createResultIQ(packet);
probeResult.setParent(null);
if (session.getStatus() == Session.STATUS_AUTHENTICATED) { if (session.getStatus() == Session.STATUS_AUTHENTICATED) {
try { try {
User user = userManager.getUser(session.getUsername()); User user = userManager.getUser(session.getUsername());
...@@ -192,10 +183,10 @@ public class IQRegisterHandler extends IQHandler implements ServerFeaturesProvid ...@@ -192,10 +183,10 @@ public class IQRegisterHandler extends IQHandler implements ServerFeaturesProvid
reply.setChildElement(currentRegistration); reply.setChildElement(currentRegistration);
} }
catch (UserNotFoundException e) { catch (UserNotFoundException e) {
reply.setChildElement(probeResult); reply.setChildElement(probeResult.createCopy());
} }
catch (UnauthorizedException e) { catch (UnauthorizedException e) {
reply.setChildElement(probeResult); reply.setChildElement(probeResult.createCopy());
} }
} }
else { else {
...@@ -204,7 +195,7 @@ public class IQRegisterHandler extends IQHandler implements ServerFeaturesProvid ...@@ -204,7 +195,7 @@ public class IQRegisterHandler extends IQHandler implements ServerFeaturesProvid
// incorrect value since we are setting a fake JID until the user actually // incorrect value since we are setting a fake JID until the user actually
// authenticates with the server. // authenticates with the server.
reply.setTo((JID) null); reply.setTo((JID) null);
reply.setChildElement(probeResult); reply.setChildElement(probeResult.createCopy());
} }
} }
else if (IQ.Type.set.equals(packet.getType())) { else if (IQ.Type.set.equals(packet.getType())) {
......
...@@ -36,7 +36,6 @@ public class IQVersionHandler extends IQHandler implements ServerFeaturesProvide ...@@ -36,7 +36,6 @@ public class IQVersionHandler extends IQHandler implements ServerFeaturesProvide
private static Element bodyElement; private static Element bodyElement;
private static Element versionElement; private static Element versionElement;
private IQHandlerInfo info; private IQHandlerInfo info;
private XMPPServer localServer;
public IQVersionHandler() { public IQVersionHandler() {
super("XMPP Server Version Handler"); super("XMPP Server Version Handler");
......
...@@ -68,7 +68,7 @@ public class IQvCardHandler extends IQHandler { ...@@ -68,7 +68,7 @@ public class IQvCardHandler extends IQHandler {
info = new IQHandlerInfo("vCard", "vcard-temp"); info = new IQHandlerInfo("vCard", "vcard-temp");
} }
public synchronized IQ handleIQ(IQ packet) throws UnauthorizedException, PacketException { public IQ handleIQ(IQ packet) throws UnauthorizedException, PacketException {
IQ result = null; IQ result = null;
try { try {
JID recipient = packet.getTo(); JID recipient = packet.getTo();
......
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