bug5828: interims commit, working towards allowing ACL setting when creating -server group

This commit is contained in:
Axel Uhl
2023-05-08 18:12:09 +02:00
parent 131c7d8384
commit 3e5e4c5901
3 changed files with 66 additions and 2 deletions
@@ -128,7 +128,7 @@ public class OwnershipResource extends AbstractSecurityResource {
return Response.ok(streamingOutput(result)).build();
}
@Path("{objectType}/{typeRelativeObjectId}/acl")
@Path("{objectType}/{typeRelativeObjectId}/"+KEY_ACL)
@GET
@Produces("application/json;charset=UTF-8")
public Response getAccessControlLists(@PathParam("objectType") String objectType,
@@ -155,7 +155,7 @@ public class OwnershipResource extends AbstractSecurityResource {
return Response.ok(streamingOutput(result)).build();
}
@Path("{objectType}/{typeRelativeObjectId}/acl")
@Path("{objectType}/{typeRelativeObjectId}/"+KEY_ACL)
@PUT
@Consumes(MediaType.APPLICATION_JSON)
@Produces("application/json;charset=UTF-8")
@@ -4,7 +4,9 @@ import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import org.apache.http.client.ClientProtocolException;
@@ -14,6 +16,7 @@ import com.sap.sse.common.Util.Pair;
import com.sap.sse.security.shared.HasPermissions;
import com.sap.sse.security.shared.TypeRelativeObjectIdentifier;
import com.sap.sse.security.shared.WildcardPermission;
import com.sap.sse.security.shared.impl.UserGroup;
/**
* Represents a remote instance of a server process or an entire application replica set with a master and zero or more
@@ -97,4 +100,30 @@ public interface SecuredServer {
UUID createUserGroupAndAddCurrentUser(String serverGroupName) throws ClientProtocolException, IOException, ParseException, IllegalAccessException;
Iterable<String> getNamesOfUsersInGroup(UUID userGroupId) throws ClientProtocolException, IOException, ParseException;
/**
* Obtains the access control lists defined for the object identified by {@code type} and
* {@code typeRelativeObjectId}.
*
* @return a valid, non-{@code null} map which may be empty. It does support the {@code null} key which then means
* the "<Any>" virtual group of which implicitly all users are a member. The keys of the map returned identify
* {@link UserGroup} objects, the value sets contain the names of the actions allowed/disallowed for the group
* identified by the corresponding key. Disallowed actions are indicated by a leading exclamation mark, as in
* {@code "!UPDATE"}.
*/
Map<UUID, Set<String>> getAccessControlLists(HasPermissions type, TypeRelativeObjectIdentifier typeRelativeObjectId)
throws ClientProtocolException, IOException, ParseException;
/**
* Updates the access control lists for the object identified by {@code type} and {@code typeRelativeObjectId}.
*
* @param actionsPerGroup
* a valid, non-{@code null} map which may be empty. It does support the {@code null} key which then
* means the "<Any>" virtual group of which implicitly all users are a member. The keys of the map
* returned identify {@link UserGroup} objects, the value sets contain the names of the actions
* allowed/disallowed for the group identified by the corresponding key. Disallowed actions are indicated
* by a leading exclamation mark, as in {@code "!UPDATE"}.
*/
void setAccessControlLists(HasPermissions type, TypeRelativeObjectIdentifier typeRelativeObjectId,
Map<UUID, Set<String>> actionsPerGroup) throws ClientProtocolException, IOException, ParseException;
}
@@ -8,7 +8,9 @@ import java.net.URL;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import java.util.logging.Logger;
@@ -158,6 +160,39 @@ public class SecuredServerImpl implements SecuredServer {
}
}
@Override
public Map<UUID, Set<String>> getAccessControlLists(HasPermissions type, TypeRelativeObjectIdentifier typeRelativeObjectId) throws ClientProtocolException, IOException, ParseException {
final URL getGroupAndUserOwnerUrl = new URL(getBaseUrl(), SECURITY_API_PREFIX + OwnershipResource.RESTSECURITY_OWNERSHIP
+ "/" + type.getName() + "/" + typeRelativeObjectId.toString() + "/" + OwnershipResource.KEY_ACL);
final HttpGet getRequest = new HttpGet(getGroupAndUserOwnerUrl.toString());
final JSONObject aclJson = (JSONObject) getJsonParsedResponse(getRequest).getA();
// TODO implement SecuredServerImpl.getAccessControlList
return null;
}
@Override
public void setAccessControlLists(HasPermissions type, TypeRelativeObjectIdentifier typeRelativeObjectId,
Map<UUID, Set<String>> actionsPerGroup) throws ClientProtocolException, IOException, ParseException {
final URL setGroupAndUserOwnerUrl = new URL(getBaseUrl(),
SECURITY_API_PREFIX + OwnershipResource.RESTSECURITY_OWNERSHIP + "/"
+ type.getName() + "/" + typeRelativeObjectId.toString() + "/" + OwnershipResource.KEY_ACL);
final HttpPut putRequest = new HttpPut(setGroupAndUserOwnerUrl.toString());
final JSONObject aclJson = new JSONObject();
// TODO implement SecuredServerImpl.setAccessControlList
int TODO;
// username.map(un->ownershipJson.put(OwnershipResource.KEY_USERNAME, un));
// groupId.map(gid->ownershipJson.put(OwnershipResource.KEY_GROUP_ID, gid.toString()));
// displayName.map(dn->ownershipJson.put(OwnershipResource.KEY_DISPLAY_NAME, dn));
final HttpEntity entity = new StringEntity(aclJson.toJSONString(), "UTF-8");
putRequest.setHeader(HTTP.CONTENT_TYPE, "application/json");
putRequest.setEntity(entity);
authenticate(putRequest);
final CloseableHttpResponse response = createHttpClient().execute(putRequest);
if (response.getStatusLine().getStatusCode() >= 300) {
throw new IllegalArgumentException(response.getStatusLine().getReasonPhrase());
}
}
@Override
public Iterable<Pair<WildcardPermission, Boolean>> hasPermissions(Iterable<WildcardPermission> permissions) throws ClientProtocolException, IOException, ParseException {
final StringBuilder sb = new StringBuilder(SECURITY_API_PREFIX + SecurityResource.RESTSECURITY + SecurityResource.HAS_PERMISSION_METHOD + "?");