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