Commit 757bb674 authored by daryl herzmann's avatar daryl herzmann

Merge pull request #292 from Redor/master

Updated the REST API plugin to 1.1.6
parents 6f732813 c6435b62
......@@ -44,6 +44,12 @@
REST API Plugin Changelog
</h1>
<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>
......
......@@ -5,8 +5,8 @@
<name>REST API</name>
<description>Allows administration over a RESTful API.</description>
<author>Roman Soldatow</author>
<version>1.1.5</version>
<date>09/01/2015</date>
<version>1.1.6</version>
<date>09/24/2015</date>
<minServerVersion>3.9.0</minServerVersion>
<adminconsole>
......
......@@ -1292,73 +1292,83 @@ body.pdf{font-family:"DejaVu Sans"}body.pdf code,body.pdf pre{font-family:"DejaV
<li><a href="#examples-5">Examples</a></li>
</ul>
</li>
<li><a href="#add-user-to-group">Add user to group</a><ul>
<li><a href="#add-user-to-groups">Add user to groups</a><ul>
<li><a href="#possible-parameters-5">Possible parameters</a></li>
<li><a href="#examples-6">Examples</a></li>
</ul>
</li>
<li><a href="#delete-a-user-from-a-group">Delete a user from a group</a><ul>
<li><a href="#add-user-to-group">Add user to group</a><ul>
<li><a href="#possible-parameters-6">Possible parameters</a></li>
<li><a href="#examples-7">Examples</a></li>
</ul>
</li>
<li><a href="#lockout-a-user">Lockout a user</a><ul>
<li><a href="#delete-a-user-from-a-groups">Delete a user from a groups</a><ul>
<li><a href="#possible-parameters-7">Possible parameters</a></li>
<li><a href="#examples-8">Examples</a></li>
</ul>
</li>
<li><a href="#unlock-a-user">Unlock a user</a><ul>
<li><a href="#delete-a-user-from-a-group">Delete a user from a group</a><ul>
<li><a href="#possible-parameters-8">Possible parameters</a></li>
<li><a href="#examples-9">Examples</a></li>
</ul>
</li>
<li><a href="#retrieve-user-roster">Retrieve user roster</a><ul>
<li><a href="#lockout-a-user">Lockout a user</a><ul>
<li><a href="#possible-parameters-8-1">Possible parameters</a></li>
<li><a href="#examples-9-1">Examples</a></li>
</ul>
</li>
<li><a href="#unlock-a-user">Unlock a user</a><ul>
<li><a href="#possible-parameters-9">Possible parameters</a></li>
<li><a href="#examples-10">Examples</a></li>
</ul>
</li>
<li><a href="#create-a-user-roster-entry">Create a user roster entry</a><ul>
<li><a href="#retrieve-user-roster">Retrieve user roster</a><ul>
<li><a href="#possible-parameters-10">Possible parameters</a></li>
<li><a href="#examples-11">Examples</a></li>
</ul>
</li>
<li><a href="#delete-a-user-roster-entry">Delete a user roster entry</a><ul>
<li><a href="#create-a-user-roster-entry">Create a user roster entry</a><ul>
<li><a href="#possible-parameters-11">Possible parameters</a></li>
<li><a href="#examples-12">Examples</a></li>
</ul>
</li>
<li><a href="#update-a-user-roster-entry">Update a user roster entry</a><ul>
<li><a href="#delete-a-user-roster-entry">Delete a user roster entry</a><ul>
<li><a href="#possible-parameters-12">Possible parameters</a></li>
<li><a href="#examples-13">Examples</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#chat-room-related-rest-endpoints">Chat room related REST Endpoints</a><ul>
<li><a href="#retrieve-all-chat-rooms">Retrieve all chat rooms</a><ul>
<li><a href="#update-a-user-roster-entry">Update a user roster entry</a><ul>
<li><a href="#possible-parameters-13">Possible parameters</a></li>
<li><a href="#examples-14">Examples</a></li>
</ul>
</li>
<li><a href="#retrieve-a-chat-room">Retrieve a chat room</a><ul>
</ul>
</li>
<li><a href="#chat-room-related-rest-endpoints">Chat room related REST Endpoints</a><ul>
<li><a href="#retrieve-all-chat-rooms">Retrieve all chat rooms</a><ul>
<li><a href="#possible-parameters-14">Possible parameters</a></li>
<li><a href="#examples-15">Examples</a></li>
</ul>
</li>
<li><a href="#retrieve-chat-room-participants">Retrieve chat room participants</a><ul>
<li><a href="#retrieve-a-chat-room">Retrieve a chat room</a><ul>
<li><a href="#possible-parameters-15">Possible parameters</a></li>
<li><a href="#examples-16">Examples</a></li>
</ul>
</li>
<li><a href="#create-a-chat-room">Create a chat room</a><ul>
<li><a href="#retrieve-chat-room-participants">Retrieve chat room participants</a><ul>
<li><a href="#possible-parameters-16">Possible parameters</a></li>
<li><a href="#examples-17">Examples</a></li>
</ul>
</li>
<li><a href="#create-a-chat-room">Create a chat room</a><ul>
<li><a href="#possible-parameters-17">Possible parameters</a></li>
<li><a href="#xml-examples-1">XML Examples</a></li>
<li><a href="#json-examples-1">JSON Examples</a></li>
</ul>
</li>
<li><a href="#delete-a-chat-room">Delete a chat room</a><ul>
<li><a href="#possible-parameters-17">Possible parameters</a></li>
<li><a href="#examples-17">Examples</a></li>
<li><a href="#possible-parameters-17-1">Possible parameters</a></li>
<li><a href="#examples-17-1">Examples</a></li>
</ul>
</li>
<li><a href="#update-a-chat-room">Update a chat room</a><ul>
......@@ -1485,6 +1495,8 @@ body.pdf{font-family:"DejaVu Sans"}body.pdf code,body.pdf pre{font-family:"DejaV
<li>Send broadcast message to all online users</li>
</ul>
<h2 id="available-rest-api-clients">Available REST API clients</h2>
<p>REST API clients are implementations of the REST API in a specific programming language.</p>
......@@ -2322,9 +2334,9 @@ If you want to create a resource with JSON data format, please add “<strong>Co
<h2 id="add-user-to-group">Add user to group</h2>
<h2 id="add-user-to-groups">Add user to groups</h2>
<p>Endpoint to add user to a group(s)</p>
<p>Endpoint to add user to a groups</p>
<blockquote>
<p><strong>POST</strong> /users/{username}/groups</p>
......@@ -2333,8 +2345,6 @@ If you want to create a resource with JSON data format, please add “<strong>Co
<p><strong>Payload:</strong> Groups <br>
<strong>Return value:</strong> HTTP status 201 (Created)</p>
<h3 id="possible-parameters-5">Possible parameters</h3>
<table>
......@@ -2378,9 +2388,55 @@ If you want to create a resource with JSON data format, please add “<strong>Co
<h2 id="delete-a-user-from-a-group">Delete a user from a group</h2>
<h2 id="add-user-to-group">Add user to group</h2>
<p>Endpoint to remove a user from a group(s)</p>
<p>Endpoint to add user to a group</p>
<blockquote>
<p><strong>POST</strong> /users/{username}/groups/{groupName}</p>
</blockquote>
<p><strong>Payload:</strong> none <br>
<strong>Return value:</strong> HTTP status 201 (Created)</p>
<h3 id="possible-parameters-6">Possible parameters</h3>
<table>
<thead>
<tr>
<th>Parameter</th>
<th>Parameter Type</th>
<th>Description</th>
<th>Default value</th>
</tr>
</thead>
<tbody><tr>
<td>username</td>
<td>@Path</td>
<td>Exact username</td>
<td></td>
</tr>
<tr>
<td>groupName</td>
<td>@Path</td>
<td>Exact group name</td>
<td></td>
</tr>
</tbody></table>
<h3 id="examples-7">Examples</h3>
<blockquote>
<p><strong>Header:</strong> Authorization: Basic YWRtaW46MTIzNDU= <br>
<strong>Header:</strong> Content-Type application/xml</p>
<p><strong>POST</strong> <a href="http://example.org:9090/plugins/restapi/v1/users/testuser/groups/testGroup">http://example.org:9090/plugins/restapi/v1/users/testuser/groups/testGroup</a></p>
</blockquote>
<h2 id="delete-a-user-from-a-groups">Delete a user from a groups</h2>
<p>Endpoint to remove a user from a groups</p>
<blockquote>
<p><strong>DELETE</strong> /users/{username}/groups</p>
......@@ -2389,9 +2445,7 @@ If you want to create a resource with JSON data format, please add “<strong>Co
<p><strong>Payload:</strong> Groups <br>
<strong>Return value:</strong> HTTP status 200 (OK)</p>
<h3 id="possible-parameters-6">Possible parameters</h3>
<h3 id="possible-parameters-7">Possible parameters</h3>
<table>
<thead>
......@@ -2413,7 +2467,7 @@ If you want to create a resource with JSON data format, please add “<strong>Co
<h3 id="examples-7">Examples</h3>
<h3 id="examples-8">Examples</h3>
<blockquote>
<p><strong>Header:</strong> Authorization: Basic YWRtaW46MTIzNDU= <br>
......@@ -2434,6 +2488,52 @@ If you want to create a resource with JSON data format, please add “<strong>Co
<h2 id="delete-a-user-from-a-group">Delete a user from a group</h2>
<p>Endpoint to remove a user from a group</p>
<blockquote>
<p><strong>DELETE</strong> /users/{username}/groups/{groupName}</p>
</blockquote>
<p><strong>Payload:</strong> none <br>
<strong>Return value:</strong> HTTP status 200 (OK)</p>
<h3 id="possible-parameters-8">Possible parameters</h3>
<table>
<thead>
<tr>
<th>Parameter</th>
<th>Parameter Type</th>
<th>Description</th>
<th>Default value</th>
</tr>
</thead>
<tbody><tr>
<td>username</td>
<td>@Path</td>
<td>Exact username</td>
<td></td>
</tr>
<tr>
<td>groupName</td>
<td>@Path</td>
<td>Exact group name</td>
<td></td>
</tr>
</tbody></table>
<h3 id="examples-9">Examples</h3>
<blockquote>
<p><strong>Header:</strong> Authorization: Basic YWRtaW46MTIzNDU= <br>
<strong>Header:</strong> Content-Type application/xml</p>
<p><strong>DELETE</strong> <a href="http://example.org:9090/plugins/restapi/v1/users/testuser/groups/testGroup">http://example.org:9090/plugins/restapi/v1/users/testuser/groups/testGroup</a></p>
</blockquote>
<h2 id="lockout-a-user">Lockout a user</h2>
<p>Endpoint to lockout / ban the user from the chat server. The user will be kicked if the user is online.</p>
......@@ -2447,7 +2547,7 @@ If you want to create a resource with JSON data format, please add “<strong>Co
<h3 id="possible-parameters-7">Possible parameters</h3>
<h3 id="possible-parameters-8">Possible parameters</h3>
<table>
<thead>
......@@ -2469,7 +2569,7 @@ If you want to create a resource with JSON data format, please add “<strong>Co
<h3 id="examples-8">Examples</h3>
<h3 id="examples-9">Examples</h3>
<blockquote>
<p><strong>Header:</strong> Authorization: Basic YWRtaW46MTIzNDU=</p>
......@@ -2492,7 +2592,7 @@ If you want to create a resource with JSON data format, please add “<strong>Co
<h3 id="possible-parameters-8">Possible parameters</h3>
<h3 id="possible-parameters-9">Possible parameters</h3>
<table>
<thead>
......@@ -2514,7 +2614,7 @@ If you want to create a resource with JSON data format, please add “<strong>Co
<h3 id="examples-9">Examples</h3>
<h3 id="examples-10">Examples</h3>
<blockquote>
<p><strong>Header:</strong> Authorization: Basic YWRtaW46MTIzNDU=</p>
......@@ -2537,7 +2637,7 @@ If you want to create a resource with JSON data format, please add “<strong>Co
<h3 id="possible-parameters-9">Possible parameters</h3>
<h3 id="possible-parameters-10">Possible parameters</h3>
<table>
<thead>
......@@ -2559,7 +2659,7 @@ If you want to create a resource with JSON data format, please add “<strong>Co
<h3 id="examples-10">Examples</h3>
<h3 id="examples-11">Examples</h3>
<blockquote>
<p><strong>Header:</strong> Authorization: Basic YWRtaW46MTIzNDU=</p>
......@@ -2582,7 +2682,7 @@ If you want to create a resource with JSON data format, please add “<strong>Co
<h3 id="possible-parameters-10">Possible parameters</h3>
<h3 id="possible-parameters-11">Possible parameters</h3>
<table>
<thead>
......@@ -2604,7 +2704,7 @@ If you want to create a resource with JSON data format, please add “<strong>Co
<h3 id="examples-11">Examples</h3>
<h3 id="examples-12">Examples</h3>
<blockquote>
<p><strong>Header:</strong> Authorization: Basic YWRtaW46MTIzNDU= <br>
......@@ -2652,7 +2752,7 @@ Payload Example 1 (required parameters):</p>
<h3 id="possible-parameters-11">Possible parameters</h3>
<h3 id="possible-parameters-12">Possible parameters</h3>
<table>
<thead>
......@@ -2680,7 +2780,7 @@ Payload Example 1 (required parameters):</p>
<h3 id="examples-12">Examples</h3>
<h3 id="examples-13">Examples</h3>
<blockquote>
<p><strong>Header:</strong> Authorization: Basic YWRtaW46MTIzNDU=</p>
......@@ -2703,7 +2803,7 @@ Payload Example 1 (required parameters):</p>
<h3 id="possible-parameters-12">Possible parameters</h3>
<h3 id="possible-parameters-13">Possible parameters</h3>
<table>
<thead>
......@@ -2731,7 +2831,7 @@ Payload Example 1 (required parameters):</p>
<h3 id="examples-13">Examples</h3>
<h3 id="examples-14">Examples</h3>
<blockquote>
<p><strong>Header:</strong> Authorization: Basic YWRtaW46MTIzNDU= <br>
......@@ -2773,7 +2873,7 @@ Payload Example 1 (required parameters):</p>
<h3 id="possible-parameters-13">Possible parameters</h3>
<h3 id="possible-parameters-14">Possible parameters</h3>
<table>
<thead>
......@@ -2807,7 +2907,7 @@ Payload Example 1 (required parameters):</p>
<h3 id="examples-14">Examples</h3>
<h3 id="examples-15">Examples</h3>
<blockquote>
<p><strong>Header</strong>: Authorization: Basic YWRtaW46MTIzNDU=</p>
......@@ -2833,7 +2933,7 @@ Payload Example 1 (required parameters):</p>
<h3 id="possible-parameters-14">Possible parameters</h3>
<h3 id="possible-parameters-15">Possible parameters</h3>
<table>
<thead>
......@@ -2861,7 +2961,7 @@ Payload Example 1 (required parameters):</p>
<h3 id="examples-15">Examples</h3>
<h3 id="examples-16">Examples</h3>
<blockquote>
<p><strong>Header:</strong> Authorization: Basic YWRtaW46MTIzNDU=</p>
......@@ -2885,7 +2985,7 @@ Payload Example 1 (required parameters):</p>
<h3 id="possible-parameters-15">Possible parameters</h3>
<h3 id="possible-parameters-16">Possible parameters</h3>
<table>
<thead>
......@@ -2913,7 +3013,7 @@ Payload Example 1 (required parameters):</p>
<h3 id="examples-16">Examples</h3>
<h3 id="examples-17">Examples</h3>
<blockquote>
<p><strong>Header:</strong> Authorization: Basic YWRtaW46MTIzNDU=</p>
......@@ -2936,7 +3036,7 @@ Payload Example 1 (required parameters):</p>
<h3 id="possible-parameters-16">Possible parameters</h3>
<h3 id="possible-parameters-17">Possible parameters</h3>
<table>
<thead>
......@@ -3095,8 +3195,6 @@ Payload Example 1 (required parameters):</p>
}
}</code></pre>
<h2 id="delete-a-chat-room">Delete a chat room</h2>
<p>Endpoint to delete a chat room.</p>
......@@ -3916,6 +4014,8 @@ DELETE /chatrooms/{roomName}/{roles}/{name}</p>
<h1 id="message-related-rest-endpoints">Message related REST Endpoints</h1>
<h2 id="send-a-broadcast-message">Send a broadcast message</h2>
<p>Endpoint to send a broadcast/server message to all online users</p>
......@@ -3927,6 +4027,8 @@ DELETE /chatrooms/{roomName}/{roles}/{name}</p>
<p><strong>Payload:</strong> Message <br>
<strong>Return value:</strong> HTTP status 201 (Created)</p>
<h3 id="examples-35">Examples</h3>
<blockquote>
......@@ -3944,6 +4046,8 @@ DELETE /chatrooms/{roomName}/{roles}/{name}</p>
<span class="hljs-tag">&lt;<span class="hljs-title">body</span>&gt;</span>Your message<span class="hljs-tag">&lt;/<span class="hljs-title">body</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-title">message</span>&gt;</span></code></pre>
<h1 id="deprecated-user-service-plugin-readme">(Deprecated) User Service Plugin Readme</h1>
......@@ -4479,6 +4583,47 @@ If the strings are encoded incorrectly, double byte characters will look garbele
......
......@@ -395,6 +395,25 @@ public class UserServiceController {
}
}
/**
* Adds the user to group.
*
* @param username the username
* @param groupName the group name
* @throws ServiceException the service exception
*/
public void addUserToGroup(String username, String groupName) throws ServiceException {
Group group = null;
try {
group = GroupManager.getInstance().getGroup(groupName);
} catch (GroupNotFoundException e) {
// Create this group
group = GroupController.getInstance().createGroup(new GroupEntity(groupName, ""));
}
group.getMembers().add(server.createJID(username, null));
}
/**
* Delete user from groups.
*
......@@ -420,6 +439,24 @@ public class UserServiceController {
}
}
/**
* Delete user from group.
*
* @param username the username
* @param groupName the group name
* @throws ServiceException the service exception
*/
public void deleteUserFromGroup(String username, String groupName) throws ServiceException {
Group group = null;
try {
group = GroupManager.getInstance().getGroup(groupName);
} catch (GroupNotFoundException e) {
throw new ServiceException("Could not find group", groupName, ExceptionType.GROUP_NOT_FOUND,
Response.Status.NOT_FOUND, e);
}
group.getMembers().remove(server.createJID(username, null));
}
/**
* Gets the user entities by property key and or value.
*
......
package org.jivesoftware.openfire.plugin.rest.exceptions;
import java.util.List;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.ResponseBuilder;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;
......@@ -17,6 +22,11 @@ public class RESTExceptionMapper implements ExceptionMapper<ServiceException> {
/** The log. */
private static Logger LOG = LoggerFactory.getLogger(RESTExceptionMapper.class);
/** The headers. */
@Context
private HttpHeaders headers;
/**
* Instantiates a new REST exception mapper.
*/
......@@ -36,7 +46,17 @@ public class RESTExceptionMapper implements ExceptionMapper<ServiceException> {
LOG.error(
exception.getException() + ": " + exception.getMessage() + " with ressource "
+ exception.getRessource(), exception.getException());
return Response.status(exception.getStatus()).entity(errorResponse).type(MediaType.APPLICATION_XML).build();
ResponseBuilder responseBuilder = Response.status(exception.getStatus()).entity(errorResponse);
List<MediaType> accepts = headers.getAcceptableMediaTypes();
if (accepts!=null && accepts.size() > 0) {
MediaType mediaType = accepts.get(0);
responseBuilder = responseBuilder.type(mediaType);
}
else {
responseBuilder = responseBuilder.type(headers.getMediaType());
}
return responseBuilder.build();
}
}
......@@ -54,7 +54,7 @@ public class GroupService {
@DELETE
@Path("/{groupName}")
public Response deleteUserFromGroups(@PathParam("groupName") String groupName) throws ServiceException {
public Response deleteGroup(@PathParam("groupName") String groupName) throws ServiceException {
groupController.deleteGroup(groupName);
return Response.status(Response.Status.OK).build();
}
......
......@@ -37,6 +37,22 @@ public class UserGroupService {
return Response.status(Response.Status.CREATED).build();
}
@POST
@Path("/{groupName}")
public Response addUserToGroup(@PathParam("username") String username, @PathParam("groupName") String groupName)
throws ServiceException {
plugin.addUserToGroup(username, groupName);
return Response.status(Response.Status.CREATED).build();
}
@DELETE
@Path("/{groupName}")
public Response deleteUserFromGroup(@PathParam("username") String username, @PathParam("groupName") String groupName)
throws ServiceException {
plugin.deleteUserFromGroup(username, groupName);
return Response.status(Response.Status.OK).build();
}
@DELETE
public Response deleteUserFromGroups(@PathParam("username") String username, UserGroupsEntity userGroupsEntity)
throws ServiceException {
......
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