Commit 7a12660f authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gato

More anonymous users work.

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@3506 b35dd754-fafc-0310-a699-88a17e54d16e
parent 1e6754aa
......@@ -19,6 +19,7 @@ import org.jivesoftware.wildfire.container.BasicModule;
import org.jivesoftware.wildfire.handler.IQHandler;
import org.jivesoftware.wildfire.privacy.PrivacyList;
import org.jivesoftware.wildfire.privacy.PrivacyListManager;
import org.jivesoftware.wildfire.user.UserManager;
import org.xmpp.packet.IQ;
import org.xmpp.packet.JID;
import org.xmpp.packet.PacketError;
......@@ -46,6 +47,7 @@ public class IQRouter extends BasicModule {
private Map<String, IQResultListener> resultListeners =
new ConcurrentHashMap<String, IQResultListener>();
private SessionManager sessionManager;
private UserManager userManager;
/**
* Creates a packet router.
......@@ -163,6 +165,7 @@ public class IQRouter extends BasicModule {
multicastRouter = server.getMulticastRouter();
iqHandlers.addAll(server.getIQHandlers());
sessionManager = server.getSessionManager();
userManager = server.getUserManager();
}
/**
......@@ -228,7 +231,8 @@ public class IQRouter extends BasicModule {
}
else {
// Check if communication to local users is allowed
if (recipientJID != null && recipientJID.getNode() != null) {
if (recipientJID != null &&
userManager.isRegisteredUser(recipientJID.getNode())) {
PrivacyList list = PrivacyListManager.getInstance()
.getDefaultPrivacyList(recipientJID.getNode());
if (list != null && list.shouldBlockPacket(packet)) {
......
......@@ -13,6 +13,7 @@ package org.jivesoftware.wildfire.handler;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.jivesoftware.util.Log;
import org.jivesoftware.wildfire.*;
import org.jivesoftware.wildfire.auth.UnauthorizedException;
import org.jivesoftware.wildfire.disco.*;
......@@ -20,7 +21,7 @@ import org.jivesoftware.wildfire.forms.DataForm;
import org.jivesoftware.wildfire.forms.FormField;
import org.jivesoftware.wildfire.forms.spi.XDataFormImpl;
import org.jivesoftware.wildfire.forms.spi.XFormFieldImpl;
import org.jivesoftware.util.Log;
import org.jivesoftware.wildfire.user.UserManager;
import org.xmpp.packet.IQ;
import org.xmpp.packet.JID;
......@@ -46,6 +47,7 @@ public class IQOfflineMessagesHandler extends IQHandler implements ServerFeature
private IQDiscoItemsHandler itemsHandler;
private SessionManager sessionManager;
private UserManager userManager;
private OfflineMessageStore messageStore;
public IQOfflineMessagesHandler() {
......@@ -154,7 +156,7 @@ public class IQOfflineMessagesHandler extends IQHandler implements ServerFeature
}
public boolean hasInfo(String name, String node, JID senderJID) {
return NAMESPACE.equals(node) && senderJID.getNode() != null;
return NAMESPACE.equals(node) && userManager.isRegisteredUser(senderJID.getNode());
}
public Iterator<Element> getItems(String name, String node, JID senderJID) {
......@@ -182,6 +184,7 @@ public class IQOfflineMessagesHandler extends IQHandler implements ServerFeature
itemsHandler = server.getIQDiscoItemsHandler();
messageStore = server.getOfflineMessageStore();
sessionManager = server.getSessionManager();
userManager = server.getUserManager();
}
public void start() throws IllegalStateException {
......
......@@ -14,6 +14,7 @@ package org.jivesoftware.wildfire.handler;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.QName;
import org.jivesoftware.util.Log;
import org.jivesoftware.wildfire.IQHandlerInfo;
import org.jivesoftware.wildfire.PacketException;
import org.jivesoftware.wildfire.XMPPServer;
......@@ -22,7 +23,6 @@ import org.jivesoftware.wildfire.user.User;
import org.jivesoftware.wildfire.user.UserManager;
import org.jivesoftware.wildfire.user.UserNotFoundException;
import org.jivesoftware.wildfire.vcard.VCardManager;
import org.jivesoftware.util.Log;
import org.xmpp.packet.IQ;
import org.xmpp.packet.JID;
import org.xmpp.packet.PacketError;
......@@ -100,7 +100,7 @@ public class IQvCardHandler extends IQHandler {
Element vcard = DocumentHelper.createElement(QName.get("vCard", "vcard-temp"));
result.setChildElement(vcard);
// Only try to get the vCard values of non-anonymous users
if (recipient != null && recipient.getNode() != null) {
if (recipient != null && userManager.isRegisteredUser(recipient.getNode())) {
User user = userManager.getUser(recipient.getNode());
VCardManager vManager = VCardManager.getInstance();
Element userVCard = vManager.getVCard(user.getUsername());
......
......@@ -11,15 +11,16 @@
package org.jivesoftware.wildfire.handler;
import org.jivesoftware.util.CacheManager;
import org.jivesoftware.util.LocaleUtils;
import org.jivesoftware.util.Log;
import org.jivesoftware.wildfire.*;
import org.jivesoftware.wildfire.container.BasicModule;
import org.jivesoftware.wildfire.roster.Roster;
import org.jivesoftware.wildfire.roster.RosterItem;
import org.jivesoftware.wildfire.user.UserAlreadyExistsException;
import org.jivesoftware.wildfire.user.UserManager;
import org.jivesoftware.wildfire.user.UserNotFoundException;
import org.jivesoftware.util.CacheManager;
import org.jivesoftware.util.LocaleUtils;
import org.jivesoftware.util.Log;
import org.xmpp.packet.JID;
import org.xmpp.packet.Packet;
import org.xmpp.packet.PacketError;
......@@ -78,6 +79,7 @@ public class PresenceSubscribeHandler extends BasicModule implements ChannelHand
private XMPPServer localServer;
private PacketDeliverer deliverer;
private PresenceManager presenceManager;
private UserManager userManager;
public PresenceSubscribeHandler() {
super("Presence subscription handler");
......@@ -181,8 +183,7 @@ public class PresenceSubscribeHandler extends BasicModule implements ChannelHand
private Roster getRoster(JID address) {
String username = null;
Roster roster = null;
if (localServer.isLocal(address) && address.getNode() != null &&
!"".equals(address.getNode())) {
if (localServer.isLocal(address) && userManager.isRegisteredUser(address.getNode())) {
username = address.getNode();
// Check for a cached roster:
roster = (Roster)CacheManager.getCache("username2roster").get(username);
......@@ -452,5 +453,6 @@ public class PresenceSubscribeHandler extends BasicModule implements ChannelHand
routingTable = server.getRoutingTable();
deliverer = server.getPacketDeliverer();
presenceManager = server.getPresenceManager();
userManager = server.getUserManager();
}
}
\ No newline at end of file
......@@ -50,6 +50,7 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager
private static final String LAST_ACTIVITY_PROP = "lastActivity";
private SessionManager sessionManager;
private UserManager userManager;
private XMPPServer server;
private PacketDeliverer deliverer;
private PresenceUpdateHandler presenceUpdateHandler;
......@@ -140,12 +141,12 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager
// THE SERVER and the presence belongs to a local user.
if (presence.getTo() == null && server.isLocal(presence.getFrom())) {
String username = presence.getFrom().getNode();
if (username == null || !UserManager.getInstance().isRegisteredUser(username)) {
if (username == null || !userManager.isRegisteredUser(username)) {
// Ignore anonymous users
return;
}
try {
User probeeUser = UserManager.getInstance().getUser(username);
User probeeUser = userManager.getUser(username);
probeeUser.getProperties().remove(LAST_PRESENCE_PROP);
}
catch (UserNotFoundException e) {
......@@ -159,12 +160,12 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager
// to a local user.
if (presence.getTo() == null && server.isLocal(presence.getFrom())) {
String username = presence.getFrom().getNode();
if (username == null || !UserManager.getInstance().isRegisteredUser(username)) {
if (username == null || !userManager.isRegisteredUser(username)) {
// Ignore anonymous users
return;
}
try {
User probeeUser = UserManager.getInstance().getUser(username);
User probeeUser = userManager.getUser(username);
if (!presence.getElement().elements().isEmpty()) {
// Save the last unavailable presence of this user if the presence contains any
// child element such as <status>
......@@ -225,7 +226,7 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager
public boolean canProbePresence(JID prober, String probee) throws UserNotFoundException {
// Check that the probee is a valid user
UserManager.getInstance().getUser(probee);
userManager.getUser(probee);
// Check for a cached roster:
Roster roster = (Roster)CacheManager.getCache("username2roster").get(probee);
if (roster == null) {
......@@ -251,7 +252,7 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager
if (server.isLocal(probee)) {
// If the probee is a local user then don't send a probe to the contact's server.
// But instead just send the contact's presence to the prober
if (probee.getNode() != null && !"".equals(probee.getNode())) {
if (userManager.isRegisteredUser(probee.getNode())) {
Collection<ClientSession> sessions =
sessionManager.getSessions(probee.getNode());
if (sessions.isEmpty()) {
......@@ -259,7 +260,7 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager
// presence which may contain particular information and send it to the
// prober
try {
User probeeUser = UserManager.getInstance().getUser(probee.getNode());
User probeeUser = userManager.getUser(probee.getNode());
String presenceXML = probeeUser.getProperties().get(LAST_PRESENCE_PROP);
if (presenceXML != null) {
try {
......@@ -353,7 +354,7 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager
}
public void sendUnavailableFromSessions(JID recipientJID, JID userJID) {
if (userJID.getNode() != null && !"".equals(userJID.getNode())) {
if (userManager.isRegisteredUser(userJID.getNode())) {
for (ClientSession session : sessionManager.getSessions(userJID.getNode())) {
// Do not send an unavailable presence if the user sent a direct available presence
if (presenceUpdateHandler.hasDirectPresence(session, recipientJID)) {
......@@ -382,6 +383,7 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager
this.server = server;
deliverer = server.getPacketDeliverer();
sessionManager = server.getSessionManager();
userManager = server.getUserManager();
presenceUpdateHandler = server.getPresenceUpdateHandler();
}
......
......@@ -251,6 +251,9 @@ public class UserManager implements IQResultListener {
* @return true if the specified JID belongs to a local registered user.
*/
public boolean isRegisteredUser(String username) {
if (username == null || "".equals(username)) {
return false;
}
// Look up in the cache
Boolean isRegistered = (Boolean) registeredUsersCache.get(username);
if (isRegistered == null) {
......
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