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 {
*/
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
* different permissions.
......
......@@ -77,20 +77,20 @@ public class IQAuthHandler extends IQHandler implements IQAuthInfo {
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 {
Session session = sessionManager.getSession(packet.getFrom());
IQ response = null;
try {
Element iq = packet.getElement();
Element query = iq.element("query");
Element queryResponse = probeResponse.createCopy();
if (IQ.Type.get == packet.getType()) {
String username = query.elementTextTrim("username");
probeResponse.element("username").setText(username);
queryResponse.element("username").setText(username);
response = IQ.createResultIQ(packet);
probeResponse.setParent(null);
response.setChildElement(probeResponse);
queryResponse.setParent(null);
response.setChildElement(queryResponse);
// 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.
// 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 {
{
JID jid = localServer.createJID(username, iq.elementTextTrim("resource"));
// 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 (sessionManager.isActiveRoute(jid)) {
......
......@@ -16,26 +16,22 @@ import org.jivesoftware.messenger.auth.UnauthorizedException;
import org.jivesoftware.messenger.container.BasicModule;
import org.jivesoftware.util.LocaleUtils;
import org.jivesoftware.util.Log;
import org.xmlpull.v1.XmlPullParserException;
import org.xmpp.packet.IQ;
import org.xmpp.packet.Packet;
import org.xmpp.packet.PacketError;
/**
* <p>Base class whose main responsibility is to handle IQ packets. Subclasses may only need to
* specify the IQHandlerInfo (i.e. name and namespace of the packets to handle) and actually handle
* the IQ packet.</p>
* <p/>
* Simplifies creation of simple TYPE_IQ message handlers.
* Base class whose main responsibility is to handle IQ packets. Subclasses may
* only need to specify the IQHandlerInfo (i.e. name and namespace of the packets
* to handle) and actually handle the IQ packet. Simplifies creation of simple
* TYPE_IQ message handlers.
*
* @author Gaston Dombiak
*/
public abstract class IQHandler extends BasicModule implements ChannelHandler {
protected PacketDeliverer deliverer;
protected IQRouter router;
private SessionManager sessionManager;
/**
......@@ -85,18 +81,15 @@ public abstract class IQHandler extends BasicModule implements ChannelHandler {
*
* @param packet the IQ packet to handle.
* @return the response to send back.
* @throws UnauthorizedException If the user that sent the packet is not authorized to request
* the given operation.
* @throws org.xmlpull.v1.XmlPullParserException
* If there was trouble reading the stream.
* @throws UnauthorizedException if the user that sent the packet is not
* authorized to request the given operation.
*/
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>
* <p/>
* <p>IQHandlers that aren't local server iq handlers (e.g. chatbots, transports, etc)
* return a null.</p>
* Returns the handler information to help generically handle IQ packets.
* IQHandlers that aren't local server iq handlers (e.g. chatbots, transports, etc)
* return <tt>null</tt>.
*
* @return The IQHandlerInfo for this handler
*/
......
......@@ -34,7 +34,6 @@ import org.xmpp.packet.IQ;
import org.xmpp.packet.JID;
import org.xmpp.packet.PacketError;
import org.xmpp.packet.Presence;
import org.xmlpull.v1.XmlPullParserException;
/**
* Implements the TYPE_IQ jabber:iq:register protocol (plain only). Clients
......@@ -63,6 +62,7 @@ import org.xmlpull.v1.XmlPullParserException;
*/
public class IQRegisterHandler extends IQHandler implements ServerFeaturesProvider {
private static boolean enabled;
private static Element probeResult;
private UserManager userManager;
......@@ -71,8 +71,6 @@ public class IQRegisterHandler extends IQHandler implements ServerFeaturesProvid
private SessionManager sessionManager;
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();
/**
......@@ -135,18 +133,11 @@ public class IQRegisterHandler extends IQHandler implements ServerFeaturesProvid
// Add the registration form to the probe result.
probeResult.add(registrationForm.asXMLElement());
}
// Check for the default case where no inband property is set and
// make the default true (allowing inband registration)
String inband = JiveGlobals.getProperty("register.inband");
if (inband == null || "".equals(inband)) {
setInbandRegEnabled(true);
}
else {
enabled = "true".equals(inband);
}
// See if in-band registration should be enabled (default is true).
enabled = JiveGlobals.getBooleanProperty("register.inband", true);
}
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
IQHandler delegate = getDelegate(packet.getTo());
// 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
Session session = sessionManager.getSession(packet.getFrom());
IQ reply = null;
// If inband registration is not allowed, return an error.
if (!enabled) {
reply = IQ.createResultIQ(packet);
reply.setError(PacketError.Condition.forbidden);
}
else if (IQ.Type.get.equals(packet.getType())) {
reply = IQ.createResultIQ(packet);
probeResult.setParent(null);
if (session.getStatus() == Session.STATUS_AUTHENTICATED) {
try {
User user = userManager.getUser(session.getUsername());
......@@ -192,10 +183,10 @@ public class IQRegisterHandler extends IQHandler implements ServerFeaturesProvid
reply.setChildElement(currentRegistration);
}
catch (UserNotFoundException e) {
reply.setChildElement(probeResult);
reply.setChildElement(probeResult.createCopy());
}
catch (UnauthorizedException e) {
reply.setChildElement(probeResult);
reply.setChildElement(probeResult.createCopy());
}
}
else {
......@@ -204,7 +195,7 @@ public class IQRegisterHandler extends IQHandler implements ServerFeaturesProvid
// incorrect value since we are setting a fake JID until the user actually
// authenticates with the server.
reply.setTo((JID) null);
reply.setChildElement(probeResult);
reply.setChildElement(probeResult.createCopy());
}
}
else if (IQ.Type.set.equals(packet.getType())) {
......
......@@ -36,7 +36,6 @@ public class IQVersionHandler extends IQHandler implements ServerFeaturesProvide
private static Element bodyElement;
private static Element versionElement;
private IQHandlerInfo info;
private XMPPServer localServer;
public IQVersionHandler() {
super("XMPP Server Version Handler");
......
......@@ -68,7 +68,7 @@ public class IQvCardHandler extends IQHandler {
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;
try {
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