Commit aff687d1 authored by Armando Jagucki's avatar Armando Jagucki Committed by ajagucki

Added a new abstract MUCEventDelegate class with the ability to react to,...

Added a new abstract MUCEventDelegate class with the ability to react to, allow, or deny MUC related events.

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@10098 b35dd754-fafc-0310-a699-88a17e54d16e
parent 994bf861
package org.jivesoftware.openfire.clearspace;
import org.jivesoftware.openfire.muc.MUCEventDelegate;
import org.jivesoftware.openfire.XMPPServer;
import org.jivesoftware.openfire.component.InternalComponentManager;
import org.xmpp.packet.JID;
import org.xmpp.packet.IQ;
import org.xmpp.component.ComponentException;
import org.xmpp.component.Component;
import java.util.Map;
import java.util.HashMap;
/**
* TODO: Comment me
*
* @author Armando Jagucki
*/
public class ClearspaceMUCEventDelegate extends MUCEventDelegate {
/**
* This event will be triggered when an entity joins an existing room.
* <p/>
* Returns true if the user is allowed to join the room.
*
* @param roomName the name of the MUC room.
* @param userjid the JID of the user attempting to join the room.
* @return true if the user is allowed to join the room.
*/
public boolean joiningRoom(String roomName, JID userjid) {
return false; // TODO: Implement
}
public Map<String, String> getRoomConfig(String roomName) {
Map<String, String> roomConfig = new HashMap<String, String>();
// TODO: Ensure the getComponent method gets implemented.
Component csComponent = ClearspaceManager.getInstance().getComponent();
// TODO: Get the config by connecting to CS through the component
InternalComponentManager internalComponentManager = InternalComponentManager.getInstance();
// TODO: Create query packet asking for the room config and in CS create a handler for that packet
IQ query = null;
IQ result;
try {
result = internalComponentManager.query(csComponent, query, 15000);
} catch (ComponentException e) {
//
}
// TODO: Setup roomConfig based on the result packet containing config values
JID roomJid = new JID(roomName);
roomConfig.put("muc#roomconfig_roomname", roomJid.getNode());
roomConfig.put("muc#roomconfig_roomdesc", "");
roomConfig.put("muc#roomconfig_changesubject", "1");
roomConfig.put("muc#roomconfig_maxusers", "0");
roomConfig.put("muc#roomconfig_publicroom", "1");
roomConfig.put("muc#roomconfig_moderatedroom", "0");
roomConfig.put("muc#roomconfig_membersonly", "0");
roomConfig.put("muc#roomconfig_allowinvites", "1");
roomConfig.put("muc#roomconfig_roomsecret", "");
roomConfig.put("muc#roomconfig_whois", "anyone");
roomConfig.put("muc#roomconfig_enablelogging", "0");
roomConfig.put("x-muc#roomconfig_reservednick", "0");
roomConfig.put("x-muc#roomconfig_canchangenick", "1");
roomConfig.put("x-muc#roomconfig_registration", "1");
roomConfig.put("muc#roomconfig_persistentroom", "1");
String ownerJid = roomJid.getNode() + "@"
+ "clearspace." + XMPPServer.getInstance().getServerInfo().getXMPPDomain();
roomConfig.put("muc#roomconfig_roomowners", ownerJid);
return roomConfig;
}
/**
* This event will be triggered when an entity attempts to destroy a room.
* <p/>
* Returns true if the user is allowed to destroy the room.
*
* @param roomName the name of the MUC room being destroyed.
* @param userjid the JID of the user attempting to destroy the room.
* @return true if the user is allowed to destroy the room.
*/
public boolean destroyingRoom(String roomName, JID userjid) {
return false; // TODO: Implement
}
}
......@@ -34,6 +34,7 @@ import org.jivesoftware.util.cache.DefaultCache;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;
import org.xmpp.packet.JID;
import org.xmpp.component.Component;
import java.io.IOException;
import java.lang.reflect.Constructor;
......@@ -91,6 +92,9 @@ public class ClearspaceManager extends BasicModule implements ExternalComponentM
protected static final String IM_URL_PREFIX = "imService/";
public static final String MUC_SUBDOMAIN = "clearspace-conference";
private static final String MUC_DESCRIPTION = "Clearspace Conference Services";
private static ThreadLocal<XMPPPacketReader> localParser = null;
private static XmlPullParserFactory factory = null;
......@@ -407,12 +411,22 @@ public class ClearspaceManager extends BasicModule implements ExternalComponentM
}
// Listen for changes to external component settings
ExternalComponentManager.addListener(this);
// Set up custom clearspace MUC service
ClearspaceMultiUserChatService mucService = new ClearspaceMultiUserChatService(MUC_SUBDOMAIN, MUC_DESCRIPTION);
XMPPServer.getInstance().getMultiUserChatManager().registerMultiUserChatService(mucService);
// Starts the clearspace configuration task
startClearspaceConfig();
}
}
public void stop() {
super.stop();
// Unregister/shut down custom MUC service
XMPPServer.getInstance().getMultiUserChatManager().unregisterMultiUserChatService(MUC_SUBDOMAIN);
}
/**
*
*/
......@@ -421,7 +435,7 @@ public class ClearspaceManager extends BasicModule implements ExternalComponentM
if (configClearspaceTask != null) {
configClearspaceTask.cancel();
Log.debug("Stopping previous configuration Clearspace task.");
}
}
// Create and schedule a confi task every minute
configClearspaceTask = new ConfigClearspaceTask();
......@@ -824,6 +838,16 @@ public class ClearspaceManager extends BasicModule implements ExternalComponentM
}
}
/**
* Returns the Clearspace External XMPP Component.
*
* @return the Clearspace External XMPP Component.
*/
protected Component getComponent() {
// TODO: Implement
return null;
}
private class ConfigClearspaceTask extends TimerTask {
public void run() {
......@@ -838,4 +862,4 @@ public class ClearspaceManager extends BasicModule implements ExternalComponentM
}
}
}
}
\ No newline at end of file
}
/**
* $Revision$
* $Date$
*
* Copyright (C) 2008 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution.
*/
package org.jivesoftware.openfire.clearspace;
import org.jivesoftware.openfire.muc.*;
import org.jivesoftware.openfire.muc.spi.MultiUserChatServiceImpl;
import org.dom4j.Element;
import org.xmpp.packet.JID;
import java.util.Iterator;
import java.util.ArrayList;
/**
* This ia an extension of a standard MultiUserChatService implementation that accounts for
* Clearspace interactions, restrictions, and special rules.
*
* @author Daniel Henninger
*/
public class ClearspaceMultiUserChatService extends MultiUserChatServiceImpl implements MultiUserChatService {
/**
* Create a new clearspace group chat service.
*
* @param subdomain Subdomain portion of the conference services (for example, conference for conference.example.org)
* @param description Short description of service for disco and such.
*/
public ClearspaceMultiUserChatService(String subdomain, String description) {
super(subdomain, description);
// TODO: enable when CS MUC works (should create a protected setter method)
//mucEventDelegate = new ClearspaceMUCEventDelegate();
}
@Override
public void enableService(boolean enabled, boolean persistent) {
// Ignore
}
@Override
public boolean isServiceEnabled() {
return true;
}
@Override
public boolean isServicePrivate() {
return true;
}
@Override
public Iterator<Element> getIdentities(String name, String node, JID senderJID) {
Iterator identitiesIterator = super.getIdentities(name, node, senderJID);
// TODO: Add custom identities
return identitiesIterator;
}
}
package org.jivesoftware.openfire.muc;
import org.xmpp.packet.JID;
import java.util.Map;
/**
* Gives the implementer the ability to react to, allow, or deny MUC related events.
*
* For example:
* - Event: a user tries to join a room
* Reaction: the delegate decides to allow or deny the user from joining
*
* @author Armando Jagucki
*/
public abstract class MUCEventDelegate {
/**
* This event will be triggered when an entity joins an existing room.
*
* Returns true if the user is allowed to join the room.
*
* @param roomName the name of the MUC room.
* @param userjid the JID of the user attempting to join the room.
* @return true if the user is allowed to join the room.
*/
public abstract boolean joiningRoom(String roomName, JID userjid);
public abstract Map<String, String> getRoomConfig(String roomName);
/**
* This event will be triggered when an entity attempts to destroy a room.
*
* Returns true if the user is allowed to destroy the room.
*
* @param roomName the name of the MUC room being destroyed.
* @param userjid the JID of the user attempting to destroy the room.
* @return true if the user is allowed to destroy the room.
*/
public abstract boolean destroyingRoom(String roomName, JID userjid);
public boolean loadConfig(MUCRoom room) {
Map<String, String> roomConfig = getRoomConfig(room.getName());
if (roomConfig != null) {
room.setNaturalLanguageName(roomConfig.get("muc#roomconfig_roomname"));
room.setDescription(roomConfig.get("muc#roomconfig_roomdesc"));
room.setCanOccupantsChangeSubject("1".equals(roomConfig.get("muc#roomconfig_changesubject")));
room.setMaxUsers(Integer.parseInt(roomConfig.get("muc#roomconfig_maxusers")));
room.setPublicRoom("1".equals(roomConfig.get("muc#roomconfig_publicroom")));
room.setModerated("1".equals(roomConfig.get("muc#roomconfig_moderatedroom")));
room.setMembersOnly("1".equals(roomConfig.get("muc#roomconfig_membersonly")));
room.setCanOccupantsInvite("1".equals(roomConfig.get("muc#roomconfig_allowinvites")));
room.setPassword(roomConfig.get("muc#roomconfig_roomsecret"));
room.setCanAnyoneDiscoverJID("anyone".equals(roomConfig.get("muc#roomconfig_whois")));
room.setLogEnabled("1".equals(roomConfig.get("muc#roomconfig_enablelogging")));
room.setLoginRestrictedToNickname("1".equals(roomConfig.get("x-muc#roomconfig_reservednick")));
room.setChangeNickname("1".equals(roomConfig.get("x-muc#roomconfig_canchangenick")));
room.setRegistrationEnabled("1".equals(roomConfig.get("x-muc#roomconfig_registration")));
room.setPersistent("1".equals(roomConfig.get("muc#roomconfig_persistentroom")));
room.addFirstOwner(roomConfig.get("muc#roomconfig_roomowners"));
}
return roomConfig != null;
}
}
......@@ -198,6 +198,11 @@ public class MultiUserChatServiceImpl implements Component, MultiUserChatService
*/
private boolean serviceEnabled = true;
/**
* Delegate responds to events for the MUC service.
*/
protected MUCEventDelegate mucEventDelegate;
/**
* Create a new group chat server.
*
......@@ -447,19 +452,28 @@ public class MultiUserChatServiceImpl implements Component, MultiUserChatService
loaded = true;
}
catch (IllegalArgumentException e) {
// The room does not exist so check for creation permissions
// Room creation is always allowed for sysadmin
if (isRoomCreationRestricted() &&
!sysadmins.contains(userjid.toBareJID())) {
// The room creation is only allowed for certain JIDs
if (!allowedToCreate.contains(userjid.toBareJID())) {
// The user is not in the list of allowed JIDs to create a room so raise
// an exception
throw new NotAllowedException();
// Check if room needs to be recreated in case it failed to be created previously
// (or was deleted somehow and is expected to exist by a delegate).
if (mucEventDelegate != null && mucEventDelegate.loadConfig(room)) {
loaded = true;
if (room.isPersistent()) {
MUCPersistenceManager.saveToDB(room);
}
}
else {
// The room does not exist so check for creation permissions
// Room creation is always allowed for sysadmin
if (isRoomCreationRestricted() && !sysadmins.contains(userjid.toBareJID())) {
// The room creation is only allowed for certain JIDs
if (!allowedToCreate.contains(userjid.toBareJID())) {
// The user is not in the list of allowed JIDs to create a room so raise
// an exception
throw new NotAllowedException();
}
}
room.addFirstOwner(userjid.toBareJID());
created = true;
}
room.addFirstOwner(userjid.toBareJID());
created = true;
}
rooms.put(roomName, room);
}
......
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