bug4757 added PreferencesRessource to REST api and adjusted the

documentation accordingly
This commit is contained in:
Kai Börnert committed 2018-10-04 20:01:19 +02:00
1 parent b0ee83e046
commit 990b8aac51
7 files changed
+223 -3

No files matched your search

@@ -82,7 +82,7 @@ bearerToken = com.sap.sailing.server.security.BearerTokenOrBasicOrFormAuthentica
# Secure the access (in particular the POST/write access) to posting race log events
/rc/racelog = bearerToken
# Secure access to additional apis used for SailRacer
# Secure access to additional apis used for SailRacer and SailInsight 2.0
/api/v1/leaderboards/*/enableRaceLogForCompetitorRegistration/** = bearerToken
/api/v1/leaderboards/*/denoteForTracking/** = bearerToken
/api/v1/leaderboards/*/removeTrackedRace/** = bearerToken
@@ -91,3 +91,6 @@ bearerToken = com.sap.sailing.server.security.BearerTokenOrBasicOrFormAuthentica
/api/v1/mark/addMarkFix/** = bearerToken
/api/v1/mark/addCourseDefinitionToRaceLog/** = bearerToken
/api/v1/wind/putWind/** = bearerToken
#Secure access for preferences api, used for SailInsight 2.0
/api/v1/preferences/** = bearerToken
@@ -0,0 +1,76 @@
package com.sap.sailing.server.gateway.jaxrs.api;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.apache.shiro.SecurityUtils;
import org.json.simple.parser.ParseException;
import com.sap.sailing.server.gateway.deserialization.JsonDeserializationException;
import com.sap.sailing.server.gateway.jaxrs.AbstractSailingServerResource;
import com.sap.sse.security.UserStore;
@Path("/v1/preferences")
public class PreferencesResource extends AbstractSailingServerResource {
@GET
@Produces("application/json;charset=UTF-8")
@Path("{settingsKey}")
public Response getPreference(@PathParam("settingsKey") String settingsKey)
throws ParseException, JsonDeserializationException {
Response response = null;
if (SecurityUtils.getSubject().isAuthenticated()) {
String username = SecurityUtils.getSubject().getPrincipal().toString();
UserStore userStore = getService(UserStore.class);
String settings = userStore.getPreference(username, settingsKey);
if (settings == null) {
response = Response.noContent().build();
} else {
response = Response.ok(settings).build();
}
} else {
response = Response.status(401).build();
}
return response;
}
@PUT
@Consumes(MediaType.APPLICATION_JSON)
@Path("{settingsKey}")
public Response putPreference(@PathParam("settingsKey") String settingsKey, String json)
throws ParseException, JsonDeserializationException {
Response response = null;
if (SecurityUtils.getSubject().isAuthenticated()) {
String username = SecurityUtils.getSubject().getPrincipal().toString();
UserStore userStore = getService(UserStore.class);
userStore.setPreference(username, settingsKey, json);
response = Response.ok().build();
} else {
response = Response.status(401).build();
}
return response;
}
@DELETE
@Produces("application/json;charset=UTF-8")
@Path("{settingsKey}")
public Response deletePreference(@PathParam("settingsKey") String settingsKey)
throws ParseException, JsonDeserializationException {
Response response = null;
if (SecurityUtils.getSubject().isAuthenticated()) {
String username = SecurityUtils.getSubject().getPrincipal().toString();
UserStore userStore = getService(UserStore.class);
userStore.unsetPreference(username, settingsKey);
response = Response.ok().build();
} else {
response = Response.status(401).build();
}
return response;
}
}
@@ -8,7 +8,6 @@ import javax.ws.rs.core.Application;
import com.sap.sailing.server.gateway.jaxrs.exceptions.ExceptionManager;
import com.sap.sse.security.jaxrs.ShiroAuthorizationExceptionTo401ResponseMapper;
public class RestApiApplication extends Application {
public Set<Class<?>> getClasses() {
HashSet<Class<?>> classes = new HashSet<>();
@@ -30,7 +29,8 @@ public class RestApiApplication extends Application {
classes.add(StatisticsResource.class);
classes.add(WindResource.class);
classes.add(MarkRessource.class);
classes.add(PreferencesResource.class);
// Exception Mappers
classes.add(ShiroAuthorizationExceptionTo401ResponseMapper.class);
classes.add(ExceptionManager.class);
@@ -290,6 +290,21 @@ name to make sure you get to the event you're interested in.
<td><a href="addMarkToRegatta.html">/api/v1/mark/addMarkToRegatta</a></td>
<td>Adds a Mark to a specified Regatta</td>
</tr>
</tr>
<tr>
<td><a href="preferencesPut.html">/api/v1/preferences/{SETTINGS_KEY}</a></td>
<td>Stores a document into the preferences of a user</td>
</tr>
</tr>
<tr>
<td><a href="preferencesGet.html">/api/v1/preferences/{SETTINGS_KEY}</a></td>
<td>Retrives a document that was stored into the preferences of a user</td>
</tr>
</tr>
<tr>
<td><a href="preferencesDelete.html">/api/v1/preferences/{SETTINGS_KEY}</a></td>
<td>Removes a document from the preferences of a user</td>
</tr>
</tbody>
</table>
<div style="height: 1em;"></div>
@@ -0,0 +1,42 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link href='../../../../sailing-fontface-1.0.cache.css' media='screen' rel='stylesheet' title='Default stylesheet' type='text/css' />
<link href='../../../main.css' media='screen' rel='stylesheet' title='Default stylesheet' type='text/css' />
<link rel='icon' href='../../../../sap.ico' type='image/x-icon'>
<title>SAP Sailing Analytics Webservices API Version 1.0</title>
</head>
<body>
<h1>SAP Sailing Analytics Webservices API Version 1.0</h1>
<h2>URL: /api/v1/preferences/{SETTINGS_KEY}/</h2>
<b>Description:</b>
<p>Deletes whatever is stored under SETTINGS_KEY in currently logged in users preferences</p>
<br/>
<table>
<tr>
<td>Webservice Type:</td>
<td>REST</td>
</tr>
<tr>
<td>Output format:</td>
<td>none</td>
</tr>
<tr>
<td>Mandatory parameters:</td>
<td>none</td>
</tr>
<tr>
<td>Examples:</td>
<td>
Delete @ http://sapsailing.com/sailingserver/api/v1/preferences/testSetting/
<br>
Answer: Ok
</td>
</tr>
</table>
<div style="height: 1em;"></div>
<a href="index.html">Back to Web Service Overview</a>
</body>
</html>
@@ -0,0 +1,42 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link href='../../../../sailing-fontface-1.0.cache.css' media='screen' rel='stylesheet' title='Default stylesheet' type='text/css' />
<link href='../../../main.css' media='screen' rel='stylesheet' title='Default stylesheet' type='text/css' />
<link rel='icon' href='../../../../sap.ico' type='image/x-icon'>
<title>SAP Sailing Analytics Webservices API Version 1.0</title>
</head>
<body>
<h1>SAP Sailing Analytics Webservices API Version 1.0</h1>
<h2>URL: /api/v1/preferences/{SETTINGS_KEY}/</h2>
<b>Description:</b>
<p>Gets the stored Json data for the currently logged in user with the key SETTINGS_KEY</p>
<br/>
<table>
<tr>
<td>Webservice Type:</td>
<td>REST</td>
</tr>
<tr>
<td>Output format:</td>
<td>Json</td>
</tr>
<tr>
<td>Mandatory parameters:</td>
<td>none</td>
</tr>
<tr>
<td>Examples:</td>
<td>
Get @ http://sapsailing.com/sailingserver/api/v1/preferences/testSetting/
<br>
Answer: No Content Status code, or Ok and the stored document
</td>
</tr>
</table>
<div style="height: 1em;"></div>
<a href="index.html">Back to Web Service Overview</a>
</body>
</html>
@@ -0,0 +1,42 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link href='../../../../sailing-fontface-1.0.cache.css' media='screen' rel='stylesheet' title='Default stylesheet' type='text/css' />
<link href='../../../main.css' media='screen' rel='stylesheet' title='Default stylesheet' type='text/css' />
<link rel='icon' href='../../../../sap.ico' type='image/x-icon'>
<title>SAP Sailing Analytics Webservices API Version 1.0</title>
</head>
<body>
<h1>SAP Sailing Analytics Webservices API Version 1.0</h1>
<h2>URL: /api/v1/preferences/{SETTINGS_KEY}/</h2>
<b>Description:</b>
<p>Stores the body of the request in the currently logged in users preferences under the given SETTINGS_KEY, the body is expected to be UTF-8 Json</p>
<br/>
<table>
<tr>
<td>Webservice Type:</td>
<td>REST</td>
</tr>
<tr>
<td>Output format:</td>
<td>none</td>
</tr>
<tr>
<td>Mandatory parameters:</td>
<td>none</td>
</tr>
<tr>
<td>Examples:</td>
<td>
Put @ http://sapsailing.com/sailingserver/api/v1/preferences/testSetting/
<br>
Answer: Ok
</td>
</tr>
</table>
<div style="height: 1em;"></div>
<a href="index.html">Back to Web Service Overview</a>
</body>
</html>