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

Delete user affiliations when removing user account. JM-1136

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@10722 b35dd754-fafc-0310-a699-88a17e54d16e
parent e731e09e
......@@ -10,34 +10,39 @@
*/
package org.jivesoftware.openfire.muc;
import org.jivesoftware.util.*;
import org.jivesoftware.util.cache.CacheFactory;
import org.jivesoftware.openfire.container.BasicModule;
import org.jivesoftware.database.DbConnectionManager;
import org.jivesoftware.database.SequenceManager;
import org.jivesoftware.openfire.XMPPServer;
import org.jivesoftware.openfire.cluster.ClusterEventListener;
import org.jivesoftware.openfire.cluster.ClusterManager;
import org.jivesoftware.openfire.stats.Statistic;
import org.jivesoftware.openfire.stats.StatisticsManager;
import org.jivesoftware.openfire.muc.spi.MultiUserChatServiceImpl;
import org.jivesoftware.openfire.container.BasicModule;
import org.jivesoftware.openfire.event.UserEventDispatcher;
import org.jivesoftware.openfire.event.UserEventListener;
import org.jivesoftware.openfire.muc.cluster.*;
import org.jivesoftware.openfire.muc.spi.LocalMUCRoom;
import org.jivesoftware.openfire.muc.spi.MUCPersistenceManager;
import org.jivesoftware.openfire.muc.spi.MUCServicePropertyEventListener;
import org.jivesoftware.openfire.muc.cluster.*;
import org.jivesoftware.database.DbConnectionManager;
import org.jivesoftware.database.SequenceManager;
import org.xmpp.packet.JID;
import org.xmpp.component.ComponentManagerFactory;
import org.jivesoftware.openfire.muc.spi.MultiUserChatServiceImpl;
import org.jivesoftware.openfire.stats.Statistic;
import org.jivesoftware.openfire.stats.StatisticsManager;
import org.jivesoftware.openfire.user.User;
import org.jivesoftware.util.*;
import org.jivesoftware.util.cache.CacheFactory;
import org.xmpp.component.ComponentException;
import org.xmpp.component.ComponentManagerFactory;
import org.xmpp.packet.JID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.*;
import java.sql.*;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
/**
* Provides centralized management of all configured Multi User Chat (MUC) services.
*
* @author Daniel Henninger
*/
public class MultiUserChatManager extends BasicModule implements ClusterEventListener, MUCServicePropertyEventListener {
public class MultiUserChatManager extends BasicModule implements ClusterEventListener, MUCServicePropertyEventListener,
UserEventListener {
private static final String LOAD_SERVICES = "SELECT subdomain,description,isHidden FROM ofMucService";
private static final String CREATE_SERVICE = "INSERT INTO ofMucService(serviceID,subdomain,description,isHidden) VALUES(?,?,?,?)";
......@@ -85,6 +90,7 @@ public class MultiUserChatManager extends BasicModule implements ClusterEventLis
addNumberOutgoingMessages();
ClusterManager.addListener(this);
UserEventDispatcher.addListener(this);
}
/**
......@@ -94,6 +100,7 @@ public class MultiUserChatManager extends BasicModule implements ClusterEventLis
super.stop();
ClusterManager.removeListener(this);
UserEventDispatcher.removeListener(this);
// Remove the statistics.
StatisticsManager.getInstance().removeStatistic(roomsStatKey);
......@@ -821,6 +828,21 @@ public class MultiUserChatManager extends BasicModule implements ClusterEventLis
CacheFactory.doSynchronousClusterTask(new ServiceUpdatedEvent(service), false);
}
public void userCreated(User user, Map<String, Object> params) {
// Do nothing
}
public void userDeleting(User user, Map<String, Object> params) {
// Delete any affiliation of the user to any room of any MUC service
MUCPersistenceManager
.removeAffiliationFromDB(XMPPServer.getInstance().createJID(user.getUsername(), null, true));
// TODO Delete any user information from the rooms loaded into memory
}
public void userModified(User user, Map<String, Object> params) {
// Do nothing
}
private static class ServiceComparator implements Comparator<MultiUserChatService> {
public int compare(MultiUserChatService o1, MultiUserChatService o2) {
return o1.getServiceName().compareTo(o2.getServiceName());
......
......@@ -20,6 +20,7 @@ import org.jivesoftware.openfire.muc.MUCRoom;
import org.jivesoftware.openfire.muc.MultiUserChatService;
import org.jivesoftware.util.Log;
import org.jivesoftware.util.StringUtils;
import org.xmpp.packet.JID;
import java.sql.Connection;
import java.sql.PreparedStatement;
......@@ -108,6 +109,10 @@ public class MUCPersistenceManager {
"UPDATE ofMucAffiliation SET affiliation=? WHERE roomID=? AND jid=?";
private static final String DELETE_AFFILIATION =
"DELETE FROM ofMucAffiliation WHERE roomID=? AND jid=?";
private static final String DELETE_USER_MEMBER =
"DELETE FROM ofMucMember WHERE jid=?";
private static final String DELETE_USER_MUCAFFILIATION =
"DELETE FROM ofMucaffiliation WHERE jid=?";
private static final String ADD_CONVERSATION_LOG =
"INSERT INTO ofMucConversationLog (roomID,sender,nickname,logTime,subject,body) " +
"VALUES (?,?,?,?,?,?)";
......@@ -928,6 +933,39 @@ public class MUCPersistenceManager {
}
}
/**
* Removes the affiliation of the user from the DB if ANY room that is persistent.
*
* @param bareJID The bareJID of the user to remove his affiliation from ALL persistent rooms.
*/
public static void removeAffiliationFromDB(JID bareJID)
{
Connection con = null;
PreparedStatement pstmt = null;
try {
con = DbConnectionManager.getConnection();
// Remove the user from the members table
pstmt = con.prepareStatement(DELETE_USER_MEMBER);
pstmt.setString(1, bareJID.toBareJID());
pstmt.executeUpdate();
pstmt.close();
// Remove the user from the generic affiliations table
pstmt = con.prepareStatement(DELETE_USER_MUCAFFILIATION);
pstmt.setString(1, bareJID.toBareJID());
pstmt.executeUpdate();
}
catch (SQLException sqle) {
Log.error(sqle);
}
finally {
try { if (pstmt != null) pstmt.close(); }
catch (Exception e) { Log.error(e); }
try { if (con != null) con.close(); }
catch (Exception e) { Log.error(e); }
}
}
/**
* Saves the conversation log entry to the database.
*
......
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