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

Implement anonymous users as defined in JEP-175.

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@3486 b35dd754-fafc-0310-a699-88a17e54d16e
parent 174fc7eb
...@@ -523,12 +523,14 @@ public class ClientSession extends Session { ...@@ -523,12 +523,14 @@ public class ClientSession extends Session {
} }
/** /**
* <p>Initialize the session as an anonymous login.</p> * Initialize the session as an anonymous login. This automatically upgrades the session's
* <p>This automatically upgrades the session's * status to authenticated and enables many features that are not available until
* status to authenticated and enables many features that are not * authenticated (obtaining managers for example).<p>
* available until authenticated (obtaining managers for example).</p>
*/ */
public void setAnonymousAuth() { public void setAnonymousAuth() {
// Anonymous users have a full JID. Use the random resource as the JID's node
String resource = getAddress().getResource();
setAddress(new JID(resource, getServerName(), resource));
sessionManager.addAnonymousSession(this); sessionManager.addAnonymousSession(this);
setStatus(Session.STATUS_AUTHENTICATED); setStatus(Session.STATUS_AUTHENTICATED);
} }
......
...@@ -20,6 +20,8 @@ import org.jivesoftware.wildfire.container.BasicModule; ...@@ -20,6 +20,8 @@ import org.jivesoftware.wildfire.container.BasicModule;
import org.jivesoftware.wildfire.event.UserEventDispatcher; import org.jivesoftware.wildfire.event.UserEventDispatcher;
import org.jivesoftware.wildfire.event.UserEventListener; import org.jivesoftware.wildfire.event.UserEventListener;
import org.jivesoftware.wildfire.user.User; import org.jivesoftware.wildfire.user.User;
import org.jivesoftware.wildfire.user.UserManager;
import org.xmpp.packet.JID;
import org.xmpp.packet.Message; import org.xmpp.packet.Message;
import java.io.StringReader; import java.io.StringReader;
...@@ -93,13 +95,14 @@ public class OfflineMessageStore extends BasicModule implements UserEventListene ...@@ -93,13 +95,14 @@ public class OfflineMessageStore extends BasicModule implements UserEventListene
if (message == null) { if (message == null) {
return; return;
} }
String username = message.getTo().getNode(); JID recipient = message.getTo();
String username = recipient.getNode();
// If the username is null (such as when an anonymous user), don't store. // If the username is null (such as when an anonymous user), don't store.
if (username == null) { if (username == null || !UserManager.getInstance().isRegisteredUser(recipient)) {
return; return;
} }
else if (!XMPPServer.getInstance().getServerInfo().getName().equals(message.getTo() else
.getDomain())) { if (!XMPPServer.getInstance().getServerInfo().getName().equals(recipient.getDomain())) {
// Do not store messages sent to users of remote servers // Do not store messages sent to users of remote servers
return; return;
} }
......
...@@ -11,11 +11,12 @@ ...@@ -11,11 +11,12 @@
package org.jivesoftware.wildfire; package org.jivesoftware.wildfire;
import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.util.Log;
import org.jivesoftware.wildfire.container.BasicModule; import org.jivesoftware.wildfire.container.BasicModule;
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.util.JiveGlobals; import org.jivesoftware.wildfire.user.UserManager;
import org.jivesoftware.util.Log;
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;
...@@ -64,7 +65,8 @@ public class OfflineMessageStrategy extends BasicModule { ...@@ -64,7 +65,8 @@ public class OfflineMessageStrategy extends BasicModule {
// Do nothing if the message was sent to the server itself or to an anonymous user // Do nothing if the message was sent to the server itself or to an anonymous user
JID recipientJID = message.getTo(); JID recipientJID = message.getTo();
if (recipientJID == null || serverAddress.equals(recipientJID) || if (recipientJID == null || serverAddress.equals(recipientJID) ||
recipientJID.getNode() == null) { recipientJID.getNode() == null ||
!UserManager.getInstance().isRegisteredUser(recipientJID.getNode())) {
return; return;
} }
// Do not store messages of type groupchat, error or headline as specified in JEP-160 // Do not store messages of type groupchat, error or headline as specified in JEP-160
......
...@@ -680,7 +680,8 @@ public class SessionManager extends BasicModule { ...@@ -680,7 +680,8 @@ public class SessionManager extends BasicModule {
* @param priority The new priority for the session * @param priority The new priority for the session
*/ */
public void changePriority(JID sender, int priority) { public void changePriority(JID sender, int priority) {
if (sender.getNode() == null) { if (sender.getNode() == null ||
!UserManager.getInstance().isRegisteredUser(sender.getNode())) {
// Do nothing if the session belongs to an anonymous user // Do nothing if the session belongs to an anonymous user
return; return;
} }
...@@ -719,14 +720,13 @@ public class SessionManager extends BasicModule { ...@@ -719,14 +720,13 @@ public class SessionManager extends BasicModule {
ClientSession session = null; ClientSession session = null;
String resource = recipient.getResource(); String resource = recipient.getResource();
String username = recipient.getNode(); String username = recipient.getNode();
if (username == null || "".equals(username)) { if (resource != null &&
if (resource != null) { (username == null || !UserManager.getInstance().isRegisteredUser(username))) {
session = anonymousSessions.get(resource); session = anonymousSessions.get(resource);
if (session == null){ if (session == null){
session = getSession(recipient); session = getSession(recipient);
} }
} }
}
else { else {
synchronized (username.intern()) { synchronized (username.intern()) {
SessionMap sessionMap = sessions.get(username); SessionMap sessionMap = sessions.get(username);
...@@ -752,15 +752,21 @@ public class SessionManager extends BasicModule { ...@@ -752,15 +752,21 @@ public class SessionManager extends BasicModule {
return session; return session;
} }
public boolean isAnonymousRoute(String username) {
// JID's node and resource are the same for anonymous sessions
return anonymousSessions.containsKey(username);
}
public boolean isActiveRoute(String username, String resource) { public boolean isActiveRoute(String username, String resource) {
boolean hasRoute = false; boolean hasRoute = false;
if (username == null || "".equals(username)) { // Check if there is an anonymous session
if (resource != null) { if (resource != null && resource.equals(username) &&
hasRoute = anonymousSessions.containsKey(resource); anonymousSessions.containsKey(resource)) {
} hasRoute = true;
} }
else { else {
// Check if there is a session for a registered user
username = username.toLowerCase(); username = username.toLowerCase();
Session session = null; Session session = null;
synchronized (username.intern()) { synchronized (username.intern()) {
...@@ -858,7 +864,7 @@ public class SessionManager extends BasicModule { ...@@ -858,7 +864,7 @@ public class SessionManager extends BasicModule {
if (resource == null) { if (resource == null) {
return null; return null;
} }
if (username == null || "".equals(username)) { if (username == null || !UserManager.getInstance().isRegisteredUser(username)) {
session = anonymousSessions.get(resource); session = anonymousSessions.get(resource);
} }
else { else {
...@@ -1100,7 +1106,7 @@ public class SessionManager extends BasicModule { ...@@ -1100,7 +1106,7 @@ public class SessionManager extends BasicModule {
} }
public int getSessionCount(String username) { public int getSessionCount(String username) {
if (username == null) { if (username == null || !UserManager.getInstance().isRegisteredUser(username)) {
return 0; return 0;
} }
int sessionCount = 0; int sessionCount = 0;
...@@ -1428,7 +1434,8 @@ public class SessionManager extends BasicModule { ...@@ -1428,7 +1434,8 @@ public class SessionManager extends BasicModule {
public void sendServerMessage(JID address, String subject, String body) { public void sendServerMessage(JID address, String subject, String body) {
Message packet = createServerMessage(subject, body); Message packet = createServerMessage(subject, body);
try { try {
if (address == null || address.getNode() == null || address.getNode().length() < 1) { if (address == null || address.getNode() == null ||
!UserManager.getInstance().isRegisteredUser(address)) {
broadcast(packet); broadcast(packet);
} }
else if (address.getResource() == null || address.getResource().length() < 1) { else if (address.getResource() == null || address.getResource().length() < 1) {
......
...@@ -11,6 +11,8 @@ ...@@ -11,6 +11,8 @@
package org.jivesoftware.wildfire.auth; package org.jivesoftware.wildfire.auth;
import org.jivesoftware.wildfire.user.UserManager;
/** /**
* A token that proves that a user has successfully authenticated. * A token that proves that a user has successfully authenticated.
* *
...@@ -46,6 +48,6 @@ public class AuthToken { ...@@ -46,6 +48,6 @@ public class AuthToken {
* @return true if this token is the anonymous AuthToken. * @return true if this token is the anonymous AuthToken.
*/ */
public boolean isAnonymous() { public boolean isAnonymous() {
return username == null; return username == null || !UserManager.getInstance().isRegisteredUser(username);
} }
} }
\ No newline at end of file
...@@ -14,17 +14,17 @@ package org.jivesoftware.wildfire.handler; ...@@ -14,17 +14,17 @@ 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.stringprep.Stringprep;
import org.jivesoftware.stringprep.StringprepException;
import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.util.LocaleUtils;
import org.jivesoftware.util.Log;
import org.jivesoftware.wildfire.*; import org.jivesoftware.wildfire.*;
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.user.UserManager; import org.jivesoftware.wildfire.user.UserManager;
import org.jivesoftware.wildfire.user.UserNotFoundException; import org.jivesoftware.wildfire.user.UserNotFoundException;
import org.jivesoftware.util.LocaleUtils;
import org.jivesoftware.util.Log;
import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.stringprep.Stringprep;
import org.jivesoftware.stringprep.StringprepException;
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;
...@@ -263,6 +263,7 @@ public class IQAuthHandler extends IQHandler implements IQAuthInfo { ...@@ -263,6 +263,7 @@ public class IQAuthHandler extends IQHandler implements IQAuthInfo {
IQ response = IQ.createResultIQ(packet);; IQ response = IQ.createResultIQ(packet);;
if (anonymousAllowed) { if (anonymousAllowed) {
session.setAnonymousAuth(); session.setAnonymousAuth();
response.setTo(session.getAddress());
Element auth = response.setChildElement("query", "jabber:iq:auth"); Element auth = response.setChildElement("query", "jabber:iq:auth");
auth.addElement("resource").setText(session.getAddress().getResource()); auth.addElement("resource").setText(session.getAddress().getResource());
} }
......
...@@ -16,13 +16,14 @@ import org.jivesoftware.wildfire.ClientSession; ...@@ -16,13 +16,14 @@ import org.jivesoftware.wildfire.ClientSession;
import org.jivesoftware.wildfire.IQHandlerInfo; import org.jivesoftware.wildfire.IQHandlerInfo;
import org.jivesoftware.wildfire.SessionManager; import org.jivesoftware.wildfire.SessionManager;
import org.jivesoftware.wildfire.XMPPServer; import org.jivesoftware.wildfire.XMPPServer;
import org.jivesoftware.wildfire.user.User;
import org.jivesoftware.wildfire.event.UserEventListener;
import org.jivesoftware.wildfire.auth.UnauthorizedException; import org.jivesoftware.wildfire.auth.UnauthorizedException;
import org.jivesoftware.wildfire.disco.ServerFeaturesProvider; import org.jivesoftware.wildfire.disco.ServerFeaturesProvider;
import org.jivesoftware.wildfire.event.UserEventListener;
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.privacy.PrivacyListProvider; import org.jivesoftware.wildfire.privacy.PrivacyListProvider;
import org.jivesoftware.wildfire.user.User;
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;
...@@ -53,7 +54,7 @@ public class IQPrivacyHandler extends IQHandler ...@@ -53,7 +54,7 @@ public class IQPrivacyHandler extends IQHandler
public IQ handleIQ(IQ packet) throws UnauthorizedException { public IQ handleIQ(IQ packet) throws UnauthorizedException {
IQ.Type type = packet.getType(); IQ.Type type = packet.getType();
JID from = packet.getFrom(); JID from = packet.getFrom();
if (from.getNode() == null) { if (from.getNode() == null || !UserManager.getInstance().isRegisteredUser(from.getNode())) {
// Service is unavailable for anonymous users // Service is unavailable for anonymous users
IQ result = IQ.createResultIQ(packet); IQ result = IQ.createResultIQ(packet);
result.setChildElement(packet.getChildElement().createCopy()); result.setChildElement(packet.getChildElement().createCopy());
......
...@@ -11,17 +11,16 @@ ...@@ -11,17 +11,16 @@
package org.jivesoftware.wildfire.handler; package org.jivesoftware.wildfire.handler;
import org.jivesoftware.util.LocaleUtils;
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.ServerFeaturesProvider; import org.jivesoftware.wildfire.disco.ServerFeaturesProvider;
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.User;
import org.jivesoftware.wildfire.user.UserAlreadyExistsException; import org.jivesoftware.wildfire.user.UserAlreadyExistsException;
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.util.LocaleUtils;
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.Packet; import org.xmpp.packet.Packet;
...@@ -99,7 +98,8 @@ public class IQRosterHandler extends IQHandler implements ServerFeaturesProvider ...@@ -99,7 +98,8 @@ public class IQRosterHandler extends IQHandler implements ServerFeaturesProvider
JID recipientJID = packet.getTo(); JID recipientJID = packet.getTo();
// The packet is bound for the server and must be roster management // The packet is bound for the server and must be roster management
if (recipientJID == null || recipientJID.getNode() == null) { if (recipientJID == null || recipientJID.getNode() == null ||
!UserManager.getInstance().isRegisteredUser(recipientJID.getNode())) {
returnPacket = manageRoster(roster); returnPacket = manageRoster(roster);
} }
// The packet must be a roster removal from a foreign domain user. // The packet must be a roster removal from a foreign domain user.
...@@ -168,7 +168,9 @@ public class IQRosterHandler extends IQHandler implements ServerFeaturesProvider ...@@ -168,7 +168,9 @@ public class IQRosterHandler extends IQHandler implements ServerFeaturesProvider
IQ.Type type = packet.getType(); IQ.Type type = packet.getType();
try { try {
if (sender.getNode() == null && IQ.Type.get == type) { if ((sender.getNode() == null ||
!UserManager.getInstance().isRegisteredUser(sender.getNode())) &&
IQ.Type.get == type) {
// If anonymous user asks for his roster then return an empty roster // If anonymous user asks for his roster then return an empty roster
IQ reply = IQ.createResultIQ(packet); IQ reply = IQ.createResultIQ(packet);
reply.setChildElement("query", "jabber:iq:roster"); reply.setChildElement("query", "jabber:iq:roster");
......
...@@ -12,23 +12,23 @@ ...@@ -12,23 +12,23 @@
package org.jivesoftware.wildfire.spi; package org.jivesoftware.wildfire.spi;
import org.dom4j.Document; import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.DocumentException; import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
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.privacy.PrivacyList;
import org.jivesoftware.wildfire.privacy.PrivacyListManager;
import org.jivesoftware.wildfire.handler.PresenceUpdateHandler;
import org.jivesoftware.wildfire.component.InternalComponentManager;
import org.jivesoftware.wildfire.auth.UnauthorizedException; import org.jivesoftware.wildfire.auth.UnauthorizedException;
import org.jivesoftware.wildfire.component.InternalComponentManager;
import org.jivesoftware.wildfire.container.BasicModule; import org.jivesoftware.wildfire.container.BasicModule;
import org.jivesoftware.wildfire.handler.PresenceUpdateHandler;
import org.jivesoftware.wildfire.privacy.PrivacyList;
import org.jivesoftware.wildfire.privacy.PrivacyListManager;
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.User; 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.util.CacheManager;
import org.jivesoftware.util.LocaleUtils;
import org.jivesoftware.util.Log;
import org.xmpp.component.Component; import org.xmpp.component.Component;
import org.xmpp.packet.JID; import org.xmpp.packet.JID;
import org.xmpp.packet.PacketError; import org.xmpp.packet.PacketError;
...@@ -140,7 +140,7 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager ...@@ -140,7 +140,7 @@ 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) { if (username == null || !UserManager.getInstance().isRegisteredUser(username)) {
// Ignore anonymous users // Ignore anonymous users
return; return;
} }
...@@ -159,7 +159,7 @@ public class PresenceManagerImpl extends BasicModule implements PresenceManager ...@@ -159,7 +159,7 @@ 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) { if (username == null || !UserManager.getInstance().isRegisteredUser(username)) {
// Ignore anonymous users // Ignore anonymous users
return; return;
} }
......
...@@ -8,17 +8,18 @@ ...@@ -8,17 +8,18 @@
- a copy of which is included in this distribution. - a copy of which is included in this distribution.
--%> --%>
<%@ page import="org.jivesoftware.util.*, <%@ page import="org.jivesoftware.util.JiveGlobals,
java.util.*, org.jivesoftware.util.ParamUtils,
org.jivesoftware.wildfire.*, org.jivesoftware.wildfire.ClientSession,
java.text.NumberFormat, org.jivesoftware.wildfire.PresenceManager,
org.jivesoftware.admin.*, org.jivesoftware.wildfire.SessionManager,
org.jivesoftware.wildfire.user.User, org.jivesoftware.wildfire.user.User,
org.jivesoftware.wildfire.user.UserManager,
org.xmpp.packet.JID, org.xmpp.packet.JID,
org.xmpp.packet.Presence, java.text.NumberFormat"
java.net.URLEncoder"
errorPage="error.jsp" errorPage="error.jsp"
%> %>
<%@ page import="java.util.Collection"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %> <%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt" %> <%@ taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt" %>
...@@ -39,7 +40,7 @@ ...@@ -39,7 +40,7 @@
SessionManager sessionManager = webManager.getSessionManager(); SessionManager sessionManager = webManager.getSessionManager();
JID address = new JID(jid); JID address = new JID(jid);
ClientSession currentSess = sessionManager.getSession(address); ClientSession currentSess = sessionManager.getSession(address);
boolean isAnonymous = address.getNode() == null || "".equals(address.getNode()); boolean isAnonymous = !UserManager.getInstance().isRegisteredUser(address);
// Get a presence manager // Get a presence manager
PresenceManager presenceManager = webManager.getPresenceManager(); PresenceManager presenceManager = webManager.getPresenceManager();
......
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