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 {
}
/**
* <p>Initialize the session as an anonymous login.</p>
* <p>This automatically upgrades the session's
* status to authenticated and enables many features that are not
* available until authenticated (obtaining managers for example).</p>
* Initialize the session as an anonymous login. This automatically upgrades the session's
* status to authenticated and enables many features that are not available until
* authenticated (obtaining managers for example).<p>
*/
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);
setStatus(Session.STATUS_AUTHENTICATED);
}
......
......@@ -20,6 +20,8 @@ import org.jivesoftware.wildfire.container.BasicModule;
import org.jivesoftware.wildfire.event.UserEventDispatcher;
import org.jivesoftware.wildfire.event.UserEventListener;
import org.jivesoftware.wildfire.user.User;
import org.jivesoftware.wildfire.user.UserManager;
import org.xmpp.packet.JID;
import org.xmpp.packet.Message;
import java.io.StringReader;
......@@ -93,13 +95,14 @@ public class OfflineMessageStore extends BasicModule implements UserEventListene
if (message == null) {
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 (username == null) {
if (username == null || !UserManager.getInstance().isRegisteredUser(recipient)) {
return;
}
else if (!XMPPServer.getInstance().getServerInfo().getName().equals(message.getTo()
.getDomain())) {
else
if (!XMPPServer.getInstance().getServerInfo().getName().equals(recipient.getDomain())) {
// Do not store messages sent to users of remote servers
return;
}
......
......@@ -11,11 +11,12 @@
package org.jivesoftware.wildfire;
import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.util.Log;
import org.jivesoftware.wildfire.container.BasicModule;
import org.jivesoftware.wildfire.privacy.PrivacyList;
import org.jivesoftware.wildfire.privacy.PrivacyListManager;
import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.util.Log;
import org.jivesoftware.wildfire.user.UserManager;
import org.xmpp.packet.JID;
import org.xmpp.packet.Message;
import org.xmpp.packet.PacketError;
......@@ -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
JID recipientJID = message.getTo();
if (recipientJID == null || serverAddress.equals(recipientJID) ||
recipientJID.getNode() == null) {
recipientJID.getNode() == null ||
!UserManager.getInstance().isRegisteredUser(recipientJID.getNode())) {
return;
}
// Do not store messages of type groupchat, error or headline as specified in JEP-160
......
......@@ -680,8 +680,9 @@ public class SessionManager extends BasicModule {
* @param priority The new priority for the session
*/
public void changePriority(JID sender, int priority) {
if (sender.getNode() == null) {
// Do nothing if the session belongs to an anonymous user
if (sender.getNode() == null ||
!UserManager.getInstance().isRegisteredUser(sender.getNode())) {
// Do nothing if the session belongs to an anonymous user
return;
}
String username = sender.getNode();
......@@ -719,12 +720,11 @@ public class SessionManager extends BasicModule {
ClientSession session = null;
String resource = recipient.getResource();
String username = recipient.getNode();
if (username == null || "".equals(username)) {
if (resource != null) {
session = anonymousSessions.get(resource);
if (session == null){
session = getSession(recipient);
}
if (resource != null &&
(username == null || !UserManager.getInstance().isRegisteredUser(username))) {
session = anonymousSessions.get(resource);
if (session == null){
session = getSession(recipient);
}
}
else {
......@@ -752,15 +752,21 @@ public class SessionManager extends BasicModule {
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) {
boolean hasRoute = false;
if (username == null || "".equals(username)) {
if (resource != null) {
hasRoute = anonymousSessions.containsKey(resource);
}
// Check if there is an anonymous session
if (resource != null && resource.equals(username) &&
anonymousSessions.containsKey(resource)) {
hasRoute = true;
}
else {
// Check if there is a session for a registered user
username = username.toLowerCase();
Session session = null;
synchronized (username.intern()) {
......@@ -858,7 +864,7 @@ public class SessionManager extends BasicModule {
if (resource == null) {
return null;
}
if (username == null || "".equals(username)) {
if (username == null || !UserManager.getInstance().isRegisteredUser(username)) {
session = anonymousSessions.get(resource);
}
else {
......@@ -1100,7 +1106,7 @@ public class SessionManager extends BasicModule {
}
public int getSessionCount(String username) {
if (username == null) {
if (username == null || !UserManager.getInstance().isRegisteredUser(username)) {
return 0;
}
int sessionCount = 0;
......@@ -1428,7 +1434,8 @@ public class SessionManager extends BasicModule {
public void sendServerMessage(JID address, String subject, String body) {
Message packet = createServerMessage(subject, body);
try {
if (address == null || address.getNode() == null || address.getNode().length() < 1) {
if (address == null || address.getNode() == null ||
!UserManager.getInstance().isRegisteredUser(address)) {
broadcast(packet);
}
else if (address.getResource() == null || address.getResource().length() < 1) {
......
......@@ -11,6 +11,8 @@
package org.jivesoftware.wildfire.auth;
import org.jivesoftware.wildfire.user.UserManager;
/**
* A token that proves that a user has successfully authenticated.
*
......@@ -46,6 +48,6 @@ public class AuthToken {
* @return true if this token is the anonymous AuthToken.
*/
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;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
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.auth.AuthFactory;
import org.jivesoftware.wildfire.auth.AuthToken;
import org.jivesoftware.wildfire.auth.UnauthorizedException;
import org.jivesoftware.wildfire.user.UserManager;
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.JID;
import org.xmpp.packet.PacketError;
......@@ -263,6 +263,7 @@ public class IQAuthHandler extends IQHandler implements IQAuthInfo {
IQ response = IQ.createResultIQ(packet);;
if (anonymousAllowed) {
session.setAnonymousAuth();
response.setTo(session.getAddress());
Element auth = response.setChildElement("query", "jabber:iq:auth");
auth.addElement("resource").setText(session.getAddress().getResource());
}
......
......@@ -16,13 +16,14 @@ import org.jivesoftware.wildfire.ClientSession;
import org.jivesoftware.wildfire.IQHandlerInfo;
import org.jivesoftware.wildfire.SessionManager;
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.disco.ServerFeaturesProvider;
import org.jivesoftware.wildfire.event.UserEventListener;
import org.jivesoftware.wildfire.privacy.PrivacyList;
import org.jivesoftware.wildfire.privacy.PrivacyListManager;
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.JID;
import org.xmpp.packet.PacketError;
......@@ -53,7 +54,7 @@ public class IQPrivacyHandler extends IQHandler
public IQ handleIQ(IQ packet) throws UnauthorizedException {
IQ.Type type = packet.getType();
JID from = packet.getFrom();
if (from.getNode() == null) {
if (from.getNode() == null || !UserManager.getInstance().isRegisteredUser(from.getNode())) {
// Service is unavailable for anonymous users
IQ result = IQ.createResultIQ(packet);
result.setChildElement(packet.getChildElement().createCopy());
......
......@@ -11,17 +11,16 @@
package org.jivesoftware.wildfire.handler;
import org.jivesoftware.util.LocaleUtils;
import org.jivesoftware.util.Log;
import org.jivesoftware.wildfire.*;
import org.jivesoftware.wildfire.auth.UnauthorizedException;
import org.jivesoftware.wildfire.disco.ServerFeaturesProvider;
import org.jivesoftware.wildfire.roster.Roster;
import org.jivesoftware.wildfire.roster.RosterItem;
import org.jivesoftware.wildfire.user.User;
import org.jivesoftware.wildfire.user.UserAlreadyExistsException;
import org.jivesoftware.wildfire.user.UserManager;
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.JID;
import org.xmpp.packet.Packet;
......@@ -99,7 +98,8 @@ public class IQRosterHandler extends IQHandler implements ServerFeaturesProvider
JID recipientJID = packet.getTo();
// 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);
}
// The packet must be a roster removal from a foreign domain user.
......@@ -168,7 +168,9 @@ public class IQRosterHandler extends IQHandler implements ServerFeaturesProvider
IQ.Type type = packet.getType();
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
IQ reply = IQ.createResultIQ(packet);
reply.setChildElement("query", "jabber:iq:roster");
......
......@@ -12,23 +12,23 @@
package org.jivesoftware.wildfire.spi;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
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.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.component.InternalComponentManager;
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.RosterItem;
import org.jivesoftware.wildfire.user.User;
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.component.Component;
import org.xmpp.packet.JID;
import org.xmpp.packet.PacketError;
......@@ -140,7 +140,7 @@ 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) {
if (username == null || !UserManager.getInstance().isRegisteredUser(username)) {
// Ignore anonymous users
return;
}
......@@ -159,7 +159,7 @@ 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) {
if (username == null || !UserManager.getInstance().isRegisteredUser(username)) {
// Ignore anonymous users
return;
}
......
......@@ -8,17 +8,18 @@
- a copy of which is included in this distribution.
--%>
<%@ page import="org.jivesoftware.util.*,
java.util.*,
org.jivesoftware.wildfire.*,
java.text.NumberFormat,
org.jivesoftware.admin.*,
<%@ page import="org.jivesoftware.util.JiveGlobals,
org.jivesoftware.util.ParamUtils,
org.jivesoftware.wildfire.ClientSession,
org.jivesoftware.wildfire.PresenceManager,
org.jivesoftware.wildfire.SessionManager,
org.jivesoftware.wildfire.user.User,
org.jivesoftware.wildfire.user.UserManager,
org.xmpp.packet.JID,
org.xmpp.packet.Presence,
java.net.URLEncoder"
java.text.NumberFormat"
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/fmt_rt" prefix="fmt" %>
......@@ -39,7 +40,7 @@
SessionManager sessionManager = webManager.getSessionManager();
JID address = new JID(jid);
ClientSession currentSess = sessionManager.getSession(address);
boolean isAnonymous = address.getNode() == null || "".equals(address.getNode());
boolean isAnonymous = !UserManager.getInstance().isRegisteredUser(address);
// Get a presence manager
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