enhanced ownerships REST API to allow for composite type-relative object IDs

This commit is contained in:
Axel Uhl committed 2020-03-08 14:01:17 +01:00
1 parent 79ac0dbf5c
commit c4687e456c
2 files changed
+40 -2

No files matched your search

@@ -2,6 +2,7 @@ package com.sap.sse.security.jaxrs.api;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
@@ -13,6 +14,7 @@ import javax.ws.rs.PUT;
import javax.ws.rs.Path;
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;
@@ -101,12 +103,24 @@ public class OwnershipResource extends AbstractSecurityResource {
@Produces("application/json;charset=UTF-8")
public Response getOwnership(@PathParam("objectType") String objectType,
@PathParam("typeRelativeObjectId") String typeRelativeObjectId) throws OwnershipException {
return getOwnership(objectType, new String[] { typeRelativeObjectId });
}
@Path("{objectType}")
@GET
@Produces("application/json;charset=UTF-8")
public Response getOwnershipWithMultiId(@PathParam("objectType") String objectType,
@QueryParam("id") List<String> compositeTypeRelativeObjectId) throws OwnershipException {
return getOwnership(objectType, compositeTypeRelativeObjectId.toArray(new String[0]));
}
private Response getOwnership(String objectType, final String[] typeRelativeObjectIdArray) {
QualifiedObjectIdentifier identifier = new QualifiedObjectIdentifierImpl(objectType,
new TypeRelativeObjectIdentifier(typeRelativeObjectId));
new TypeRelativeObjectIdentifier(typeRelativeObjectIdArray));
final OwnershipAnnotation existingOwnership = getService().getOwnership(identifier);
final JSONObject result = new JSONObject();
result.put(KEY_OBJECT_TYPE, objectType);
result.put(KEY_OBJECT_ID, typeRelativeObjectId);
result.put(KEY_OBJECT_ID, identifier.getTypeRelativeObjectIdentifier());
result.put(KEY_GROUP_ID, existingOwnership == null || existingOwnership.getAnnotation().getTenantOwner() == null ? null : existingOwnership.getAnnotation().getTenantOwner().getId().toString());
result.put(KEY_USERNAME, existingOwnership == null || existingOwnership.getAnnotation().getUserOwner() == null ? null : existingOwnership.getAnnotation().getUserOwner().getName());
result.put(KEY_DISPLAY_NAME, existingOwnership == null || existingOwnership.getDisplayNameOfAnnotatedObject() == null ? null : existingOwnership.getDisplayNameOfAnnotatedObject());
@@ -70,6 +70,30 @@
Will provide a JSON document as explained above.</td>
</tr>
<tr>
<td>Request Method:</td>
<td>GET /{objectType}?id={typeRelativeObjectIdPart1}&id={typeRelativeObjectIdPart2}&...</td>
</tr>
<tr>
<td>Output format:</td>
<td>a JSON document of the following format<br>
<pre>{"objectType":"USER_GROUP","objectId":"82832851-07ac-47ee-9ddf-6f4f9eaa7823","groupId":"82832851-07ac-47ee-9ddf-6f4f9eaa7823","username":"admin"}</pre>
</td>
</tr>
<tr>
<td>Parameter (path)</td>
<td>
<div>objectType</div> Object type represents the type of object to change the ownership.
<div>id</div> Can be used multiple times, e.g., in order to encode a composite type-relative object ID such as they
are used for objects of type TRACKED_RACE.
</td>
</tr>
<tr>
<td>Example:</td>
<td><code>curl "http://127.0.0.1:8888/security/api/restsecurity/ownership/TRACKED_RACE?id=Croatia%20Coast%20Cup%202019%20-%20ORC%20with%20Spinnaker&id=Race%201%20-%20ORC%20mit%20Spi"</code><br>
Will provide a JSON document as explained above.</td>
</tr>
<tr>
<td>Request Method:</td>
<td>GET /{objectType}/{typeRelativeObjectId}/acl</td>