Commit d7eade45 authored by daryl herzmann's avatar daryl herzmann

Merge pull request #72 from Redor/master

MUC Service Plugin update to 0.2.2
parents 5110ec0f 72898bc7
......@@ -44,6 +44,11 @@
MUC Service Plugin Changelog
</h1>
<p><b>0.2.2</b> -- 09.17.2014</p>
<ul>
<li>Room user roles can now be added and removed individually</li>
</ul>
<p><b>0.2.1</b> -- 08.09.2014</p>
<ul>
<li>Creation and modification dates, are now optional</li>
......
......@@ -5,7 +5,7 @@
<name>MUC Service</name>
<description>MUC administration over REST Interface</description>
<author>Roman Soldatow</author>
<version>0.2.1</version>
<date>08.09.2014</date>
<version>0.2.2</version>
<date>09.17.2014</date>
<minServerVersion>3.9.1</minServerVersion>
</plugin>
This diff is collapsed.
......@@ -6,8 +6,14 @@ import java.util.List;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
@XmlRootElement(name = "chatRoom")
@XmlType(propOrder = { "roomName", "naturalName", "description", "password", "subject", "creationDate",
"modificationDate", "maxUsers", "persistent", "publicRoom", "registrationEnabled", "canAnyoneDiscoverJID",
"canOccupantsChangeSubject", "canOccupantsInvite", "canChangeNickname", "logEnabled",
"loginRestrictedToNickname", "membersOnly", "moderated", "broadcastPresenceRoles", "owners", "admins",
"members", "outcasts" })
public class MUCRoomEntity {
private String roomName;
......
......@@ -18,6 +18,8 @@ import org.jivesoftware.openfire.muc.MUCRole;
import org.jivesoftware.openfire.muc.MUCRoom;
import org.jivesoftware.openfire.muc.NotAllowedException;
import org.jivesoftware.openfire.utils.MUCRoomUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xmpp.packet.JID;
/**
......@@ -25,6 +27,8 @@ import org.xmpp.packet.JID;
*/
public class MUCRoomController {
/** The Constant LOG. */
private static final Logger LOG = LoggerFactory.getLogger(MUCRoomController.class);
/** The Constant INSTANCE. */
public static final MUCRoomController INSTANCE = new MUCRoomController();
......@@ -106,7 +110,7 @@ public class MUCRoomController {
*/
public void deleteChatRoom(String roomName, String serviceName) throws MUCServiceException {
MUCRoom chatRoom = XMPPServer.getInstance().getMultiUserChatManager().getMultiUserChatService(serviceName)
.getChatRoom(roomName);
.getChatRoom(roomName.toLowerCase());
if (chatRoom != null) {
chatRoom.destroyRoom(null, null);
......@@ -221,8 +225,12 @@ public class MUCRoomController {
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);
......@@ -373,4 +381,134 @@ public class MUCRoomController {
}
}
}
/**
* Adds the admin.
*
* @param serviceName
* the service name
* @param roomName
* the room name
* @param jid
* the jid
* @throws MUCServiceException
* the MUC service exception
*/
public void addAdmin(String serviceName, String roomName, String jid) throws MUCServiceException {
MUCRoom room = XMPPServer.getInstance().getMultiUserChatManager().getMultiUserChatService(serviceName)
.getChatRoom(roomName.toLowerCase());
try {
room.addAdmin(new JID(jid), room.getRole());
} catch (ForbiddenException e) {
LOG.error("Could not add admin", e);
throw new MUCServiceException("Could not add admin", jid, "ForbiddenException");
} catch (ConflictException e) {
LOG.error("Could not add admin", e);
throw new MUCServiceException("Could not add admin", jid, "ConflictException");
}
}
/**
* Adds the owner.
*
* @param serviceName
* the service name
* @param roomName
* the room name
* @param jid
* the jid
* @throws MUCServiceException
* the MUC service exception
*/
public void addOwner(String serviceName, String roomName, String jid) throws MUCServiceException {
MUCRoom room = XMPPServer.getInstance().getMultiUserChatManager().getMultiUserChatService(serviceName)
.getChatRoom(roomName.toLowerCase());
try {
room.addOwner(new JID(jid), room.getRole());
} catch (ForbiddenException e) {
LOG.error("Could not add owner", e);
throw new MUCServiceException("Could not add owner", jid, "ForbiddenException");
}
}
/**
* Adds the member.
*
* @param serviceName
* the service name
* @param roomName
* the room name
* @param jid
* the jid
* @throws MUCServiceException
* the MUC service exception
*/
public void addMember(String serviceName, String roomName, String jid) throws MUCServiceException {
MUCRoom room = XMPPServer.getInstance().getMultiUserChatManager().getMultiUserChatService(serviceName)
.getChatRoom(roomName.toLowerCase());
try {
room.addMember(new JID(jid), null, room.getRole());
} catch (ForbiddenException e) {
LOG.error("Could not add member", e);
throw new MUCServiceException("Could not add member", jid, "ForbiddenException");
} catch (ConflictException e) {
LOG.error("Could not add member", e);
throw new MUCServiceException("Could not add member", jid, "ConflictException");
}
}
/**
* Adds the outcast.
*
* @param serviceName
* the service name
* @param roomName
* the room name
* @param jid
* the jid
* @throws MUCServiceException
* the MUC service exception
*/
public void addOutcast(String serviceName, String roomName, String jid) throws MUCServiceException {
MUCRoom room = XMPPServer.getInstance().getMultiUserChatManager().getMultiUserChatService(serviceName)
.getChatRoom(roomName.toLowerCase());
try {
room.addOutcast(new JID(jid), null, room.getRole());
} catch (NotAllowedException e) {
LOG.error("Could not add outcast", e);
throw new MUCServiceException("Could not add outcast", jid, "NotAllowedException");
} catch (ForbiddenException e) {
LOG.error("Could not add outcast", e);
throw new MUCServiceException("Could not add outcast", jid, "ForbiddenException");
} catch (ConflictException e) {
LOG.error("Could not add outcast", e);
throw new MUCServiceException("Could not add outcast", jid, "ConflictException");
}
}
/**
* Delete affiliation.
*
* @param serviceName
* the service name
* @param roomName
* the room name
* @param jid
* the jid
* @throws MUCServiceException
* the MUC service exception
*/
public void deleteAffiliation(String serviceName, String roomName, String jid) throws MUCServiceException {
MUCRoom room = XMPPServer.getInstance().getMultiUserChatManager().getMultiUserChatService(serviceName)
.getChatRoom(roomName.toLowerCase());
try {
room.addNone(new JID(jid), room.getRole());
} catch (ForbiddenException e) {
LOG.error("Could not delete affiliation", e);
throw new MUCServiceException("Could not delete affiliation", jid, "ForbiddenException");
} catch (ConflictException e) {
LOG.error("Could not delete affiliation", e);
throw new MUCServiceException("Could not delete affiliation", jid, "ConflictException");
}
}
}
\ No newline at end of file
......@@ -7,6 +7,10 @@ import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import org.jivesoftware.admin.AuthCheckFilter;
import org.jivesoftware.openfire.service.MUCRoomAdminsService;
import org.jivesoftware.openfire.service.MUCRoomMembersService;
import org.jivesoftware.openfire.service.MUCRoomOutcastsService;
import org.jivesoftware.openfire.service.MUCRoomOwnersService;
import org.jivesoftware.openfire.service.MUCRoomService;
import com.sun.jersey.api.core.PackagesResourceConfig;
......@@ -46,6 +50,11 @@ public class JerseyWrapper extends ServletContainer {
prc.getProperties().put("com.sun.jersey.spi.container.ContainerRequestFilters",
"org.jivesoftware.openfire.plugin.servlet.AuthFilter");
prc.getClasses().add(MUCRoomService.class);
prc.getClasses().add(MUCRoomOwnersService.class);
prc.getClasses().add(MUCRoomAdminsService.class);
prc.getClasses().add(MUCRoomMembersService.class);
prc.getClasses().add(MUCRoomOutcastsService.class);
prc.getClasses().add(RESTExceptionMapper.class);
}
......
package org.jivesoftware.openfire.service;
import javax.ws.rs.DELETE;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import org.jivesoftware.openfire.exception.MUCServiceException;
import org.jivesoftware.openfire.plugin.MUCRoomController;
@Path("mucservice/chatrooms/{roomName}/admins")
public class MUCRoomAdminsService {
@POST
@Path("/{jid}")
public Response addMUCRoomAdmin(@DefaultValue("conference") @QueryParam("servicename") String serviceName,
@PathParam("jid") String jid, @PathParam("roomName") String roomName) throws MUCServiceException {
MUCRoomController.getInstance().addAdmin(serviceName, roomName, jid);
return Response.status(Status.CREATED).build();
}
@DELETE
@Path("/{jid}")
public Response deleteMUCRoomAdmin(@PathParam("jid") String jid,
@DefaultValue("conference") @QueryParam("servicename") String serviceName,
@PathParam("roomName") String roomName) throws MUCServiceException {
MUCRoomController.getInstance().deleteAffiliation(serviceName, roomName, jid);
return Response.status(Status.OK).build();
}
}
package org.jivesoftware.openfire.service;
import javax.ws.rs.DELETE;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import org.jivesoftware.openfire.exception.MUCServiceException;
import org.jivesoftware.openfire.plugin.MUCRoomController;
@Path("mucservice/chatrooms/{roomName}/members")
public class MUCRoomMembersService {
@POST
@Path("/{jid}")
public Response addMUCRoomMember(@DefaultValue("conference") @QueryParam("servicename") String serviceName,
@PathParam("jid") String jid, @PathParam("roomName") String roomName) throws MUCServiceException {
MUCRoomController.getInstance().addMember(serviceName, roomName, jid);
return Response.status(Status.CREATED).build();
}
@DELETE
@Path("/{jid}")
public Response deleteMUCRoomMember(@PathParam("jid") String jid,
@DefaultValue("conference") @QueryParam("servicename") String serviceName,
@PathParam("roomName") String roomName) throws MUCServiceException {
MUCRoomController.getInstance().deleteAffiliation(serviceName, roomName, jid);
return Response.status(Status.OK).build();
}
}
package org.jivesoftware.openfire.service;
import javax.ws.rs.DELETE;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import org.jivesoftware.openfire.exception.MUCServiceException;
import org.jivesoftware.openfire.plugin.MUCRoomController;
@Path("mucservice/chatrooms/{roomName}/outcasts")
public class MUCRoomOutcastsService {
@POST
@Path("/{jid}")
public Response addMUCRoomOutcast(@DefaultValue("conference") @QueryParam("servicename") String serviceName,
@PathParam("jid") String jid, @PathParam("roomName") String roomName) throws MUCServiceException {
MUCRoomController.getInstance().addOutcast(serviceName, roomName, jid);
return Response.status(Status.CREATED).build();
}
@DELETE
@Path("/{jid}")
public Response deleteMUCRoomOutcast(@PathParam("jid") String jid,
@DefaultValue("conference") @QueryParam("servicename") String serviceName,
@PathParam("roomName") String roomName) throws MUCServiceException {
MUCRoomController.getInstance().deleteAffiliation(serviceName, roomName, jid);
return Response.status(Status.OK).build();
}
}
package org.jivesoftware.openfire.service;
import javax.ws.rs.DELETE;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import org.jivesoftware.openfire.exception.MUCServiceException;
import org.jivesoftware.openfire.plugin.MUCRoomController;
@Path("mucservice/chatrooms/{roomName}/owners")
public class MUCRoomOwnersService {
@POST
@Path("/{jid}")
public Response addMUCRoomOwner(@DefaultValue("conference") @QueryParam("servicename") String serviceName,
@PathParam("jid") String jid, @PathParam("roomName") String roomName) throws MUCServiceException {
MUCRoomController.getInstance().addOwner(serviceName, roomName, jid);
return Response.status(Status.CREATED).build();
}
@DELETE
@Path("/{jid}")
public Response deleteMUCRoomOwner(@PathParam("jid") String jid,
@DefaultValue("conference") @QueryParam("servicename") String serviceName,
@PathParam("roomName") String roomName) throws MUCServiceException {
MUCRoomController.getInstance().deleteAffiliation(serviceName, roomName, jid);
return Response.status(Status.OK).build();
}
}
......@@ -10,6 +10,8 @@ import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import org.jivesoftware.openfire.entity.MUCChannelType;
import org.jivesoftware.openfire.entity.MUCRoomEntities;
......@@ -39,30 +41,33 @@ public class MUCRoomService {
@DELETE
@Path("/{roomName}")
public void deleteMUCRoom(@PathParam("roomName") String roomName,
public Response deleteMUCRoom(@PathParam("roomName") String roomName,
@DefaultValue("conference") @QueryParam("servicename") String serviceName) throws MUCServiceException {
MUCRoomController.getInstance().deleteChatRoom(roomName, serviceName);
return Response.status(Status.OK).build();
}
@POST
public void createMUCRoom(@DefaultValue("conference") @QueryParam("servicename") String serviceName,
public Response createMUCRoom(@DefaultValue("conference") @QueryParam("servicename") String serviceName,
MUCRoomEntity mucRoomEntity) throws MUCServiceException {
MUCRoomController.getInstance().createChatRoom(serviceName, mucRoomEntity);
return Response.status(Status.CREATED).build();
}
@PUT
@Path("/{roomName}")
public void udpateMUCRoom(@PathParam("roomName") String roomName,
public Response udpateMUCRoom(@PathParam("roomName") String roomName,
@DefaultValue("conference") @QueryParam("servicename") String serviceName, MUCRoomEntity mucRoomEntity)
throws MUCServiceException {
MUCRoomController.getInstance().updateChatRoom(roomName, serviceName, mucRoomEntity);
return Response.status(Status.OK).build();
}
@GET
@Path("/{roomName}/participants")
@Produces(MediaType.APPLICATION_XML)
public ParticipantEntities getMUCRoomParticipants(@PathParam("roomName") String roomName,
@DefaultValue("conference") @QueryParam("servicename") String serviceName) throws MUCServiceException {
@DefaultValue("conference") @QueryParam("servicename") String serviceName) {
return MUCRoomController.getInstance().getRoomParticipants(roomName, serviceName);
}
}
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