Commit 7018ba41 authored by daryl herzmann's avatar daryl herzmann

Merge pull request #409 from Redor/plugins

Update REST API plugin to 1.2.1
parents 82e13c81 19c5198d
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>REST API Plugin Changelog</title>
<style type="text/css">
BODY {
font-size : 100%;
}
BODY, TD, TH {
font-family : tahoma, verdana, arial, helvetica, sans-serif;
font-size : 0.8em;
}
H2 {
font-size : 10pt;
font-weight : bold;
padding-left : 1em;
}
A:hover {
text-decoration : none;
}
H1 {
font-family : tahoma, arial, helvetica, sans-serif;
font-size : 1.4em;
font-weight: bold;
border-bottom : 1px #ccc solid;
padding-bottom : 2px;
}
TT {
font-family : courier new;
font-weight : bold;
color : #060;
}
PRE {
font-family : courier new;
font-size : 100%;
}
</style>
</head>
<body>
<h1>
REST API Plugin Changelog
</h1>
<p><b>1.2.0</b> -- October 12, 2015</p>
<ul>
<li>[<a href='http://www.igniterealtime.org/issues/browse/OF-953'>OF-953</a>] - Updated JSP libraries.</li>
<li>Requires Openfire 3.11.0.</li>
</ul>
<p><b>1.1.7</b> -- November 13th, 2015</p>
<ul>
<li>Added: Provide the possibility to use a Custom Auth Filter</li>
<li>Fixed: Preflight request will be not blocked by Authentication</li>
<li>Added: Group names in ChatRoom Entity</li>
</ul>
<p><b>1.1.6</b> -- September 24th, 2015</p>
<ul>
<li>Added: Endpoints to add / remove a user from a user group</li>
<li>Fixed: Error response in JSON format</li>
</ul>
<p><b>1.1.5</b> -- September 1st, 2015</p>
<ul>
<li>Added: Send broadcast message to all online users</li>
</ul>
<p><b>1.1.4</b> -- August 19th, 2015</p>
<ul>
<li>Added: get concurrent sessions (local or cluster wide)</li>
</ul>
<p><b>1.1.3</b> -- August 15th, 2015</p>
<ul>
<li>Added: get count of users unread messages</li>
</ul>
<p><b>1.1.2</b> -- August 4th, 2015</p>
<ul>
<li>Added: CORS to all endpoints</li>
</ul>
<p><b>1.1.1</b> -- June 29th, 2015</p>
<ul>
<li>Added: new endpoint to close user sessions</li>
</ul>
<p><b>1.1.0</b> -- June 3rd, 2015</p>
<ul>
<li>Added: new endpoints for sessions (Get overview over all or specific user sessions)</li>
</ul>
<p><b>1.0.2</b> -- March 3rd, 2015</p>
<ul>
<li>User will be kicked by a lockout (ban)</li>
<li>Added: new endpoints for groups (Get overview over all or specific group and to create, update or delete a group)</li>
</ul>
<p><b>1.0.1</b> -- February 20th, 2015</p>
<ul>
<li>Added possibility to rename a user (Thanks to JustMarried plugin)</li>
<li>Adjusted HTTP Codes by conflict to HTTP CODE: 409</li>
<li>Added subject to Chat room</li>
<li>Disabled jersey logging on startup</li>
<li>By create a new chat room the chat room service will be created if it was not there</li>
</ul>
<p><b>1.0.0</b> -- February 3rd, 2015</p>
<ul>
<li>UserService plugin and MUC Service plugin are merged to the REST API plugin.</li>
<li>Extended REST API with JSON data format.</li>
</ul>
<p><b>0.1.0</b> -- November 14th, 2014</p>
<ul>
<li>Initial release of REST API Plugin with possibility to manage system properties.</li>
</ul>
</body>
</html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>REST API Plugin Changelog</title>
<style type="text/css">
BODY {
font-size : 100%;
}
BODY, TD, TH {
font-family : tahoma, verdana, arial, helvetica, sans-serif;
font-size : 0.8em;
}
H2 {
font-size : 10pt;
font-weight : bold;
padding-left : 1em;
}
A:hover {
text-decoration : none;
}
H1 {
font-family : tahoma, arial, helvetica, sans-serif;
font-size : 1.4em;
font-weight: bold;
border-bottom : 1px #ccc solid;
padding-bottom : 2px;
}
TT {
font-family : courier new;
font-weight : bold;
color : #060;
}
PRE {
font-family : courier new;
font-size : 100%;
}
</style>
</head>
<body>
<h1>
REST API Plugin Changelog
</h1>
<p><b>1.2.1</b> -- November 24th, 2015</p>
<ul>
<li>Fixed: Cluster issue by creating a new chat room</li>
</ul>
<p><b>1.2.0</b> -- October 12th, 2015</p>
<ul>
<li>[<a href='http://www.igniterealtime.org/issues/browse/OF-953'>OF-953</a>] - Updated JSP libraries.</li>
<li>Requires Openfire 3.11.0.</li>
</ul>
<p><b>1.1.7</b> -- November 13th, 2015</p>
<ul>
<li>Added: Provide the possibility to use a Custom Auth Filter</li>
<li>Fixed: Preflight request will be not blocked by Authentication</li>
<li>Added: Group names in ChatRoom Entity</li>
</ul>
<p><b>1.1.6</b> -- September 24th, 2015</p>
<ul>
<li>Added: Endpoints to add / remove a user from a user group</li>
<li>Fixed: Error response in JSON format</li>
</ul>
<p><b>1.1.5</b> -- September 1st, 2015</p>
<ul>
<li>Added: Send broadcast message to all online users</li>
</ul>
<p><b>1.1.4</b> -- August 19th, 2015</p>
<ul>
<li>Added: get concurrent sessions (local or cluster wide)</li>
</ul>
<p><b>1.1.3</b> -- August 15th, 2015</p>
<ul>
<li>Added: get count of users unread messages</li>
</ul>
<p><b>1.1.2</b> -- August 4th, 2015</p>
<ul>
<li>Added: CORS to all endpoints</li>
</ul>
<p><b>1.1.1</b> -- June 29th, 2015</p>
<ul>
<li>Added: new endpoint to close user sessions</li>
</ul>
<p><b>1.1.0</b> -- June 3rd, 2015</p>
<ul>
<li>Added: new endpoints for sessions (Get overview over all or specific user sessions)</li>
</ul>
<p><b>1.0.2</b> -- March 3rd, 2015</p>
<ul>
<li>User will be kicked by a lockout (ban)</li>
<li>Added: new endpoints for groups (Get overview over all or specific group and to create, update or delete a group)</li>
</ul>
<p><b>1.0.1</b> -- February 20th, 2015</p>
<ul>
<li>Added possibility to rename a user (Thanks to JustMarried plugin)</li>
<li>Adjusted HTTP Codes by conflict to HTTP CODE: 409</li>
<li>Added subject to Chat room</li>
<li>Disabled jersey logging on startup</li>
<li>By create a new chat room the chat room service will be created if it was not there</li>
</ul>
<p><b>1.0.0</b> -- February 3rd, 2015</p>
<ul>
<li>UserService plugin and MUC Service plugin are merged to the REST API plugin.</li>
<li>Extended REST API with JSON data format.</li>
</ul>
<p><b>0.1.0</b> -- November 14th, 2014</p>
<ul>
<li>Initial release of REST API Plugin with possibility to manage system properties.</li>
</ul>
</body>
</html>
<?xml version="1.0" encoding="UTF-8"?>
<plugin>
<class>org.jivesoftware.openfire.plugin.rest.RESTServicePlugin</class>
<name>REST API</name>
<description>Allows administration over a RESTful API.</description>
<author>Roman Soldatow</author>
<version>1.2.0</version>
<date>10/12/2015</date>
<minServerVersion>3.11.0 alpha</minServerVersion>
<adminconsole>
<tab id="tab-server">
<sidebar id="sidebar-server-settings">
<item id="rest-api" name="REST API" url="rest-api.jsp"
description="Click to manage the service that allows to configure the Openfire over a RESTFul API" />
</sidebar>
</tab>
</adminconsole>
</plugin>
<?xml version="1.0" encoding="UTF-8"?>
<plugin>
<class>org.jivesoftware.openfire.plugin.rest.RESTServicePlugin</class>
<name>REST API</name>
<description>Allows administration over a RESTful API.</description>
<author>Roman Soldatow</author>
<version>1.2.1</version>
<date>11/24/2015</date>
<minServerVersion>3.10.0</minServerVersion>
<adminconsole>
<tab id="tab-server">
<sidebar id="sidebar-server-settings">
<item id="rest-api" name="REST API" url="rest-api.jsp"
description="Click to manage the service that allows to configure the Openfire over a RESTFul API" />
</sidebar>
</tab>
</adminconsole>
</plugin>
package org.jivesoftware.openfire.plugin.rest.controller;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import javax.ws.rs.core.Response;
import org.jivesoftware.openfire.XMPPServer;
import org.jivesoftware.openfire.plugin.rest.entity.MUCChannelType;
import org.jivesoftware.openfire.plugin.rest.entity.MUCRoomEntities;
import org.jivesoftware.openfire.plugin.rest.entity.MUCRoomEntity;
import org.jivesoftware.openfire.plugin.rest.entity.ParticipantEntities;
import org.jivesoftware.openfire.plugin.rest.entity.ParticipantEntity;
import org.jivesoftware.openfire.plugin.rest.exceptions.ExceptionType;
import org.jivesoftware.openfire.plugin.rest.exceptions.ServiceException;
import org.jivesoftware.openfire.muc.ConflictException;
import org.jivesoftware.openfire.muc.ForbiddenException;
import org.jivesoftware.openfire.muc.MUCRole;
import org.jivesoftware.openfire.muc.MUCRoom;
import org.jivesoftware.openfire.muc.NotAllowedException;
import org.jivesoftware.openfire.group.ConcurrentGroupList;
import org.jivesoftware.openfire.group.Group;
import org.jivesoftware.openfire.plugin.rest.utils.MUCRoomUtils;
import org.jivesoftware.openfire.plugin.rest.utils.UserUtils;
import org.jivesoftware.util.AlreadyExistsException;
import org.xmpp.packet.JID;
/**
* The Class MUCRoomController.
*/
public class MUCRoomController {
/** The Constant INSTANCE. */
public static final MUCRoomController INSTANCE = new MUCRoomController();
/**
* Gets the single instance of MUCRoomController.
*
* @return single instance of MUCRoomController
*/
public static MUCRoomController getInstance() {
return INSTANCE;
}
/**
* Gets the chat rooms.
*
* @param serviceName
* the service name
* @param channelType
* the channel type
* @param roomSearch
* the room search
* @return the chat rooms
*/
public MUCRoomEntities getChatRooms(String serviceName, String channelType, String roomSearch, boolean expand) {
List<MUCRoom> rooms = XMPPServer.getInstance().getMultiUserChatManager().getMultiUserChatService(serviceName)
.getChatRooms();
List<MUCRoomEntity> mucRoomEntities = new ArrayList<MUCRoomEntity>();
for (MUCRoom chatRoom : rooms) {
if (roomSearch != null) {
if (!chatRoom.getName().contains(roomSearch)) {
continue;
}
}
if (channelType.equals(MUCChannelType.ALL)) {
mucRoomEntities.add(convertToMUCRoomEntity(chatRoom, expand));
} else if (channelType.equals(MUCChannelType.PUBLIC) && chatRoom.isPublicRoom()) {
mucRoomEntities.add(convertToMUCRoomEntity(chatRoom, expand));
}
}
return new MUCRoomEntities(mucRoomEntities);
}
/**
* Gets the chat room.
*
* @param roomName
* the room name
* @param serviceName
* the service name
* @return the chat room
* @throws ServiceException
* the service exception
*/
public MUCRoomEntity getChatRoom(String roomName, String serviceName, boolean expand) throws ServiceException {
MUCRoom chatRoom = XMPPServer.getInstance().getMultiUserChatManager().getMultiUserChatService(serviceName)
.getChatRoom(roomName);
if (chatRoom == null) {
throw new ServiceException("Could not find the chat room", roomName, ExceptionType.ROOM_NOT_FOUND, Response.Status.NOT_FOUND);
}
MUCRoomEntity mucRoomEntity = convertToMUCRoomEntity(chatRoom, expand);
return mucRoomEntity;
}
/**
* Delete chat room.
*
* @param roomName
* the room name
* @param serviceName
* the service name
* @throws ServiceException
* the service exception
*/
public void deleteChatRoom(String roomName, String serviceName) throws ServiceException {
MUCRoom chatRoom = XMPPServer.getInstance().getMultiUserChatManager().getMultiUserChatService(serviceName)
.getChatRoom(roomName.toLowerCase());
if (chatRoom != null) {
chatRoom.destroyRoom(null, null);
} else {
throw new ServiceException("Could not remove the channel", roomName, ExceptionType.ROOM_NOT_FOUND, Response.Status.NOT_FOUND);
}
}
/**
* Creates the chat room.
*
* @param serviceName
* the service name
* @param mucRoomEntity
* the MUC room entity
* @throws ServiceException
* the service exception
*/
public void createChatRoom(String serviceName, MUCRoomEntity mucRoomEntity) throws ServiceException {
try {
createRoom(mucRoomEntity, serviceName);
} catch (NotAllowedException e) {
throw new ServiceException("Could not create the channel", mucRoomEntity.getRoomName(),
ExceptionType.NOT_ALLOWED, Response.Status.FORBIDDEN, e);
} catch (ForbiddenException e) {
throw new ServiceException("Could not create the channel", mucRoomEntity.getRoomName(),
ExceptionType.NOT_ALLOWED, Response.Status.FORBIDDEN, e);
} catch (ConflictException e) {
throw new ServiceException("Could not create the channel", mucRoomEntity.getRoomName(),
ExceptionType.NOT_ALLOWED, Response.Status.CONFLICT, e);
} catch (AlreadyExistsException e) {
throw new ServiceException("Could not create the channel", mucRoomEntity.getRoomName(),
ExceptionType.ALREADY_EXISTS, Response.Status.CONFLICT, e);
}
}
/**
* Update chat room.
*
* @param roomName
* the room name
* @param serviceName
* the service name
* @param mucRoomEntity
* the MUC room entity
* @throws ServiceException
* the service exception
*/
public void updateChatRoom(String roomName, String serviceName, MUCRoomEntity mucRoomEntity)
throws ServiceException {
try {
// If the room name is different throw exception
if (!roomName.equals(mucRoomEntity.getRoomName())) {
throw new ServiceException(
"Could not update the channel. The room name is different to the entity room name.", roomName,
ExceptionType.ILLEGAL_ARGUMENT_EXCEPTION, Response.Status.BAD_REQUEST);
}
createRoom(mucRoomEntity, serviceName);
} catch (NotAllowedException e) {
throw new ServiceException("Could not update the channel", roomName, ExceptionType.NOT_ALLOWED, Response.Status.FORBIDDEN, e);
} catch (ForbiddenException e) {
throw new ServiceException("Could not update the channel", roomName, ExceptionType.NOT_ALLOWED, Response.Status.FORBIDDEN, e);
} catch (ConflictException e) {
throw new ServiceException("Could not update the channel", roomName, ExceptionType.NOT_ALLOWED, Response.Status.CONFLICT, e);
} catch (AlreadyExistsException e) {
throw new ServiceException("Could not update the channel", mucRoomEntity.getRoomName(),
ExceptionType.ALREADY_EXISTS, Response.Status.CONFLICT, e);
}
}
/**
* Creates the room.
*
* @param mucRoomEntity
* the MUC room entity
* @param serviceName
* the service name
* @throws NotAllowedException
* the not allowed exception
* @throws ForbiddenException
* the forbidden exception
* @throws ConflictException
* the conflict exception
* @throws AlreadyExistsException
*/
private void createRoom(MUCRoomEntity mucRoomEntity, String serviceName) throws NotAllowedException,
ForbiddenException, ConflictException, AlreadyExistsException {
// Set owner
JID owner = XMPPServer.getInstance().createJID("admin", null);
if (mucRoomEntity.getOwners() != null && mucRoomEntity.getOwners().size() > 0) {
owner = new JID(mucRoomEntity.getOwners().get(0));
} else {
List<String> owners = new ArrayList<String>();
owners.add(owner.toBareJID());
mucRoomEntity.setOwners(owners);
}
// Check if chat service is available, if not create a new one
boolean serviceRegistered = XMPPServer.getInstance().getMultiUserChatManager().isServiceRegistered(serviceName);
if(!serviceRegistered) {
XMPPServer.getInstance().getMultiUserChatManager().createMultiUserChatService(serviceName, serviceName, false);
}
MUCRoom room = XMPPServer.getInstance().getMultiUserChatManager().getMultiUserChatService(serviceName)
.getChatRoom(mucRoomEntity.getRoomName().toLowerCase(), owner);
// Set values
room.setNaturalLanguageName(mucRoomEntity.getNaturalName());
room.setSubject(mucRoomEntity.getSubject());
room.setDescription(mucRoomEntity.getDescription());
room.setPassword(mucRoomEntity.getPassword());
room.setPersistent(mucRoomEntity.isPersistent());
room.setPublicRoom(mucRoomEntity.isPublicRoom());
room.setRegistrationEnabled(mucRoomEntity.isRegistrationEnabled());
room.setCanAnyoneDiscoverJID(mucRoomEntity.isCanAnyoneDiscoverJID());
room.setCanOccupantsChangeSubject(mucRoomEntity.isCanOccupantsChangeSubject());
room.setCanOccupantsInvite(mucRoomEntity.isCanOccupantsInvite());
room.setChangeNickname(mucRoomEntity.isCanChangeNickname());
room.setModificationDate(mucRoomEntity.getModificationDate());
room.setLogEnabled(mucRoomEntity.isLogEnabled());
room.setLoginRestrictedToNickname(mucRoomEntity.isLoginRestrictedToNickname());
room.setMaxUsers(mucRoomEntity.getMaxUsers());
room.setMembersOnly(mucRoomEntity.isMembersOnly());
room.setModerated(mucRoomEntity.isModerated());
// Set broadcast presence roles
if (mucRoomEntity.getBroadcastPresenceRoles() != null) {
room.setRolesToBroadcastPresence(mucRoomEntity.getBroadcastPresenceRoles());
} else {
room.setRolesToBroadcastPresence(new ArrayList<String>());
}
// Set all roles
setRoles(room, mucRoomEntity);
// Set creation date
if (mucRoomEntity.getCreationDate() != null) {
room.setCreationDate(mucRoomEntity.getCreationDate());
} else {
room.setCreationDate(new Date());
}
// Set modification date
if (mucRoomEntity.getModificationDate() != null) {
room.setModificationDate(mucRoomEntity.getModificationDate());
} else {
room.setModificationDate(new Date());
}
// Unlock the room, because the default configuration lock the room.
room.unlock(room.getRole());
// Save the room to the DB if the room should be persistant
if (room.isPersistent()) {
room.saveToDB();
}
}
/**
* Gets the room participants.
*
* @param roomName
* the room name
* @param serviceName
* the service name
* @return the room participants
*/
public ParticipantEntities getRoomParticipants(String roomName, String serviceName) {
ParticipantEntities participantEntities = new ParticipantEntities();
List<ParticipantEntity> participants = new ArrayList<ParticipantEntity>();
Collection<MUCRole> serverParticipants = XMPPServer.getInstance().getMultiUserChatManager()
.getMultiUserChatService(serviceName).getChatRoom(roomName).getParticipants();
for (MUCRole role : serverParticipants) {
ParticipantEntity participantEntity = new ParticipantEntity();
participantEntity.setJid(role.getRoleAddress().toFullJID());
participantEntity.setRole(role.getRole().name());
participantEntity.setAffiliation(role.getAffiliation().name());
participants.add(participantEntity);
}
participantEntities.setParticipants(participants);
return participantEntities;
}
/**
* Convert to MUC room entity.
*
* @param room
* the room
* @return the MUC room entity
*/
public MUCRoomEntity convertToMUCRoomEntity(MUCRoom room, boolean expand) {
MUCRoomEntity mucRoomEntity = new MUCRoomEntity(room.getNaturalLanguageName(), room.getName(),
room.getDescription());
mucRoomEntity.setSubject(room.getSubject());
mucRoomEntity.setCanAnyoneDiscoverJID(room.canAnyoneDiscoverJID());
mucRoomEntity.setCanChangeNickname(room.canChangeNickname());
mucRoomEntity.setCanOccupantsChangeSubject(room.canOccupantsChangeSubject());
mucRoomEntity.setCanOccupantsInvite(room.canOccupantsInvite());
mucRoomEntity.setPublicRoom(room.isPublicRoom());
mucRoomEntity.setPassword(room.getPassword());
mucRoomEntity.setPersistent(room.isPersistent());
mucRoomEntity.setRegistrationEnabled(room.isRegistrationEnabled());
mucRoomEntity.setLogEnabled(room.isLogEnabled());
mucRoomEntity.setLoginRestrictedToNickname(room.isLoginRestrictedToNickname());
mucRoomEntity.setMaxUsers(room.getMaxUsers());
mucRoomEntity.setMembersOnly(room.isMembersOnly());
mucRoomEntity.setModerated(room.isModerated());
ConcurrentGroupList<JID> owners = new ConcurrentGroupList<JID>(room.getOwners());
ConcurrentGroupList<JID> admins = new ConcurrentGroupList<JID>(room.getAdmins());
ConcurrentGroupList<JID> members = new ConcurrentGroupList<JID>(room.getMembers());
ConcurrentGroupList<JID> outcasts = new ConcurrentGroupList<JID>(room.getOutcasts());
if (expand) {
for(Group ownerGroup : owners.getGroups()) {
owners.addAllAbsent(ownerGroup.getAll());
}
for(Group adminGroup : admins.getGroups()) {
admins.addAllAbsent(adminGroup.getAll());
}
for(Group memberGroup : members.getGroups()) {
members.addAllAbsent(memberGroup.getAll());
}
for(Group outcastGroup : outcasts.getGroups()) {
outcasts.addAllAbsent(outcastGroup.getAll());
}
}
mucRoomEntity.setOwners(MUCRoomUtils.convertJIDsToStringList(owners));
mucRoomEntity.setAdmins(MUCRoomUtils.convertJIDsToStringList(admins));
mucRoomEntity.setMembers(MUCRoomUtils.convertJIDsToStringList(members));
mucRoomEntity.setOutcasts(MUCRoomUtils.convertJIDsToStringList(outcasts));
mucRoomEntity.setOwnerGroups(MUCRoomUtils.convertGroupsToStringList(owners.getGroups()));
mucRoomEntity.setAdminGroups(MUCRoomUtils.convertGroupsToStringList(admins.getGroups()));
mucRoomEntity.setMemberGroups(MUCRoomUtils.convertGroupsToStringList(members.getGroups()));
mucRoomEntity.setOutcastGroups(MUCRoomUtils.convertGroupsToStringList(outcasts.getGroups()));
mucRoomEntity.setBroadcastPresenceRoles(room.getRolesToBroadcastPresence());
mucRoomEntity.setCreationDate(room.getCreationDate());
mucRoomEntity.setModificationDate(room.getModificationDate());
return mucRoomEntity;
}
/**
* Reset roles.
*
* @param room
* the room
* @param mucRoomEntity
* the muc room entity
* @throws ForbiddenException
* the forbidden exception
* @throws NotAllowedException
* the not allowed exception
* @throws ConflictException
* the conflict exception
*/
private void setRoles(MUCRoom room, MUCRoomEntity mucRoomEntity) throws ForbiddenException, NotAllowedException,
ConflictException {
List<JID> roles = new ArrayList<JID>();
Collection<JID> owners = new ArrayList<JID>();
Collection<JID> existingOwners = new ArrayList<JID>();
List<JID> mucRoomEntityOwners = MUCRoomUtils.convertStringsToJIDs(mucRoomEntity.getOwners());
owners.addAll(room.getOwners());
// Find same owners
for (JID jid : owners) {
if (mucRoomEntityOwners.contains(jid)) {
existingOwners.add(jid);
}
}
// Don't delete the same owners
owners.removeAll(existingOwners);
room.addOwners(MUCRoomUtils.convertStringsToJIDs(mucRoomEntity.getOwners()), room.getRole());
// Collect all roles to reset
roles.addAll(owners);
roles.addAll(room.getAdmins());
roles.addAll(room.getMembers());
roles.addAll(room.getOutcasts());
for (JID jid : roles) {
room.addNone(jid, room.getRole());
}
room.addOwners(MUCRoomUtils.convertStringsToJIDs(mucRoomEntity.getOwners()), room.getRole());
if (mucRoomEntity.getAdmins() != null) {
room.addAdmins(MUCRoomUtils.convertStringsToJIDs(mucRoomEntity.getAdmins()), room.getRole());
}
if (mucRoomEntity.getMembers() != null) {
for (String memberJid : mucRoomEntity.getMembers()) {
room.addMember(new JID(memberJid), null, room.getRole());
}
}
if (mucRoomEntity.getOutcasts() != null) {
for (String outcastJid : mucRoomEntity.getOutcasts()) {
room.addOutcast(new JID(outcastJid), null, room.getRole());
}
}
}
/**
* Adds the admin.
*
* @param serviceName
* the service name
* @param roomName
* the room name
* @param jid
* the jid
* @throws ServiceException
* the service exception
*/
public void addAdmin(String serviceName, String roomName, String jid) throws ServiceException {
MUCRoom room = XMPPServer.getInstance().getMultiUserChatManager().getMultiUserChatService(serviceName)
.getChatRoom(roomName.toLowerCase());
try {
room.addAdmin(UserUtils.checkAndGetJID(jid), room.getRole());
} catch (ForbiddenException e) {
throw new ServiceException("Could not add admin", jid, ExceptionType.NOT_ALLOWED, Response.Status.FORBIDDEN, e);
} catch (ConflictException e) {
throw new ServiceException("Could not add admin", jid, ExceptionType.NOT_ALLOWED, Response.Status.CONFLICT, e);
}
}
/**
* Adds the owner.
*
* @param serviceName
* the service name
* @param roomName
* the room name
* @param jid
* the jid
* @throws ServiceException
* the service exception
*/
public void addOwner(String serviceName, String roomName, String jid) throws ServiceException {
MUCRoom room = XMPPServer.getInstance().getMultiUserChatManager().getMultiUserChatService(serviceName)
.getChatRoom(roomName.toLowerCase());
try {
room.addOwner(UserUtils.checkAndGetJID(jid), room.getRole());
} catch (ForbiddenException e) {
throw new ServiceException("Could not add owner", jid, ExceptionType.NOT_ALLOWED, Response.Status.FORBIDDEN, e);
}
}
/**
* Adds the member.
*
* @param serviceName
* the service name
* @param roomName
* the room name
* @param jid
* the jid
* @throws ServiceException
* the service exception
*/
public void addMember(String serviceName, String roomName, String jid) throws ServiceException {
MUCRoom room = XMPPServer.getInstance().getMultiUserChatManager().getMultiUserChatService(serviceName)
.getChatRoom(roomName.toLowerCase());
try {
room.addMember(UserUtils.checkAndGetJID(jid), null, room.getRole());
} catch (ForbiddenException e) {
throw new ServiceException("Could not add member", jid, ExceptionType.NOT_ALLOWED, Response.Status.FORBIDDEN, e);
} catch (ConflictException e) {
throw new ServiceException("Could not add member", jid, ExceptionType.NOT_ALLOWED, Response.Status.FORBIDDEN, e);
}
}
/**
* Adds the outcast.
*
* @param serviceName
* the service name
* @param roomName
* the room name
* @param jid
* the jid
* @throws ServiceException
* the service exception
*/
public void addOutcast(String serviceName, String roomName, String jid) throws ServiceException {
MUCRoom room = XMPPServer.getInstance().getMultiUserChatManager().getMultiUserChatService(serviceName)
.getChatRoom(roomName.toLowerCase());
try {
room.addOutcast(UserUtils.checkAndGetJID(jid), null, room.getRole());
} catch (NotAllowedException e) {
throw new ServiceException("Could not add outcast", jid, ExceptionType.NOT_ALLOWED, Response.Status.FORBIDDEN, e);
} catch (ForbiddenException e) {
throw new ServiceException("Could not add outcast", jid, ExceptionType.NOT_ALLOWED, Response.Status.FORBIDDEN, e);
} catch (ConflictException e) {
throw new ServiceException("Could not add outcast", jid, ExceptionType.NOT_ALLOWED, Response.Status.CONFLICT, e);
}
}
/**
* Delete affiliation.
*
* @param serviceName
* the service name
* @param roomName
* the room name
* @param jid
* the jid
* @throws ServiceException
* the service exception
*/
public void deleteAffiliation(String serviceName, String roomName, String jid) throws ServiceException {
MUCRoom room = XMPPServer.getInstance().getMultiUserChatManager().getMultiUserChatService(serviceName)
.getChatRoom(roomName.toLowerCase());
try {
room.addNone(UserUtils.checkAndGetJID(jid), room.getRole());
} catch (ForbiddenException e) {
throw new ServiceException("Could not delete affiliation", jid, ExceptionType.NOT_ALLOWED, Response.Status.FORBIDDEN, e);
} catch (ConflictException e) {
throw new ServiceException("Could not delete affiliation", jid, ExceptionType.NOT_ALLOWED, Response.Status.CONFLICT, e);
}
}
package org.jivesoftware.openfire.plugin.rest.controller;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import javax.ws.rs.core.Response;
import org.jivesoftware.openfire.XMPPServer;
import org.jivesoftware.openfire.cluster.ClusterManager;
import org.jivesoftware.openfire.plugin.rest.entity.MUCChannelType;
import org.jivesoftware.openfire.plugin.rest.entity.MUCRoomEntities;
import org.jivesoftware.openfire.plugin.rest.entity.MUCRoomEntity;
import org.jivesoftware.openfire.plugin.rest.entity.ParticipantEntities;
import org.jivesoftware.openfire.plugin.rest.entity.ParticipantEntity;
import org.jivesoftware.openfire.plugin.rest.exceptions.ExceptionType;
import org.jivesoftware.openfire.plugin.rest.exceptions.ServiceException;
import org.jivesoftware.openfire.muc.ConflictException;
import org.jivesoftware.openfire.muc.ForbiddenException;
import org.jivesoftware.openfire.muc.MUCRole;
import org.jivesoftware.openfire.muc.MUCRoom;
import org.jivesoftware.openfire.muc.NotAllowedException;
import org.jivesoftware.openfire.muc.cluster.RoomUpdatedEvent;
import org.jivesoftware.openfire.muc.spi.LocalMUCRoom;
import org.jivesoftware.openfire.group.ConcurrentGroupList;
import org.jivesoftware.openfire.group.Group;
import org.jivesoftware.openfire.plugin.rest.utils.MUCRoomUtils;
import org.jivesoftware.openfire.plugin.rest.utils.UserUtils;
import org.jivesoftware.util.AlreadyExistsException;
import org.jivesoftware.util.cache.CacheFactory;
import org.xmpp.packet.JID;
/**
* The Class MUCRoomController.
*/
public class MUCRoomController {
/** The Constant INSTANCE. */
public static final MUCRoomController INSTANCE = new MUCRoomController();
/**
* Gets the single instance of MUCRoomController.
*
* @return single instance of MUCRoomController
*/
public static MUCRoomController getInstance() {
return INSTANCE;
}
/**
* Gets the chat rooms.
*
* @param serviceName
* the service name
* @param channelType
* the channel type
* @param roomSearch
* the room search
* @return the chat rooms
*/
public MUCRoomEntities getChatRooms(String serviceName, String channelType, String roomSearch, boolean expand) {
List<MUCRoom> rooms = XMPPServer.getInstance().getMultiUserChatManager().getMultiUserChatService(serviceName)
.getChatRooms();
List<MUCRoomEntity> mucRoomEntities = new ArrayList<MUCRoomEntity>();
for (MUCRoom chatRoom : rooms) {
if (roomSearch != null) {
if (!chatRoom.getName().contains(roomSearch)) {
continue;
}
}
if (channelType.equals(MUCChannelType.ALL)) {
mucRoomEntities.add(convertToMUCRoomEntity(chatRoom, expand));
} else if (channelType.equals(MUCChannelType.PUBLIC) && chatRoom.isPublicRoom()) {
mucRoomEntities.add(convertToMUCRoomEntity(chatRoom, expand));
}
}
return new MUCRoomEntities(mucRoomEntities);
}
/**
* Gets the chat room.
*
* @param roomName
* the room name
* @param serviceName
* the service name
* @return the chat room
* @throws ServiceException
* the service exception
*/
public MUCRoomEntity getChatRoom(String roomName, String serviceName, boolean expand) throws ServiceException {
MUCRoom chatRoom = XMPPServer.getInstance().getMultiUserChatManager().getMultiUserChatService(serviceName)
.getChatRoom(roomName);
if (chatRoom == null) {
throw new ServiceException("Could not find the chat room", roomName, ExceptionType.ROOM_NOT_FOUND, Response.Status.NOT_FOUND);
}
MUCRoomEntity mucRoomEntity = convertToMUCRoomEntity(chatRoom, expand);
return mucRoomEntity;
}
/**
* Delete chat room.
*
* @param roomName
* the room name
* @param serviceName
* the service name
* @throws ServiceException
* the service exception
*/
public void deleteChatRoom(String roomName, String serviceName) throws ServiceException {
MUCRoom chatRoom = XMPPServer.getInstance().getMultiUserChatManager().getMultiUserChatService(serviceName)
.getChatRoom(roomName.toLowerCase());
if (chatRoom != null) {
chatRoom.destroyRoom(null, null);
} else {
throw new ServiceException("Could not remove the channel", roomName, ExceptionType.ROOM_NOT_FOUND, Response.Status.NOT_FOUND);
}
}
/**
* Creates the chat room.
*
* @param serviceName
* the service name
* @param mucRoomEntity
* the MUC room entity
* @throws ServiceException
* the service exception
*/
public void createChatRoom(String serviceName, MUCRoomEntity mucRoomEntity) throws ServiceException {
try {
createRoom(mucRoomEntity, serviceName);
} catch (NotAllowedException e) {
throw new ServiceException("Could not create the channel", mucRoomEntity.getRoomName(),
ExceptionType.NOT_ALLOWED, Response.Status.FORBIDDEN, e);
} catch (ForbiddenException e) {
throw new ServiceException("Could not create the channel", mucRoomEntity.getRoomName(),
ExceptionType.NOT_ALLOWED, Response.Status.FORBIDDEN, e);
} catch (ConflictException e) {
throw new ServiceException("Could not create the channel", mucRoomEntity.getRoomName(),
ExceptionType.NOT_ALLOWED, Response.Status.CONFLICT, e);
} catch (AlreadyExistsException e) {
throw new ServiceException("Could not create the channel", mucRoomEntity.getRoomName(),
ExceptionType.ALREADY_EXISTS, Response.Status.CONFLICT, e);
}
}
/**
* Update chat room.
*
* @param roomName
* the room name
* @param serviceName
* the service name
* @param mucRoomEntity
* the MUC room entity
* @throws ServiceException
* the service exception
*/
public void updateChatRoom(String roomName, String serviceName, MUCRoomEntity mucRoomEntity)
throws ServiceException {
try {
// If the room name is different throw exception
if (!roomName.equals(mucRoomEntity.getRoomName())) {
throw new ServiceException(
"Could not update the channel. The room name is different to the entity room name.", roomName,
ExceptionType.ILLEGAL_ARGUMENT_EXCEPTION, Response.Status.BAD_REQUEST);
}
createRoom(mucRoomEntity, serviceName);
} catch (NotAllowedException e) {
throw new ServiceException("Could not update the channel", roomName, ExceptionType.NOT_ALLOWED, Response.Status.FORBIDDEN, e);
} catch (ForbiddenException e) {
throw new ServiceException("Could not update the channel", roomName, ExceptionType.NOT_ALLOWED, Response.Status.FORBIDDEN, e);
} catch (ConflictException e) {
throw new ServiceException("Could not update the channel", roomName, ExceptionType.NOT_ALLOWED, Response.Status.CONFLICT, e);
} catch (AlreadyExistsException e) {
throw new ServiceException("Could not update the channel", mucRoomEntity.getRoomName(),
ExceptionType.ALREADY_EXISTS, Response.Status.CONFLICT, e);
}
}
/**
* Creates the room.
*
* @param mucRoomEntity
* the MUC room entity
* @param serviceName
* the service name
* @throws NotAllowedException
* the not allowed exception
* @throws ForbiddenException
* the forbidden exception
* @throws ConflictException
* the conflict exception
* @throws AlreadyExistsException
*/
private void createRoom(MUCRoomEntity mucRoomEntity, String serviceName) throws NotAllowedException,
ForbiddenException, ConflictException, AlreadyExistsException {
// Set owner
JID owner = XMPPServer.getInstance().createJID("admin", null);
if (mucRoomEntity.getOwners() != null && mucRoomEntity.getOwners().size() > 0) {
owner = new JID(mucRoomEntity.getOwners().get(0));
} else {
List<String> owners = new ArrayList<String>();
owners.add(owner.toBareJID());
mucRoomEntity.setOwners(owners);
}
// Check if chat service is available, if not create a new one
boolean serviceRegistered = XMPPServer.getInstance().getMultiUserChatManager().isServiceRegistered(serviceName);
if(!serviceRegistered) {
XMPPServer.getInstance().getMultiUserChatManager().createMultiUserChatService(serviceName, serviceName, false);
}
MUCRoom room = XMPPServer.getInstance().getMultiUserChatManager().getMultiUserChatService(serviceName)
.getChatRoom(mucRoomEntity.getRoomName().toLowerCase(), owner);
// Set values
room.setNaturalLanguageName(mucRoomEntity.getNaturalName());
room.setSubject(mucRoomEntity.getSubject());
room.setDescription(mucRoomEntity.getDescription());
room.setPassword(mucRoomEntity.getPassword());
room.setPersistent(mucRoomEntity.isPersistent());
room.setPublicRoom(mucRoomEntity.isPublicRoom());
room.setRegistrationEnabled(mucRoomEntity.isRegistrationEnabled());
room.setCanAnyoneDiscoverJID(mucRoomEntity.isCanAnyoneDiscoverJID());
room.setCanOccupantsChangeSubject(mucRoomEntity.isCanOccupantsChangeSubject());
room.setCanOccupantsInvite(mucRoomEntity.isCanOccupantsInvite());
room.setChangeNickname(mucRoomEntity.isCanChangeNickname());
room.setModificationDate(mucRoomEntity.getModificationDate());
room.setLogEnabled(mucRoomEntity.isLogEnabled());
room.setLoginRestrictedToNickname(mucRoomEntity.isLoginRestrictedToNickname());
room.setMaxUsers(mucRoomEntity.getMaxUsers());
room.setMembersOnly(mucRoomEntity.isMembersOnly());
room.setModerated(mucRoomEntity.isModerated());
// Fire RoomUpdateEvent if cluster is started
if (ClusterManager.isClusteringStarted()) {
CacheFactory.doClusterTask(new RoomUpdatedEvent((LocalMUCRoom) room));
}
// Set broadcast presence roles
if (mucRoomEntity.getBroadcastPresenceRoles() != null) {
room.setRolesToBroadcastPresence(mucRoomEntity.getBroadcastPresenceRoles());
} else {
room.setRolesToBroadcastPresence(new ArrayList<String>());
}
// Set all roles
setRoles(room, mucRoomEntity);
// Set creation date
if (mucRoomEntity.getCreationDate() != null) {
room.setCreationDate(mucRoomEntity.getCreationDate());
} else {
room.setCreationDate(new Date());
}
// Set modification date
if (mucRoomEntity.getModificationDate() != null) {
room.setModificationDate(mucRoomEntity.getModificationDate());
} else {
room.setModificationDate(new Date());
}
// Unlock the room, because the default configuration lock the room.
room.unlock(room.getRole());
// Save the room to the DB if the room should be persistant
if (room.isPersistent()) {
room.saveToDB();
}
}
/**
* Gets the room participants.
*
* @param roomName
* the room name
* @param serviceName
* the service name
* @return the room participants
*/
public ParticipantEntities getRoomParticipants(String roomName, String serviceName) {
ParticipantEntities participantEntities = new ParticipantEntities();
List<ParticipantEntity> participants = new ArrayList<ParticipantEntity>();
Collection<MUCRole> serverParticipants = XMPPServer.getInstance().getMultiUserChatManager()
.getMultiUserChatService(serviceName).getChatRoom(roomName).getParticipants();
for (MUCRole role : serverParticipants) {
ParticipantEntity participantEntity = new ParticipantEntity();
participantEntity.setJid(role.getRoleAddress().toFullJID());
participantEntity.setRole(role.getRole().name());
participantEntity.setAffiliation(role.getAffiliation().name());
participants.add(participantEntity);
}
participantEntities.setParticipants(participants);
return participantEntities;
}
/**
* Convert to MUC room entity.
*
* @param room
* the room
* @return the MUC room entity
*/
public MUCRoomEntity convertToMUCRoomEntity(MUCRoom room, boolean expand) {
MUCRoomEntity mucRoomEntity = new MUCRoomEntity(room.getNaturalLanguageName(), room.getName(),
room.getDescription());
mucRoomEntity.setSubject(room.getSubject());
mucRoomEntity.setCanAnyoneDiscoverJID(room.canAnyoneDiscoverJID());
mucRoomEntity.setCanChangeNickname(room.canChangeNickname());
mucRoomEntity.setCanOccupantsChangeSubject(room.canOccupantsChangeSubject());
mucRoomEntity.setCanOccupantsInvite(room.canOccupantsInvite());
mucRoomEntity.setPublicRoom(room.isPublicRoom());
mucRoomEntity.setPassword(room.getPassword());
mucRoomEntity.setPersistent(room.isPersistent());
mucRoomEntity.setRegistrationEnabled(room.isRegistrationEnabled());
mucRoomEntity.setLogEnabled(room.isLogEnabled());
mucRoomEntity.setLoginRestrictedToNickname(room.isLoginRestrictedToNickname());
mucRoomEntity.setMaxUsers(room.getMaxUsers());
mucRoomEntity.setMembersOnly(room.isMembersOnly());
mucRoomEntity.setModerated(room.isModerated());
ConcurrentGroupList<JID> owners = new ConcurrentGroupList<JID>(room.getOwners());
ConcurrentGroupList<JID> admins = new ConcurrentGroupList<JID>(room.getAdmins());
ConcurrentGroupList<JID> members = new ConcurrentGroupList<JID>(room.getMembers());
ConcurrentGroupList<JID> outcasts = new ConcurrentGroupList<JID>(room.getOutcasts());
if (expand) {
for(Group ownerGroup : owners.getGroups()) {
owners.addAllAbsent(ownerGroup.getAll());
}
for(Group adminGroup : admins.getGroups()) {
admins.addAllAbsent(adminGroup.getAll());
}
for(Group memberGroup : members.getGroups()) {
members.addAllAbsent(memberGroup.getAll());
}
for(Group outcastGroup : outcasts.getGroups()) {
outcasts.addAllAbsent(outcastGroup.getAll());
}
}
mucRoomEntity.setOwners(MUCRoomUtils.convertJIDsToStringList(owners));
mucRoomEntity.setAdmins(MUCRoomUtils.convertJIDsToStringList(admins));
mucRoomEntity.setMembers(MUCRoomUtils.convertJIDsToStringList(members));
mucRoomEntity.setOutcasts(MUCRoomUtils.convertJIDsToStringList(outcasts));
mucRoomEntity.setOwnerGroups(MUCRoomUtils.convertGroupsToStringList(owners.getGroups()));
mucRoomEntity.setAdminGroups(MUCRoomUtils.convertGroupsToStringList(admins.getGroups()));
mucRoomEntity.setMemberGroups(MUCRoomUtils.convertGroupsToStringList(members.getGroups()));
mucRoomEntity.setOutcastGroups(MUCRoomUtils.convertGroupsToStringList(outcasts.getGroups()));
mucRoomEntity.setBroadcastPresenceRoles(room.getRolesToBroadcastPresence());
mucRoomEntity.setCreationDate(room.getCreationDate());
mucRoomEntity.setModificationDate(room.getModificationDate());
return mucRoomEntity;
}
/**
* Reset roles.
*
* @param room
* the room
* @param mucRoomEntity
* the muc room entity
* @throws ForbiddenException
* the forbidden exception
* @throws NotAllowedException
* the not allowed exception
* @throws ConflictException
* the conflict exception
*/
private void setRoles(MUCRoom room, MUCRoomEntity mucRoomEntity) throws ForbiddenException, NotAllowedException,
ConflictException {
List<JID> roles = new ArrayList<JID>();
Collection<JID> owners = new ArrayList<JID>();
Collection<JID> existingOwners = new ArrayList<JID>();
List<JID> mucRoomEntityOwners = MUCRoomUtils.convertStringsToJIDs(mucRoomEntity.getOwners());
owners.addAll(room.getOwners());
// Find same owners
for (JID jid : owners) {
if (mucRoomEntityOwners.contains(jid)) {
existingOwners.add(jid);
}
}
// Don't delete the same owners
owners.removeAll(existingOwners);
room.addOwners(MUCRoomUtils.convertStringsToJIDs(mucRoomEntity.getOwners()), room.getRole());
// Collect all roles to reset
roles.addAll(owners);
roles.addAll(room.getAdmins());
roles.addAll(room.getMembers());
roles.addAll(room.getOutcasts());
for (JID jid : roles) {
room.addNone(jid, room.getRole());
}
room.addOwners(MUCRoomUtils.convertStringsToJIDs(mucRoomEntity.getOwners()), room.getRole());
if (mucRoomEntity.getAdmins() != null) {
room.addAdmins(MUCRoomUtils.convertStringsToJIDs(mucRoomEntity.getAdmins()), room.getRole());
}
if (mucRoomEntity.getMembers() != null) {
for (String memberJid : mucRoomEntity.getMembers()) {
room.addMember(new JID(memberJid), null, room.getRole());
}
}
if (mucRoomEntity.getOutcasts() != null) {
for (String outcastJid : mucRoomEntity.getOutcasts()) {
room.addOutcast(new JID(outcastJid), null, room.getRole());
}
}
}
/**
* Adds the admin.
*
* @param serviceName
* the service name
* @param roomName
* the room name
* @param jid
* the jid
* @throws ServiceException
* the service exception
*/
public void addAdmin(String serviceName, String roomName, String jid) throws ServiceException {
MUCRoom room = XMPPServer.getInstance().getMultiUserChatManager().getMultiUserChatService(serviceName)
.getChatRoom(roomName.toLowerCase());
try {
room.addAdmin(UserUtils.checkAndGetJID(jid), room.getRole());
} catch (ForbiddenException e) {
throw new ServiceException("Could not add admin", jid, ExceptionType.NOT_ALLOWED, Response.Status.FORBIDDEN, e);
} catch (ConflictException e) {
throw new ServiceException("Could not add admin", jid, ExceptionType.NOT_ALLOWED, Response.Status.CONFLICT, e);
}
}
/**
* Adds the owner.
*
* @param serviceName
* the service name
* @param roomName
* the room name
* @param jid
* the jid
* @throws ServiceException
* the service exception
*/
public void addOwner(String serviceName, String roomName, String jid) throws ServiceException {
MUCRoom room = XMPPServer.getInstance().getMultiUserChatManager().getMultiUserChatService(serviceName)
.getChatRoom(roomName.toLowerCase());
try {
room.addOwner(UserUtils.checkAndGetJID(jid), room.getRole());
} catch (ForbiddenException e) {
throw new ServiceException("Could not add owner", jid, ExceptionType.NOT_ALLOWED, Response.Status.FORBIDDEN, e);
}
}
/**
* Adds the member.
*
* @param serviceName
* the service name
* @param roomName
* the room name
* @param jid
* the jid
* @throws ServiceException
* the service exception
*/
public void addMember(String serviceName, String roomName, String jid) throws ServiceException {
MUCRoom room = XMPPServer.getInstance().getMultiUserChatManager().getMultiUserChatService(serviceName)
.getChatRoom(roomName.toLowerCase());
try {
room.addMember(UserUtils.checkAndGetJID(jid), null, room.getRole());
} catch (ForbiddenException e) {
throw new ServiceException("Could not add member", jid, ExceptionType.NOT_ALLOWED, Response.Status.FORBIDDEN, e);
} catch (ConflictException e) {
throw new ServiceException("Could not add member", jid, ExceptionType.NOT_ALLOWED, Response.Status.FORBIDDEN, e);
}
}
/**
* Adds the outcast.
*
* @param serviceName
* the service name
* @param roomName
* the room name
* @param jid
* the jid
* @throws ServiceException
* the service exception
*/
public void addOutcast(String serviceName, String roomName, String jid) throws ServiceException {
MUCRoom room = XMPPServer.getInstance().getMultiUserChatManager().getMultiUserChatService(serviceName)
.getChatRoom(roomName.toLowerCase());
try {
room.addOutcast(UserUtils.checkAndGetJID(jid), null, room.getRole());
} catch (NotAllowedException e) {
throw new ServiceException("Could not add outcast", jid, ExceptionType.NOT_ALLOWED, Response.Status.FORBIDDEN, e);
} catch (ForbiddenException e) {
throw new ServiceException("Could not add outcast", jid, ExceptionType.NOT_ALLOWED, Response.Status.FORBIDDEN, e);
} catch (ConflictException e) {
throw new ServiceException("Could not add outcast", jid, ExceptionType.NOT_ALLOWED, Response.Status.CONFLICT, e);
}
}
/**
* Delete affiliation.
*
* @param serviceName
* the service name
* @param roomName
* the room name
* @param jid
* the jid
* @throws ServiceException
* the service exception
*/
public void deleteAffiliation(String serviceName, String roomName, String jid) throws ServiceException {
MUCRoom room = XMPPServer.getInstance().getMultiUserChatManager().getMultiUserChatService(serviceName)
.getChatRoom(roomName.toLowerCase());
try {
room.addNone(UserUtils.checkAndGetJID(jid), room.getRole());
} catch (ForbiddenException e) {
throw new ServiceException("Could not delete affiliation", jid, ExceptionType.NOT_ALLOWED, Response.Status.FORBIDDEN, e);
} catch (ConflictException e) {
throw new ServiceException("Could not delete affiliation", jid, ExceptionType.NOT_ALLOWED, Response.Status.CONFLICT, e);
}
}
}
\ No newline at end of file
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