Commit bfce1f34 authored by Roman S's avatar Roman S

Update the REST API plugin to version 1.1.0

parent 6a72aa1b
...@@ -44,6 +44,11 @@ ...@@ -44,6 +44,11 @@
REST API Plugin Changelog REST API Plugin Changelog
</h1> </h1>
<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> <p><b>1.0.2</b> -- March 3rd, 2015</p>
<ul> <ul>
<li>User will be kicked by a lockout (ban)</li> <li>User will be kicked by a lockout (ban)</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.0.2</version> <version>1.1.0</version>
<date>03/03/2015</date> <date>06/03/2015</date>
<minServerVersion>3.9.0</minServerVersion> <minServerVersion>3.9.0</minServerVersion>
<adminconsole> <adminconsole>
......
...@@ -1452,10 +1452,9 @@ body.pdf{font-family:"DejaVu Sans"}body.pdf code,body.pdf pre{font-family:"DejaV ...@@ -1452,10 +1452,9 @@ body.pdf{font-family:"DejaVu Sans"}body.pdf code,body.pdf pre{font-family:"DejaV
<li>Lockout or unlock the user (enable / disable)</li> <li>Lockout or unlock the user (enable / disable)</li>
<li>Get overview over all or specific system properties and to create, update or delete system property</li> <li>Get overview over all or specific system properties and to create, update or delete system property</li>
<li>Get overview over all or specific chat room and to create, update or delete a chat room</li> <li>Get overview over all or specific chat room and to create, update or delete a chat room</li>
<li>Get overview over all or specific user sessions</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>
...@@ -1770,6 +1769,79 @@ If you want to create a resource with JSON data format, please add “<strong>Co ...@@ -1770,6 +1769,79 @@ If you want to create a resource with JSON data format, please add “<strong>Co
<h3 id="session">Session</h3>
<table>
<thead>
<tr>
<th>Parameter</th>
<th>Optional</th>
<th>Description</th>
</tr>
</thead>
<tbody><tr>
<td>sessionId</td>
<td>No</td>
<td>Full JID of a user e.g. (testUser@testserver.de/SomeRessource)</td>
</tr>
<tr>
<td>username</td>
<td>No</td>
<td>The username associated with this session. Can be also “Anonymous”.</td>
</tr>
<tr>
<td>ressource</td>
<td>Yes</td>
<td>Ressource name</td>
</tr>
<tr>
<td>node</td>
<td>No</td>
<td>Can be “Local” or “Remote”</td>
</tr>
<tr>
<td>sessionStatus</td>
<td>No</td>
<td>The current status of this session. Can be “Closed”, “Connected”, “Authenticated” or “Unknown”.</td>
</tr>
<tr>
<td>presenceStatus</td>
<td>No</td>
<td>The status of this presence packet, a natural-language description of availability status.</td>
</tr>
<tr>
<td>priority</td>
<td>No</td>
<td>The priority of the session. The valid priority range is -128 through 128.</td>
</tr>
<tr>
<td>hostAddress</td>
<td>No</td>
<td>Tthe IP address string in textual presentation.</td>
</tr>
<tr>
<td>hostName</td>
<td>No</td>
<td>The host name for this IP address.</td>
</tr>
<tr>
<td>creationDate</td>
<td>No</td>
<td>The date the session was created.</td>
</tr>
<tr>
<td>lastActionDate</td>
<td>No</td>
<td>The time the session last had activity.</td>
</tr>
<tr>
<td>secure</td>
<td>No</td>
<td>Is “true” if this connection is secure.</td>
</tr>
</tbody></table>
<h1 id="user-related-rest-endpoints">User related REST Endpoints</h1> <h1 id="user-related-rest-endpoints">User related REST Endpoints</h1>
...@@ -3639,6 +3711,64 @@ DELETE /chatrooms/{roomName}/{roles}/{name}</p> ...@@ -3639,6 +3711,64 @@ DELETE /chatrooms/{roomName}/{roles}/{name}</p>
<h1 id="session-related-rest-endpoints">Session related REST Endpoints</h1>
<h2 id="retrieve-all-user-session">Retrieve all user session</h2>
<p>Endpoint to get all user sessions</p>
<blockquote>
<p><strong>GET</strong> /sessions</p>
</blockquote>
<p><strong>Payload:</strong> none <br>
<strong>Return value:</strong> Sessions</p>
<h3 id="examples-31">Examples</h3>
<blockquote>
<p><strong>Header</strong>: Authorization: Basic YWRtaW46MTIzNDU=</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>
<h2 id="retrieve-the-user-sessions">Retrieve the user sessions</h2>
<p>Endpoint to get sessions from a user</p>
<blockquote>
<p><strong>GET</strong> /sessions/{username}</p>
</blockquote>
<p><strong>Payload:</strong> none <br>
<strong>Return value:</strong> Sessions</p>
<h3 id="possible-parameters-27">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>The username of the user</td>
<td></td>
</tr>
</tbody></table>
<h3 id="examples-32">Examples</h3>
<p><strong>Header:</strong> Authorization: Basic YWRtaW46MTIzNDU=</p>
<p><strong>GET</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>
...@@ -3990,6 +4120,77 @@ If the strings are encoded incorrectly, double byte characters will look garbele ...@@ -3990,6 +4120,77 @@ If the strings are encoded incorrectly, double byte characters will look garbele
......
package org.jivesoftware.openfire.plugin.rest.controller;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import javax.ws.rs.core.Response;
import org.jivesoftware.openfire.SessionManager;
import org.jivesoftware.openfire.plugin.rest.entity.SessionEntities;
import org.jivesoftware.openfire.plugin.rest.entity.SessionEntity;
import org.jivesoftware.openfire.plugin.rest.exceptions.ExceptionType;
import org.jivesoftware.openfire.plugin.rest.exceptions.ServiceException;
import org.jivesoftware.openfire.session.ClientSession;
import org.jivesoftware.openfire.session.Session;
import org.jivesoftware.openfire.user.UserNotFoundException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* The Class SessionController.
*/
public class SessionController {
/** The Constant INSTANCE. */
public static final SessionController INSTANCE = new SessionController();
/** The log. */
private static Logger LOG = LoggerFactory.getLogger(SessionController.class);
/**
* Gets the single instance of SessionController.
*
* @return single instance of SessionController
*/
public static SessionController getInstance() {
return INSTANCE;
}
/**
* Gets the user sessions.
*
* @param username the username
* @return the user sessions
* @throws ServiceException the service exception
*/
public SessionEntities getUserSessions(String username) throws ServiceException {
Collection<ClientSession> clientSessions = SessionManager.getInstance().getSessions(username);
SessionEntities sessionEntities = convertToSessionEntities(clientSessions);
return sessionEntities;
}
/**
* Gets the all sessions.
*
* @return the all sessions
* @throws ServiceException the service exception
*/
public SessionEntities getAllSessions() throws ServiceException {
Collection<ClientSession> clientSessions = SessionManager.getInstance().getSessions();
SessionEntities sessionEntities = convertToSessionEntities(clientSessions);
return sessionEntities;
}
/**
* Convert to session entities.
*
* @param clientSessions the client sessions
* @return the session entities
* @throws ServiceException the service exception
*/
private SessionEntities convertToSessionEntities(Collection<ClientSession> clientSessions) throws ServiceException {
List<SessionEntity> sessions = new ArrayList<SessionEntity>();
SessionEntities sessionEntities = new SessionEntities(sessions);
for (ClientSession clientSession : clientSessions) {
SessionEntity session = new SessionEntity();
session.setSessionId(clientSession.getAddress().toString());
if (!clientSession.isAnonymousUser()) {
try {
session.setUsername(clientSession.getUsername());
} catch (UserNotFoundException e) {
throw new ServiceException("Could not get user", "", ExceptionType.USER_NOT_FOUND_EXCEPTION,
Response.Status.NOT_FOUND, e);
}
} else {
session.setUsername("Anonymous");
}
session.setRessource(clientSession.getAddress().getResource());
session.setNode(session.getNode());
String status = "";
if (clientSession.getStatus() == Session.STATUS_CLOSED) {
status = "Closed";
} else if (clientSession.getStatus() == Session.STATUS_CONNECTED) {
status = "Connected";
} else if (clientSession.getStatus() == Session.STATUS_AUTHENTICATED) {
status = "Authenticated";
} else {
status = "Unkown";
}
session.setSessionStatus(status);
if (clientSession.getPresence() != null) {
session.setPresenceStatus(clientSession.getPresence().getStatus());
session.setPriority(clientSession.getPresence().getPriority());
}
try {
session.setHostAddress(clientSession.getHostAddress());
session.setHostName(clientSession.getHostName());
} catch (UnknownHostException e) {
LOG.error("UnknownHostException", e);
}
session.setCreationDate(clientSession.getCreationDate());
session.setLastActionDate(clientSession.getLastActiveDate());
session.setSecure(clientSession.isSecure());
sessions.add(session);
}
return sessionEntities;
}
}
\ No newline at end of file
package org.jivesoftware.openfire.plugin.rest.entity;
import java.util.List;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name = "sessions")
public class SessionEntities {
List<SessionEntity> sessions;
public SessionEntities() {
}
public SessionEntities(List<SessionEntity> sessions) {
this.sessions = sessions;
}
@XmlElement(name = "session")
public List<SessionEntity> getSessions() {
return sessions;
}
public void setSessions(List<SessionEntity> sessions) {
this.sessions = sessions;
}
}
package org.jivesoftware.openfire.plugin.rest.entity;
import java.util.Date;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
@XmlRootElement(name = "session")
@XmlType(propOrder = { "sessionId", "username", "ressource", "node", "sessionStatus", "presenceStatus", "priority",
"hostAddress", "hostName", "creationDate", "lastActionDate", "secure" })
public class SessionEntity {
private String sessionId;
private String username;
private String ressource;
private String node;
private String sessionStatus;
private String presenceStatus;
private int priority;
private String hostAddress;
private String hostName;
private Date creationDate;
private Date lastActionDate;
private boolean secure;
public SessionEntity() {
}
@XmlElement
public String getSessionId() {
return sessionId;
}
public void setSessionId(String sessionId) {
this.sessionId = sessionId;
}
@XmlElement
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
@XmlElement
public String getRessource() {
return ressource;
}
public void setRessource(String ressource) {
this.ressource = ressource;
}
@XmlElement
public String getNode() {
return node;
}
public void setNode(String node) {
this.node = node;
}
@XmlElement
public String getSessionStatus() {
return sessionStatus;
}
public void setSessionStatus(String sessionStatus) {
this.sessionStatus = sessionStatus;
}
@XmlElement
public String getPresenceStatus() {
return presenceStatus;
}
public void setPresenceStatus(String presenceStatus) {
this.presenceStatus = presenceStatus;
}
@XmlElement
public int getPriority() {
return priority;
}
public void setPriority(int priority) {
this.priority = priority;
}
@XmlElement
public String getHostAddress() {
return hostAddress;
}
public void setHostAddress(String hostAddress) {
this.hostAddress = hostAddress;
}
@XmlElement
public String getHostName() {
return hostName;
}
public void setHostName(String hostName) {
this.hostName = hostName;
}
@XmlElement
public Date getCreationDate() {
return creationDate;
}
public void setCreationDate(Date creationDate) {
this.creationDate = creationDate;
}
@XmlElement
public Date getLastActionDate() {
return lastActionDate;
}
public void setLastActionDate(Date lastActionDate) {
this.lastActionDate = lastActionDate;
}
@XmlElement
public boolean isSecure() {
return secure;
}
public void setSecure(boolean secure) {
this.secure = secure;
}
}
\ No newline at end of file
...@@ -72,6 +72,7 @@ public class JerseyWrapper extends ServletContainer { ...@@ -72,6 +72,7 @@ public class JerseyWrapper extends ServletContainer {
prc.getClasses().add(UserLockoutService.class); prc.getClasses().add(UserLockoutService.class);
prc.getClasses().add(GroupService.class); prc.getClasses().add(GroupService.class);
prc.getClasses().add(SessionService.class);
prc.getClasses().add(RESTExceptionMapper.class); prc.getClasses().add(RESTExceptionMapper.class);
} }
......
package org.jivesoftware.openfire.plugin.rest.service;
import javax.annotation.PostConstruct;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import org.jivesoftware.openfire.plugin.rest.controller.SessionController;
import org.jivesoftware.openfire.plugin.rest.entity.SessionEntities;
import org.jivesoftware.openfire.plugin.rest.exceptions.ServiceException;
@Path("restapi/v1/sessions")
public class SessionService {
private SessionController sessionController;
@PostConstruct
public void init() {
sessionController = SessionController.getInstance();
}
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public SessionEntities getAllSessions() throws ServiceException {
return sessionController.getAllSessions();
}
@GET
@Path("/{username}")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public SessionEntities getUserSessions(@PathParam("username") String username) throws ServiceException {
return sessionController.getUserSessions(username);
}
}
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