Commit 6fa51d80 authored by Armando Jagucki's avatar Armando Jagucki Committed by ajagucki

ClearspaceMUCEventDelegate is now operational supporting on-demand room...

ClearspaceMUCEventDelegate is now operational supporting on-demand room creation and permissions-limited room joins/deletions. Along with that work came an optimization to the user creation process (JM-1313).

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@10163 b35dd754-fafc-0310-a699-88a17e54d16e
parent bfaccdb4
......@@ -277,9 +277,11 @@ public class IQRouter extends BasicModule {
multicastRouter.route(packet);
return;
}
else if (IQ.Type.result == packet.getType() || IQ.Type.error == packet.getType()) {
// The server got an answer to an IQ packet that was sent from the server
IQResultListener iqResultListener = resultListeners.remove(packet.getID());
}
if (IQ.Type.result == packet.getType() || IQ.Type.error == packet.getType()) {
// The server got an answer to an IQ packet that was sent from the server
IQResultListener iqResultListener = resultListeners.remove(packet.getID());
if (iqResultListener != null) {
resultTimeout.remove(packet.getID());
if (iqResultListener != null) {
try {
......
......@@ -26,12 +26,7 @@ public class ClearspaceAuthProvider implements AuthProvider {
// Service url prefix
protected static final String URL_PREFIX = "permissionService/";
private ClearspaceManager manager;
public ClearspaceAuthProvider() {
// gets the manager
manager = ClearspaceManager.getInstance();
// Add SASL mechanism for use with Clearspace's group chat integration
SASLAuthentication.addSupportedMechanism("CLEARSPACE");
}
......@@ -65,7 +60,7 @@ public class ClearspaceAuthProvider implements AuthProvider {
public void authenticate(String username, String password) throws UnauthorizedException {
try {
String path = URL_PREFIX + "authenticate/" + username + "/" + password;
manager.executeRequest(GET, path);
ClearspaceManager.getInstance().executeRequest(GET, path);
} catch (UnauthorizedException ue) {
throw ue;
} catch (Exception e) {
......
......@@ -35,12 +35,9 @@ import java.util.List;
public class ClearspaceGroupProvider implements GroupProvider {
protected static final String URL_PREFIX = "groupService/";
private ClearspaceManager manager;
private Boolean readOnly;
public ClearspaceGroupProvider() {
// gets the manager
manager = ClearspaceManager.getInstance();
}
public Group createGroup(String name) throws UnsupportedOperationException, GroupAlreadyExistsException {
......@@ -60,7 +57,7 @@ public class ClearspaceGroupProvider implements GroupProvider {
nameE.addText(name);
rootE.addElement("description");
Element group = manager.executeRequest(POST, path, groupDoc.asXML());
Element group = ClearspaceManager.getInstance().executeRequest(POST, path, groupDoc.asXML());
return translateGroup(group);
......@@ -79,9 +76,9 @@ public class ClearspaceGroupProvider implements GroupProvider {
}
try {
long groupID = manager.getGroupID(name);
long groupID = ClearspaceManager.getInstance().getGroupID(name);
String path = URL_PREFIX + "groups/" + groupID;
manager.executeRequest(DELETE, path);
ClearspaceManager.getInstance().executeRequest(DELETE, path);
} catch (GroupNotFoundException gnfe) {
Log.error(gnfe);
......@@ -102,7 +99,7 @@ public class ClearspaceGroupProvider implements GroupProvider {
WSUtils.modifyElementText(group, "name", newName);
String path = URL_PREFIX + "groups";
manager.executeRequest(PUT, path);
ClearspaceManager.getInstance().executeRequest(PUT, path);
} catch (GroupNotFoundException gnfe) {
Log.error(gnfe);
......@@ -120,7 +117,7 @@ public class ClearspaceGroupProvider implements GroupProvider {
WSUtils.modifyElementText(group, "description", description);
String path = URL_PREFIX + "groups";
manager.executeRequest(PUT, path);
ClearspaceManager.getInstance().executeRequest(PUT, path);
} catch (GroupNotFoundException gnfe) {
Log.error(gnfe);
......@@ -134,7 +131,7 @@ public class ClearspaceGroupProvider implements GroupProvider {
public int getGroupCount() {
try {
String path = URL_PREFIX + "groupCount";
Element element = manager.executeRequest(GET, path);
Element element = ClearspaceManager.getInstance().executeRequest(GET, path);
return Integer.valueOf(getReturn(element));
} catch (Exception e) {
// It is not supported exception, wrap it into an UnsupportedOperationException
......@@ -145,7 +142,7 @@ public class ClearspaceGroupProvider implements GroupProvider {
public Collection<String> getGroupNames() {
try {
String path = URL_PREFIX + "groupNames";
Element element = manager.executeRequest(GET, path);
Element element = ClearspaceManager.getInstance().executeRequest(GET, path);
return parseStringArray(element);
} catch (Exception e) {
......@@ -157,7 +154,7 @@ public class ClearspaceGroupProvider implements GroupProvider {
public Collection<String> getGroupNames(int startIndex, int numResults) {
try {
String path = URL_PREFIX + "groupNamesBounded/" + startIndex + "/" + numResults;
Element element = manager.executeRequest(GET, path);
Element element = ClearspaceManager.getInstance().executeRequest(GET, path);
return parseStringArray(element);
} catch (Exception e) {
......@@ -168,9 +165,9 @@ public class ClearspaceGroupProvider implements GroupProvider {
public Collection<String> getGroupNames(JID user) {
try {
long userID = manager.getUserID(user);
long userID = ClearspaceManager.getInstance().getUserID(user);
String path = URL_PREFIX + "userGroupNames/" + userID;
Element element = manager.executeRequest(GET, path);
Element element = ClearspaceManager.getInstance().executeRequest(GET, path);
return parseStringArray(element);
} catch (UserNotFoundException e) {
......@@ -183,8 +180,8 @@ public class ClearspaceGroupProvider implements GroupProvider {
public void addMember(String groupName, JID user, boolean administrator) throws UnsupportedOperationException {
try {
long userID = manager.getUserID(user);
long groupID = manager.getGroupID(groupName);
long userID = ClearspaceManager.getInstance().getUserID(user);
long groupID = ClearspaceManager.getInstance().getGroupID(groupName);
String path = URL_PREFIX;
......@@ -202,7 +199,7 @@ public class ClearspaceGroupProvider implements GroupProvider {
rootE.addElement("groupID");
nameE.addText(String.valueOf(groupID));
manager.executeRequest(POST, path, groupDoc.asXML());
ClearspaceManager.getInstance().executeRequest(POST, path, groupDoc.asXML());
} catch (GroupNotFoundException e) {
......@@ -225,8 +222,8 @@ public class ClearspaceGroupProvider implements GroupProvider {
long userID;
long groupID;
try {
userID = manager.getUserID(user);
groupID = manager.getGroupID(groupName);
userID = ClearspaceManager.getInstance().getUserID(user);
groupID = ClearspaceManager.getInstance().getGroupID(groupName);
} catch (GroupNotFoundException e) {
// It's ok, that not existing group doesn't contains that memeber, :)
......@@ -243,10 +240,10 @@ public class ClearspaceGroupProvider implements GroupProvider {
//for user. Therefore one of them could throw an exception.
try {
String path = URL_PREFIX + "groupAdmins/" + groupID + "/" + userID;
manager.executeRequest(DELETE, path);
ClearspaceManager.getInstance().executeRequest(DELETE, path);
path = URL_PREFIX + "groupMembers/" + groupID + "/" + userID;
manager.executeRequest(DELETE, path);
ClearspaceManager.getInstance().executeRequest(DELETE, path);
} catch (GroupNotFoundException e) {
//won't happend, the group exist
} catch (UserNotFoundException e) {
......@@ -270,7 +267,7 @@ public class ClearspaceGroupProvider implements GroupProvider {
try {
// See if the is read only
String path = URL_PREFIX + "isReadOnly";
Element element = manager.executeRequest(GET, path);
Element element = ClearspaceManager.getInstance().executeRequest(GET, path);
readOnly = Boolean.valueOf(getReturn(element));
} catch (Exception e) {
// if there is a problem, keep it null, maybe in the next call succes.
......@@ -328,7 +325,7 @@ public class ClearspaceGroupProvider implements GroupProvider {
try {
String path = URL_PREFIX + "groups/" + name;
return manager.executeRequest(GET, path);
return ClearspaceManager.getInstance().executeRequest(GET, path);
} catch (GroupNotFoundException gnfe) {
// It is a supported exception, throw it again
throw gnfe;
......@@ -350,7 +347,7 @@ public class ClearspaceGroupProvider implements GroupProvider {
} else {
path = URL_PREFIX + "groupMembers/" + groupID;
}
Element element = manager.executeRequest(GET, path);
Element element = ClearspaceManager.getInstance().executeRequest(GET, path);
// Gets the JID from the response
List<Node> users = (List<Node>) element.selectNodes("return");
......
......@@ -36,14 +36,10 @@ public class ClearspaceLockOutProvider implements LockOutProvider {
protected static final String USER_URL_PREFIX = "userService/";
private ClearspaceManager manager;
/**
* Generate a ClearspaceLockOutProvider instance.
*/
public ClearspaceLockOutProvider() {
// Gets the manager
manager = ClearspaceManager.getInstance();
}
/**
......@@ -123,7 +119,7 @@ public class ClearspaceLockOutProvider implements LockOutProvider {
Element modifiedUser = modifyUser(user.element("return"), "enabled", enabled ? "true" : "false");
String path = USER_URL_PREFIX + "users";
manager.executeRequest(PUT, path, modifiedUser.asXML());
ClearspaceManager.getInstance().executeRequest(PUT, path, modifiedUser.asXML());
}
catch (UserNotFoundException e) {
Log.error("User with name " + username + " not found.", e);
......@@ -206,7 +202,7 @@ public class ClearspaceLockOutProvider implements LockOutProvider {
// Requests the user
String path = USER_URL_PREFIX + "users/" + username;
// return the response
return manager.executeRequest(GET, path);
return ClearspaceManager.getInstance().executeRequest(GET, path);
}
catch (Exception e) {
// It is not supported exception, wrap it into an UserNotFoundException
......
......@@ -2,27 +2,38 @@ package org.jivesoftware.openfire.clearspace;
import org.jivesoftware.openfire.XMPPServer;
import org.jivesoftware.openfire.muc.MUCEventDelegate;
import org.jivesoftware.openfire.muc.MUCRoom;
import org.jivesoftware.util.StringUtils;
import org.jivesoftware.util.Log;
import org.xmpp.packet.IQ;
import org.xmpp.packet.JID;
import org.dom4j.Element;
import org.dom4j.DocumentHelper;
import org.dom4j.Attribute;
import java.util.HashMap;
import java.util.Map;
import java.util.Collection;
import java.util.Iterator;
/**
* Handles checking with Clearspace regarding whether a user can join a particular chatroom (based
* on their permissions with the document/whatever the chatroom is associated with), as well as setting
* up room configurations.
* Handles checking with Clearspace regarding whether a user can join a particular MUC room (based
* on their permissions with the Clearspace JiveObject (eg. Community/Space) that the room is associated with).
*
* In addition, this MUCEventDelegate provides a means to obtain room configuration details from Clearspace
* in the event that the Clearspace MUC service needs to create a room on-demand (eg. when a user first joins the room).
*
* @author Armando Jagucki
*/
public class ClearspaceMUCEventDelegate extends MUCEventDelegate {
private String csMucDomain;
private String csComponentAddress;
private final String GET_ROOM_CONFIG_WARNING ="Clearspace sent an unexpected reply to a get-room-config request.";
public ClearspaceMUCEventDelegate() {
csMucDomain = ClearspaceManager.MUC_SUBDOMAIN+"@"+XMPPServer.getInstance().getServerInfo().getXMPPDomain();
String xmppDomain = XMPPServer.getInstance().getServerInfo().getXMPPDomain();
csMucDomain = ClearspaceManager.MUC_SUBDOMAIN + "." + xmppDomain;
csComponentAddress = ClearspaceManager.CLEARSPACE_COMPONENT + "." + xmppDomain;
}
/**
......@@ -30,25 +41,33 @@ public class ClearspaceMUCEventDelegate extends MUCEventDelegate {
* <p/>
* Returns true if the user is allowed to join the room.
*
* @param roomName the name of the MUC room.
* @param room the room the user is attempting to join.
* @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) {
public boolean joiningRoom(MUCRoom room, JID userjid) {
// Packet should look like:
// <iq to="clearspace.example.org" from="clearspace-conference.example.org">
// <join-check xmlns="http://jivesoftware.com/clearspace">
// <userjid>username@example.org</userjid>
// <roomjid>DOC-1234@clearspace-conference.example.org</roomjid>
// <roomjid>14-1234@clearspace-conference.example.org</roomjid>
// </join-check>
// </iq>
// Always allow an owner to join the room (especially since they need to join to configure the
// room on initial creation).
Collection<String> owners = room.getOwners();
if (owners != null && owners.contains(userjid.toBareJID())) {
return true;
}
IQ query = new IQ();
query.setFrom(csMucDomain);
Element cmd = DocumentHelper.createElement("join-check");
cmd.addElement("userjid").addText(userjid.toBareJID());
cmd.addElement("roomjid").addText(roomName+"@"+csMucDomain);
query.setChildElement(cmd);
Element cmd = query.setChildElement("join-check", "http://jivesoftware.com/clearspace");
Element userjidElement = cmd.addElement("userjid");
userjidElement.setText(userjid.toBareJID());
Element roomjidElement = cmd.addElement("roomjid");
roomjidElement.setText(room.getJID().toBareJID());
IQ result = ClearspaceManager.getInstance().query(query, 15000);
if (result == null) {
......@@ -68,35 +87,49 @@ public class ClearspaceMUCEventDelegate extends MUCEventDelegate {
public Map<String, String> getRoomConfig(String roomName) {
Map<String, String> roomConfig = new HashMap<String, String>();
// TODO: Create query packet asking for the room config and in CS create a handler for that packet
IQ query = null;
IQ result = ClearspaceManager.getInstance().query(query, 15000);
IQ iq = new IQ(IQ.Type.get);
iq.setFrom(csMucDomain);
iq.setID("get_room_config_" + StringUtils.randomString(3));
Element child = iq.setChildElement("get-room-config", "http://jivesoftware.com/clearspace");
Element roomjidElement = child.addElement("roomjid");
JID roomJid = new JID(roomName + "@" + csMucDomain);
roomjidElement.setText(roomJid.toBareJID());
IQ result = ClearspaceManager.getInstance().query(iq, 15000);
if (result == null) {
// TODO No answer was received from Clearspace so return null
// No answer was received from Clearspace, so return null.
Log.warn(GET_ROOM_CONFIG_WARNING);
return null;
}
else if (result.getType() != IQ.Type.result) {
// The reply was not a valid result containing the room configuration, so return null.
Log.warn(GET_ROOM_CONFIG_WARNING);
return null;
}
// TODO Check that the IQ is of type RESULT (and not ERROR) otherwise return null
// 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();
// Setup room configuration based on the configuration values in the result packet.
Element query = result.getChildElement();
if (query == null) {
Log.warn(GET_ROOM_CONFIG_WARNING);
return null;
}
Element xElement = query.element("x");
if (xElement == null) {
Log.warn(GET_ROOM_CONFIG_WARNING);
return null;
}
Iterator fields = xElement.elementIterator("field");
while (fields.hasNext()) {
Element field = (Element) fields.next();
Attribute varAttribute = field.attribute("var");
if (varAttribute != null) {
Element value = field.element("value");
if (value != null) {
roomConfig.put(varAttribute.getValue(), value.getText());
}
}
}
String ownerJid = roomJid.getNode() + "@" + csComponentAddress;
roomConfig.put("muc#roomconfig_roomowners", ownerJid);
return roomConfig;
......@@ -113,6 +146,6 @@ public class ClearspaceMUCEventDelegate extends MUCEventDelegate {
*/
public boolean destroyingRoom(String roomName, JID userjid) {
// We never allow destroying a room as a user, but clearspace components are permitted.
return ClearspaceManager.getInstance().isClearspace(userjid);
return ClearspaceManager.getInstance().isFromClearspace(userjid);
}
}
......@@ -66,6 +66,7 @@ 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";
public static final String CLEARSPACE_COMPONENT = "clearspace";
private static ThreadLocal<XMPPPacketReader> localParser = null;
private static XmlPullParserFactory factory = null;
......@@ -74,7 +75,7 @@ public class ClearspaceManager extends BasicModule implements ExternalComponentM
*/
private static final Map<String, String> exceptionMap;
private static ClearspaceManager instance = new ClearspaceManager();
private static ClearspaceManager instance;
static {
try {
......@@ -205,6 +206,7 @@ public class ClearspaceManager extends BasicModule implements ExternalComponentM
};
init();
instance = this;
}
private void init() {
......@@ -832,23 +834,18 @@ public class ClearspaceManager extends BasicModule implements ExternalComponentM
}
/**
* Returns true if a given JID represents a known Clearspace component domain.
* Returns true if a given JID belongs to a known Clearspace component domain.
* @param address Address to check.
* @return True if the specified address is a Clearspace component.
*/
public boolean isClearspace(JID address) {
return address.getNode() == null && clearspaces.contains(address.getDomain());
public boolean isFromClearspace(JID address) {
return clearspaces.contains(address.getDomain());
}
/**
* Sends an IQ packet to the Clearspace external component and returns the IQ packet
* returned by CS or <tt>null</tt> if no answer was received before the specified
* timeout.<p>
*
* The returned packet will be handled by the server and routed to the entity that sent
* the original IQ packet. Since this method block and listen to the replied IQ packet
* then the entity that sent the original IQ packet should ignore any reply related to
* the originating IQ packet.
* timeout.
*
* @param packet IQ packet to send.
* @param timeout milliseconds to wait before timing out.
......
......@@ -32,14 +32,10 @@ public class ClearspaceSecurityAuditProvider implements SecurityAuditProvider {
protected static final String AUDIT_URL_PREFIX = "auditService/";
private ClearspaceManager manager;
/**
* Generate a ClearspaceSecurityAuditProvider instance.
*/
public ClearspaceSecurityAuditProvider() {
// Gets the manager
manager = ClearspaceManager.getInstance();
}
/**
......@@ -72,7 +68,7 @@ public class ClearspaceSecurityAuditProvider implements SecurityAuditProvider {
detlE.addText("No details provided.");
}
manager.executeRequest(POST, path, auditDoc.asXML());
ClearspaceManager.getInstance().executeRequest(POST, path, auditDoc.asXML());
}
catch (Exception e) {
// Error while setting properties?
......
......@@ -35,14 +35,10 @@ public class ClearspaceUserProvider implements UserProvider {
// The ProfileSearchService webservice url prefix
protected static final String SEARCH_URL_PREFIX = "profileSearchService/";
private ClearspaceManager manager;
// Used to know it CS is a read only user provider
private Boolean readOnly;
public ClearspaceUserProvider() {
// Gets the manager
manager = ClearspaceManager.getInstance();
}
/**
......@@ -117,7 +113,7 @@ public class ClearspaceUserProvider implements UserProvider {
enabledE.addText("true");
Element user = manager.executeRequest(POST, path, groupDoc.asXML());
Element user = ClearspaceManager.getInstance().executeRequest(POST, path, groupDoc.asXML());
return translate(user);
} catch (UserAlreadyExistsException uaee) {
......@@ -139,9 +135,9 @@ public class ClearspaceUserProvider implements UserProvider {
}
try {
long userID = manager.getUserID(username);
long userID = ClearspaceManager.getInstance().getUserID(username);
String path = USER_URL_PREFIX + "users/" + userID;
manager.executeRequest(DELETE, path);
ClearspaceManager.getInstance().executeRequest(DELETE, path);
} catch (UserNotFoundException gnfe) {
// it is OK, the user doesn't exist "anymore"
......@@ -159,7 +155,7 @@ public class ClearspaceUserProvider implements UserProvider {
public int getUserCount() {
try {
String path = USER_URL_PREFIX + "users/count";
Element element = manager.executeRequest(GET, path);
Element element = ClearspaceManager.getInstance().executeRequest(GET, path);
int count = Integer.valueOf(getReturn(element));
return count;
} catch (Exception e) {
......@@ -186,7 +182,7 @@ public class ClearspaceUserProvider implements UserProvider {
public Collection<String> getUsernames() {
try {
String path = USER_URL_PREFIX + "userNames";
Element element = manager.executeRequest(GET, path);
Element element = ClearspaceManager.getInstance().executeRequest(GET, path);
return parseStringArray(element);
} catch (Exception e) {
......@@ -345,7 +341,7 @@ public class ClearspaceUserProvider implements UserProvider {
protected void updateUser(Element userUpdateParams) throws UserNotFoundException {
try {
String path = USER_URL_PREFIX + "users";
manager.executeRequest(PUT, path, userUpdateParams.asXML());
ClearspaceManager.getInstance().executeRequest(PUT, path, userUpdateParams.asXML());
} catch (UserNotFoundException e) {
throw new UserNotFoundException("User not found.");
......@@ -392,7 +388,7 @@ public class ClearspaceUserProvider implements UserProvider {
//TODO create a service on CS to get only the username field
String path = SEARCH_URL_PREFIX + "searchProfile";
Element element = manager.executeRequest(POST, path, paramsE.asXML());
Element element = ClearspaceManager.getInstance().executeRequest(POST, path, paramsE.asXML());
List<Node> userNodes = (List<Node>) element.selectNodes("return");
for (Node userNode : userNodes) {
......@@ -439,7 +435,7 @@ public class ClearspaceUserProvider implements UserProvider {
//TODO create a service on CS to get only the username field
String path = SEARCH_URL_PREFIX + "searchProfile";
Element element = manager.executeRequest(POST, path, paramsE.asXML());
Element element = ClearspaceManager.getInstance().executeRequest(POST, path, paramsE.asXML());
List<Node> userNodes = (List<Node>) element.selectNodes("return");
for (Node userNode : userNodes) {
......@@ -496,7 +492,7 @@ public class ClearspaceUserProvider implements UserProvider {
try {
// See if the is read only
String path = USER_URL_PREFIX + "isReadOnly";
Element element = manager.executeRequest(GET, path);
Element element = ClearspaceManager.getInstance().executeRequest(GET, path);
readOnly = Boolean.valueOf(getReturn(element));
} catch (Exception e) {
// if there is a problem, keep it null, maybe in the next call success.
......@@ -571,7 +567,7 @@ public class ClearspaceUserProvider implements UserProvider {
// Requests the user
String path = USER_URL_PREFIX + "users/" + username;
Element response = manager.executeRequest(GET, path);
Element response = ClearspaceManager.getInstance().executeRequest(GET, path);
// return the response
return response;
......
......@@ -41,12 +41,10 @@ public class ClearspaceVCardProvider implements VCardProvider {
protected static final String PROFILE_FIELDS_URL_PREFIX = "profileFieldService/";
protected static final String AVATAR_URL_PREFIX = "avatarService/";
private ClearspaceManager manager;
private Boolean avatarReadOnly;
private boolean fieldsIDLoaded;
public ClearspaceVCardProvider() {
this.manager = ClearspaceManager.getInstance();
}
/**
......@@ -77,7 +75,7 @@ public class ClearspaceVCardProvider implements VCardProvider {
// Gets the user
User user = UserManager.getInstance().getUser(username);
long userID = manager.getUserID(username);
long userID = ClearspaceManager.getInstance().getUserID(username);
// Gets the profiles information
Element profiles = getProfiles(userID);
......@@ -187,7 +185,7 @@ public class ClearspaceVCardProvider implements VCardProvider {
try {
long userID = manager.getUserID(username);
long userID = ClearspaceManager.getInstance().getUserID(username);
ClearspaceUserProvider userProvider = (ClearspaceUserProvider) UserManager.getUserProvider();
// Gets the user params that can be used to update it
......@@ -255,7 +253,7 @@ public class ClearspaceVCardProvider implements VCardProvider {
long userID;
try {
userID = manager.getUserID(username);
userID = ClearspaceManager.getInstance().getUserID(username);
} catch (UserNotFoundException gnfe) {
// it is OK, the user doesn't exist "anymore"
return;
......@@ -274,7 +272,7 @@ public class ClearspaceVCardProvider implements VCardProvider {
private void deleteProfiles(long userID) {
try {
String path = PROFILE_URL_PREFIX + "profiles/" + userID;
manager.executeRequest(ClearspaceManager.HttpType.DELETE, path);
ClearspaceManager.getInstance().executeRequest(ClearspaceManager.HttpType.DELETE, path);
} catch (Exception e) {
// It is not supported exception, wrap it into an UnsupportedOperationException
throw new UnsupportedOperationException("Unexpected error", e);
......@@ -289,7 +287,7 @@ public class ClearspaceVCardProvider implements VCardProvider {
private void deleteAvatar(long userID) {
try {
String path = AVATAR_URL_PREFIX + "avatar/" + userID;
manager.executeRequest(ClearspaceManager.HttpType.DELETE, path);
ClearspaceManager.getInstance().executeRequest(ClearspaceManager.HttpType.DELETE, path);
} catch (Exception e) {
// It is not supported exception, wrap it into an UnsupportedOperationException
throw new UnsupportedOperationException("Unexpected error", e);
......@@ -305,7 +303,7 @@ public class ClearspaceVCardProvider implements VCardProvider {
// Try to save the profile changes
try {
String path = PROFILE_URL_PREFIX + "profiles";
manager.executeRequest(POST, path, profilesUpdateParams.asXML());
ClearspaceManager.getInstance().executeRequest(POST, path, profilesUpdateParams.asXML());
} catch (Exception e) {
// It is not supported exception, wrap it into an UnsupportedOperationException
throw new UnsupportedOperationException("Unexpected error", e);
......@@ -328,7 +326,7 @@ public class ClearspaceVCardProvider implements VCardProvider {
// Requests the user active avatar
String path = AVATAR_URL_PREFIX + "activeAvatar/" + userID;
manager.executeRequest(POST, path, rootE.asXML());
ClearspaceManager.getInstance().executeRequest(POST, path, rootE.asXML());
} catch (Exception e) {
throw new UnsupportedOperationException("Error setting the user's " + userID + " active avatar " + avatarID, e);
}
......@@ -345,7 +343,7 @@ public class ClearspaceVCardProvider implements VCardProvider {
// Requests the user active avatar
String path = AVATAR_URL_PREFIX + "createAvatar";
Element avatar = manager.executeRequest(POST, path, avatarCreateParams.asXML());
Element avatar = ClearspaceManager.getInstance().executeRequest(POST, path, avatarCreateParams.asXML());
return Long.valueOf(avatar.element("return").element("WSAvatar").elementTextTrim("id"));
} catch (Exception e) {
......@@ -363,7 +361,7 @@ public class ClearspaceVCardProvider implements VCardProvider {
try {
// Requests the user profile
String path = PROFILE_URL_PREFIX + "profiles/" + userID;
return manager.executeRequest(GET, path);
return ClearspaceManager.getInstance().executeRequest(GET, path);
} catch (Exception e) {
throw new UnsupportedOperationException("Error getting the profiles of user: " + userID, e);
}
......@@ -379,7 +377,7 @@ public class ClearspaceVCardProvider implements VCardProvider {
try {
// Requests the user active avatar
String path = AVATAR_URL_PREFIX + "activeAvatar/" + userID;
return manager.executeRequest(GET, path);
return ClearspaceManager.getInstance().executeRequest(GET, path);
} catch (Exception e) {
throw new UnsupportedOperationException("Error getting the avatar of user: " + userID, e);
}
......@@ -392,7 +390,7 @@ public class ClearspaceVCardProvider implements VCardProvider {
try {
// See if the is read only
String path = AVATAR_URL_PREFIX + "userAvatarsEnabled";
Element element = manager.executeRequest(GET, path);
Element element = ClearspaceManager.getInstance().executeRequest(GET, path);
avatarReadOnly = !Boolean.valueOf(getReturn(element));
} catch (Exception e) {
// if there is a problem, keep it null, maybe next call success.
......@@ -406,7 +404,7 @@ public class ClearspaceVCardProvider implements VCardProvider {
private void loadDefaultProfileFields() {
try {
String path = PROFILE_FIELDS_URL_PREFIX + "fields";
Element defaultFields = manager.executeRequest(GET, path);
Element defaultFields = ClearspaceManager.getInstance().executeRequest(GET, path);
ClearspaceVCardTranslator.getInstance().initClearspaceFieldsId(defaultFields);
fieldsIDLoaded = true;
......
......@@ -69,7 +69,12 @@ public class WSUtils {
protected static void modifyElementText(Element element, String[] path, String newValue) {
Element e = element;
for (String s : path) {
e = e.element(s);
Element subElement = e.element(s);
if (subElement == null) {
// Add the element if associated string was not in path.
subElement = e.addElement(s);
}
e = subElement;
}
e.setText(newValue);
}
......
......@@ -376,11 +376,11 @@ public class IQRegisterHandler extends IQHandler implements ServerFeaturesProvid
}
else {
// Create the new account
newUser = userManager.createUser(username, password, null, email);
newUser = userManager.createUser(username, password, name, email);
}
}
// Set and save the extra user info (e.g. full name, etc.)
if (newUser != null && name != null) {
if (newUser != null && name != null && !name.equals(newUser.getName())) {
newUser.setName(name);
}
......
package org.jivesoftware.openfire.muc;
import org.xmpp.packet.JID;
import org.jivesoftware.openfire.muc.spi.LocalMUCRoom;
import java.util.Map;
......@@ -20,13 +21,18 @@ public abstract class MUCEventDelegate {
*
* Returns true if the user is allowed to join the room.
*
* @param roomName the name of the MUC room.
* @param room 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 boolean joiningRoom(MUCRoom room, JID userjid);
/**
* Returns a map containing room configuration variables and values.
*
* @param roomName the name of the room the configuration map is associated with.
* @returna map containing room configuration variables and values, or null if roomName was not valid.
*/
public abstract Map<String, String> getRoomConfig(String roomName);
/**
......@@ -40,28 +46,33 @@ public abstract class MUCEventDelegate {
*/
public abstract boolean destroyingRoom(String roomName, JID userjid);
/**
* Loads a delegate provided room configuration for the room specified.
*
* @param room the room to load the configuration for.
* @return true if the room configuration was received from the delegate and applied to the room.
*/
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"));
try {
room.unlock(room.getRole());
} catch (ForbiddenException e) {
return false;
}
}
return roomConfig != null;
}
......
......@@ -454,7 +454,7 @@ public class LocalMUCRoom implements MUCRoom {
RegistrationRequiredException, ConflictException, ServiceUnavailableException,
NotAcceptableException {
if (((MultiUserChatServiceImpl)mucService).getMUCDelegate() != null) {
if (!((MultiUserChatServiceImpl)mucService).getMUCDelegate().joiningRoom(this.getName(), user.getAddress())) {
if (!((MultiUserChatServiceImpl)mucService).getMUCDelegate().joiningRoom(this, user.getAddress())) {
// Delegate said no, reject join.
throw new UnauthorizedException();
}
......
......@@ -14,7 +14,14 @@
boolean save = request.getParameter("save") != null;
boolean test = request.getParameter("test") != null;
ClearspaceManager manager = ClearspaceManager.getInstance();
ClearspaceManager manager = null;
if (ClearspaceManager.getInstance() != null) {
// Use the existing manager. This will be the case after setup was completed
manager = ClearspaceManager.getInstance();
}
else {
manager = new ClearspaceManager();
}
Map<String, String> errors = new HashMap<String, String>();
if (save || test) {
......
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