Commit 90b30063 authored by Roman S's avatar Roman S

Update the REST API plugin to version 1.1.2

- Added: CORS to all endpoints
parent 31de4ae3
...@@ -44,6 +44,11 @@ ...@@ -44,6 +44,11 @@
REST API Plugin Changelog REST API Plugin Changelog
</h1> </h1>
<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> <p><b>1.1.1</b> -- June 29th, 2015</p>
<ul> <ul>
<li>Added: new endpoint to close user sessions</li> <li>Added: new endpoint to close user sessions</li>
......
...@@ -5,8 +5,8 @@ ...@@ -5,8 +5,8 @@
<name>REST API</name> <name>REST API</name>
<description>Allows administration over a RESTful API.</description> <description>Allows administration over a RESTful API.</description>
<author>Roman Soldatow</author> <author>Roman Soldatow</author>
<version>1.1.1</version> <version>1.1.2</version>
<date>06/29/2015</date> <date>08/04/2015</date>
<minServerVersion>3.9.0</minServerVersion> <minServerVersion>3.9.0</minServerVersion>
<adminconsole> <adminconsole>
......
...@@ -1233,6 +1233,7 @@ body.pdf{font-family:"DejaVu Sans"}body.pdf code,body.pdf pre{font-family:"DejaV ...@@ -1233,6 +1233,7 @@ body.pdf{font-family:"DejaVu Sans"}body.pdf code,body.pdf pre{font-family:"DejaV
<ul> <ul>
<li><a href="#rest-api-plugin-readme">REST API Plugin Readme</a><ul> <li><a href="#rest-api-plugin-readme">REST API Plugin Readme</a><ul>
<li><a href="#feature-list">Feature list</a></li> <li><a href="#feature-list">Feature list</a></li>
<li><a href="#available-rest-api-clients">Available REST API clients</a></li>
<li><a href="#installation">Installation</a></li> <li><a href="#installation">Installation</a></li>
<li><a href="#explanation-of-rest">Explanation of REST</a></li> <li><a href="#explanation-of-rest">Explanation of REST</a></li>
<li><a href="#authentication">Authentication</a><ul> <li><a href="#authentication">Authentication</a><ul>
...@@ -1438,6 +1439,11 @@ body.pdf{font-family:"DejaVu Sans"}body.pdf code,body.pdf pre{font-family:"DejaV ...@@ -1438,6 +1439,11 @@ body.pdf{font-family:"DejaVu Sans"}body.pdf code,body.pdf pre{font-family:"DejaV
<li><a href="#examples-32">Examples</a></li> <li><a href="#examples-32">Examples</a></li>
</ul> </ul>
</li> </li>
<li><a href="#close-all-user-sessions">Close all user sessions</a><ul>
<li><a href="#possible-parameters-28">Possible parameters</a></li>
<li><a href="#examples-33">Examples</a></li>
</ul>
</li>
</ul> </ul>
</li> </li>
<li><a href="#deprecated-user-service-plugin-readme">(Deprecated) User Service Plugin Readme</a><ul> <li><a href="#deprecated-user-service-plugin-readme">(Deprecated) User Service Plugin Readme</a><ul>
...@@ -1453,8 +1459,6 @@ body.pdf{font-family:"DejaVu Sans"}body.pdf code,body.pdf pre{font-family:"DejaV ...@@ -1453,8 +1459,6 @@ body.pdf{font-family:"DejaVu Sans"}body.pdf code,body.pdf pre{font-family:"DejaV
</div> </div>
</p> </p>
<h2 id="feature-list">Feature list</h2> <h2 id="feature-list">Feature list</h2>
<ul> <ul>
...@@ -1480,6 +1484,8 @@ body.pdf{font-family:"DejaVu Sans"}body.pdf code,body.pdf pre{font-family:"DejaV ...@@ -1480,6 +1484,8 @@ body.pdf{font-family:"DejaVu Sans"}body.pdf code,body.pdf pre{font-family:"DejaV
<li>GO Lang <a href="https://github.com/Urethramancer/fireman">https://github.com/Urethramancer/fireman</a> (party implemented)</li> <li>GO Lang <a href="https://github.com/Urethramancer/fireman">https://github.com/Urethramancer/fireman</a> (party implemented)</li>
</ul> </ul>
<h2 id="installation">Installation</h2> <h2 id="installation">Installation</h2>
<p>Copy restAPI.jar into the plugins directory of your Openfire server. The plugin will then be automatically deployed. To upgrade to a new version, copy the new restAPI.jar file over the existing file.</p> <p>Copy restAPI.jar into the plugins directory of your Openfire server. The plugin will then be automatically deployed. To upgrade to a new version, copy the new restAPI.jar file over the existing file.</p>
...@@ -3763,7 +3769,9 @@ DELETE /chatrooms/{roomName}/{roles}/{name}</p> ...@@ -3763,7 +3769,9 @@ DELETE /chatrooms/{roomName}/{roles}/{name}</p>
<p><strong>GET</strong> <a href="http://example.org:9090/plugins/restapi/v1/sessions">http://example.org:9090/plugins/restapi/v1/sessions</a></p> <p><strong>GET</strong> <a href="http://example.org:9090/plugins/restapi/v1/sessions">http://example.org:9090/plugins/restapi/v1/sessions</a></p>
</blockquote> </blockquote>
<h2 id="retrieve-the-user-sessions-1">Retrieve the user sessions</h2>
<h2 id="retrieve-the-user-sessions">Retrieve the user sessions</h2>
<p>Endpoint to get sessions from a user</p> <p>Endpoint to get sessions from a user</p>
...@@ -3776,7 +3784,7 @@ DELETE /chatrooms/{roomName}/{roles}/{name}</p> ...@@ -3776,7 +3784,7 @@ DELETE /chatrooms/{roomName}/{roles}/{name}</p>
<h3 id="possible-parameters-28">Possible parameters</h3> <h3 id="possible-parameters-27">Possible parameters</h3>
<table> <table>
<thead> <thead>
...@@ -3819,7 +3827,7 @@ DELETE /chatrooms/{roomName}/{roles}/{name}</p> ...@@ -3819,7 +3827,7 @@ DELETE /chatrooms/{roomName}/{roles}/{name}</p>
<h3 id="possible-parameters-27">Possible parameters</h3> <h3 id="possible-parameters-28">Possible parameters</h3>
<table> <table>
<thead> <thead>
...@@ -3847,6 +3855,8 @@ DELETE /chatrooms/{roomName}/{roles}/{name}</p> ...@@ -3847,6 +3855,8 @@ DELETE /chatrooms/{roomName}/{roles}/{name}</p>
<p><strong>DELETE</strong> <a href="http://example.org:9090/plugins/restapi/v1/sessions/testuser">http://example.org:9090/plugins/restapi/v1/sessions/testuser</a></p> <p><strong>DELETE</strong> <a href="http://example.org:9090/plugins/restapi/v1/sessions/testuser">http://example.org:9090/plugins/restapi/v1/sessions/testuser</a></p>
<h1 id="deprecated-user-service-plugin-readme">(Deprecated) User Service Plugin Readme</h1> <h1 id="deprecated-user-service-plugin-readme">(Deprecated) User Service Plugin Readme</h1>
......
package org.jivesoftware.openfire.plugin.rest;
import com.sun.jersey.spi.container.ContainerRequest;
import com.sun.jersey.spi.container.ContainerResponse;
import com.sun.jersey.spi.container.ContainerResponseFilter;
/**
* The Class CORSFilter.
*/
public class CORSFilter implements ContainerResponseFilter {
/* (non-Javadoc)
* @see com.sun.jersey.spi.container.ContainerResponseFilter#filter(com.sun.jersey.spi.container.ContainerRequest, com.sun.jersey.spi.container.ContainerResponse)
*/
@Override
public ContainerResponse filter(ContainerRequest request, ContainerResponse response) {
response.getHttpHeaders().add("Access-Control-Allow-Origin", "*");
response.getHttpHeaders().add("Access-Control-Allow-Headers",
"origin, content-type, accept, authorization");
response.getHttpHeaders().add("Access-Control-Allow-Credentials", "true");
response.getHttpHeaders().add("Access-Control-Allow-Methods",
"GET, POST, PUT, DELETE, OPTIONS, HEAD");
return response;
}
}
package org.jivesoftware.openfire.plugin.rest.service; package org.jivesoftware.openfire.plugin.rest.service;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import javax.servlet.ServletConfig; import javax.servlet.ServletConfig;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import org.jivesoftware.admin.AuthCheckFilter; import org.jivesoftware.admin.AuthCheckFilter;
import org.jivesoftware.openfire.plugin.rest.exceptions.RESTExceptionMapper; import org.jivesoftware.openfire.plugin.rest.exceptions.RESTExceptionMapper;
import com.sun.jersey.api.core.PackagesResourceConfig; import com.sun.jersey.api.core.PackagesResourceConfig;
import com.sun.jersey.spi.container.servlet.ServletContainer; import com.sun.jersey.spi.container.servlet.ServletContainer;
/** /**
* The Class JerseyWrapper. * The Class JerseyWrapper.
*/ */
public class JerseyWrapper extends ServletContainer { public class JerseyWrapper extends ServletContainer {
/** The Constant AUTHFILTER. */ /** The Constant AUTHFILTER. */
private static final String AUTHFILTER = "org.jivesoftware.openfire.plugin.rest.AuthFilter"; private static final String AUTHFILTER = "org.jivesoftware.openfire.plugin.rest.AuthFilter";
/** The Constant CONTAINER_REQUEST_FILTERS. */ /** The Constant CORSFILTER. */
private static final String CONTAINER_REQUEST_FILTERS = "com.sun.jersey.spi.container.ContainerRequestFilters"; private static final String CORSFILTER = "org.jivesoftware.openfire.plugin.rest.CORSFilter";
/** The Constant RESOURCE_CONFIG_CLASS_KEY. */ /** The Constant CONTAINER_REQUEST_FILTERS. */
private static final String RESOURCE_CONFIG_CLASS_KEY = "com.sun.jersey.config.property.resourceConfigClass"; private static final String CONTAINER_REQUEST_FILTERS = "com.sun.jersey.spi.container.ContainerRequestFilters";
/** The Constant RESOURCE_CONFIG_CLASS. */ /** The Constant CONTAINER_RESPONSE_FILTERS. */
private static final String RESOURCE_CONFIG_CLASS = "com.sun.jersey.api.core.PackagesResourceConfig"; private static final String CONTAINER_RESPONSE_FILTERS = "com.sun.jersey.spi.container.ContainerResponseFilters";
/** The Constant SCAN_PACKAGE_DEFAULT. */ /** The Constant RESOURCE_CONFIG_CLASS_KEY. */
private static final String SCAN_PACKAGE_DEFAULT = JerseyWrapper.class.getPackage().getName(); private static final String RESOURCE_CONFIG_CLASS_KEY = "com.sun.jersey.config.property.resourceConfigClass";
/** The Constant serialVersionUID. */ /** The Constant RESOURCE_CONFIG_CLASS. */
private static final long serialVersionUID = 1L; private static final String RESOURCE_CONFIG_CLASS = "com.sun.jersey.api.core.PackagesResourceConfig";
/** The Constant SERVLET_URL. */ /** The Constant SCAN_PACKAGE_DEFAULT. */
private static final String SERVLET_URL = "restapi/*"; private static final String SCAN_PACKAGE_DEFAULT = JerseyWrapper.class.getPackage().getName();
/** The config. */ /** The Constant serialVersionUID. */
private static Map<String, Object> config; private static final long serialVersionUID = 1L;
/** The prc. */ /** The Constant SERVLET_URL. */
private static PackagesResourceConfig prc; private static final String SERVLET_URL = "restapi/*";
/** The Constant JERSEY_LOGGER. */ /** The config. */
private final static Logger JERSEY_LOGGER = Logger.getLogger("com.sun.jersey"); private static Map<String, Object> config;
static { /** The prc. */
JERSEY_LOGGER.setLevel(Level.SEVERE); private static PackagesResourceConfig prc;
config = new HashMap<String, Object>();
config.put(RESOURCE_CONFIG_CLASS_KEY, RESOURCE_CONFIG_CLASS); /** The Constant JERSEY_LOGGER. */
prc = new PackagesResourceConfig(SCAN_PACKAGE_DEFAULT); private final static Logger JERSEY_LOGGER = Logger.getLogger("com.sun.jersey");
prc.setPropertiesAndFeatures(config);
prc.getProperties().put(CONTAINER_REQUEST_FILTERS, AUTHFILTER); static {
JERSEY_LOGGER.setLevel(Level.SEVERE);
prc.getClasses().add(RestAPIService.class); config = new HashMap<String, Object>();
config.put(RESOURCE_CONFIG_CLASS_KEY, RESOURCE_CONFIG_CLASS);
prc.getClasses().add(MUCRoomService.class); prc = new PackagesResourceConfig(SCAN_PACKAGE_DEFAULT);
prc.getClasses().add(MUCRoomOwnersService.class); prc.setPropertiesAndFeatures(config);
prc.getClasses().add(MUCRoomAdminsService.class); prc.getProperties().put(CONTAINER_REQUEST_FILTERS, AUTHFILTER);
prc.getClasses().add(MUCRoomMembersService.class); prc.getProperties().put(CONTAINER_RESPONSE_FILTERS, CORSFILTER);
prc.getClasses().add(MUCRoomOutcastsService.class);
prc.getClasses().add(RestAPIService.class);
prc.getClasses().add(UserServiceLegacy.class);
prc.getClasses().add(UserService.class); prc.getClasses().add(MUCRoomService.class);
prc.getClasses().add(UserRosterService.class); prc.getClasses().add(MUCRoomOwnersService.class);
prc.getClasses().add(UserGroupService.class); prc.getClasses().add(MUCRoomAdminsService.class);
prc.getClasses().add(UserLockoutService.class); prc.getClasses().add(MUCRoomMembersService.class);
prc.getClasses().add(MUCRoomOutcastsService.class);
prc.getClasses().add(GroupService.class);
prc.getClasses().add(SessionService.class); prc.getClasses().add(UserServiceLegacy.class);
prc.getClasses().add(UserService.class);
prc.getClasses().add(RESTExceptionMapper.class); prc.getClasses().add(UserRosterService.class);
} prc.getClasses().add(UserGroupService.class);
prc.getClasses().add(UserLockoutService.class);
/**
* Instantiates a new jersey wrapper. prc.getClasses().add(GroupService.class);
*/ prc.getClasses().add(SessionService.class);
public JerseyWrapper() {
super(prc); prc.getClasses().add(RESTExceptionMapper.class);
} }
/* /**
* (non-Javadoc) * Instantiates a new jersey wrapper.
* */
* @see javax.servlet.GenericServlet#init(javax.servlet.ServletConfig) public JerseyWrapper() {
*/ super(prc);
@Override }
public void init(ServletConfig servletConfig) throws ServletException {
super.init(servletConfig); /*
// Exclude this servlet from requering the user to login * (non-Javadoc)
AuthCheckFilter.addExclude(SERVLET_URL); *
} * @see javax.servlet.GenericServlet#init(javax.servlet.ServletConfig)
*/
/* @Override
* (non-Javadoc) public void init(ServletConfig servletConfig) throws ServletException {
* super.init(servletConfig);
* @see com.sun.jersey.spi.container.servlet.ServletContainer#destroy() // Exclude this servlet from requering the user to login
*/ AuthCheckFilter.addExclude(SERVLET_URL);
@Override }
public void destroy() {
super.destroy(); /*
// Release the excluded URL * (non-Javadoc)
AuthCheckFilter.removeExclude(SERVLET_URL); *
} * @see com.sun.jersey.spi.container.servlet.ServletContainer#destroy()
} */
@Override
public void destroy() {
super.destroy();
// Release the excluded URL
AuthCheckFilter.removeExclude(SERVLET_URL);
}
}
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