Skip to content

Commit

Permalink
Addition of methods to modify/suppress users or groups access rights …
Browse files Browse the repository at this point in the history
…(#827)

Signed-off-by: NOIR Nicolas ext <[email protected]>
  • Loading branch information
niconoir committed Nov 13, 2019
1 parent 498180f commit f8ca3c5
Show file tree
Hide file tree
Showing 7 changed files with 350 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,31 @@ public void setDescription(String nodeId, String description) {
throw new AssertionError();
}

@Override
public void modifyUserAccessRights(String nodeId, String userName, Integer rights) {
throw new AssertionError();
}

@Override
public void modifyGroupAccessRights(String nodeId, String groupName, Integer rights) {
throw new AssertionError();
}

@Override
public void modifyOthersAccessRights(String nodeId, Integer rights) {
throw new AssertionError();
}

@Override
public boolean removeUserAccessRights(String nodeId, String userName) {
throw new AssertionError();
}

@Override
public boolean removeGroupAccessRights(String nodeId, String groupName) {
throw new AssertionError();
}

@Override
public void setConsistent(String nodeId) {
throw new AssertionError();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,55 @@ public void setDescription(String nodeId, String description) {
nodeInfoMap.put(nodeUuid, nodeInfo);
}

@Override
public void modifyUserAccessRights(String nodeId, String userName, Integer rights) {
UUID nodeUuid = checkNodeId(nodeId);
Objects.requireNonNull(userName);
Objects.requireNonNull(rights);
NodeInfo nodeInfo = getNodeInfo(nodeId);
nodeInfo.getAccessRights().setUserRights(userName, rights);
nodeInfoMap.put(nodeUuid, nodeInfo);
}

@Override
public void modifyGroupAccessRights(String nodeId, String groupName, Integer rights) {
UUID nodeUuid = checkNodeId(nodeId);
Objects.requireNonNull(groupName);
Objects.requireNonNull(rights);
NodeInfo nodeInfo = getNodeInfo(nodeId);
nodeInfo.getAccessRights().setGroupRights(groupName, rights);
nodeInfoMap.put(nodeUuid, nodeInfo);
}

@Override
public void modifyOthersAccessRights(String nodeId, Integer rights) {
UUID nodeUuid = checkNodeId(nodeId);
Objects.requireNonNull(rights);
NodeInfo nodeInfo = getNodeInfo(nodeId);
nodeInfo.getAccessRights().setOthersRights(rights);
nodeInfoMap.put(nodeUuid, nodeInfo);
}

@Override
public boolean removeUserAccessRights(String nodeId, String userName) {
UUID nodeUuid = checkNodeId(nodeId);
Objects.requireNonNull(userName);
NodeInfo nodeInfo = getNodeInfo(nodeId);
nodeInfo.getAccessRights().getUsersRights().remove(userName);
nodeInfoMap.put(nodeUuid, nodeInfo);
return !nodeInfo.getAccessRights().getUsersRights().containsKey(userName);
}

@Override
public boolean removeGroupAccessRights(String nodeId, String groupName) {
UUID nodeUuid = checkNodeId(nodeId);
Objects.requireNonNull(groupName);
NodeInfo nodeInfo = getNodeInfo(nodeId);
nodeInfo.getAccessRights().getGroupsRights().remove(groupName);
nodeInfoMap.put(nodeUuid, nodeInfo);
return !nodeInfo.getAccessRights().getGroupsRights().containsKey(groupName);
}

@Override
public void setConsistent(String nodeId) {
UUID nodeUuid = checkNodeId(nodeId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,43 @@ default boolean isConsistent(String nodeId) {

void setDescription(String nodeId, String description);

/**
*
* @param nodeId Id of the node whose user rights have to be modified
* @param userName User name
* @param rights Access rights for the user
*/
void modifyUserAccessRights(String nodeId, String userName, Integer rights);

/**
*
* @param nodeId Id of the node whose group rights have to be modified
* @param groupName Group name
* @param rights Access rights for the group
*/
void modifyGroupAccessRights(String nodeId, String groupName, Integer rights);

/**
*
* @param nodeId Id of the node whose others rights have to be modified
* @param rights Access rights for other users
*/
void modifyOthersAccessRights(String nodeId, Integer rights);

/**
*
* @param nodeId Id of the node whose user rights have to be removed
* @param userName User name
*/
boolean removeUserAccessRights(String nodeId, String userName);

/**
*
* @param nodeId Id of the node whose group rights have to be removed
* @param groupName User name
*/
boolean removeGroupAccessRights(String nodeId, String groupName);

/**
* mark the node with ID {@code nodeId} as consistent node.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,31 @@ public void setDescription(String nodeId, String description) {
storage.setDescription(nodeId, description);
}

@Override
public void modifyUserAccessRights(String nodeId, String userName, Integer rights) {
storage.modifyUserAccessRights(nodeId, userName, rights);
}

@Override
public void modifyGroupAccessRights(String nodeId, String groupName, Integer rights) {
storage.modifyGroupAccessRights(nodeId, groupName, rights);
}

@Override
public void modifyOthersAccessRights(String nodeId, Integer rights) {
storage.modifyOthersAccessRights(nodeId, rights);
}

@Override
public boolean removeUserAccessRights(String nodeId, String userName) {
return storage.removeUserAccessRights(nodeId, userName);
}

@Override
public boolean removeGroupAccessRights(String nodeId, String groupName) {
return storage.removeGroupAccessRights(nodeId, groupName);
}

@Override
public void setConsistent(String nodeId) {
storage.setConsistent(nodeId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,9 +298,25 @@ public void test() throws IOException, InterruptedException {
assertEquals(ImmutableMap.of("d1", 1d), testData2Info.getGenericMetadata().getDoubles());
assertEquals(ImmutableMap.of("i1", 2), testData2Info.getGenericMetadata().getInts());
assertEquals(ImmutableMap.of("b1", false), testData2Info.getGenericMetadata().getBooleans());

// check access rights
assertEquals(ImmutableMap.of("user1", 2, "user2", 4), testData2Info.getAccessRights().getUsersRights());
assertEquals(ImmutableMap.of("group1", 6), testData2Info.getAccessRights().getGroupsRights());

storage.modifyUserAccessRights(testData2Info.getId(), "user1", 4);
storage.modifyGroupAccessRights(testData2Info.getId(), "group1", 4);
storage.flush();

assertEquals(ImmutableMap.of("user1", 4, "user2", 4), storage.getNodeInfo(testData2Info.getId()).getAccessRights().getUsersRights());
assertEquals(ImmutableMap.of("group1", 4), storage.getNodeInfo(testData2Info.getId()).getAccessRights().getGroupsRights());

storage.removeUserAccessRights(testData2Info.getId(), "user1");
storage.removeGroupAccessRights(testData2Info.getId(), "group1");
storage.flush();

assertEquals(ImmutableMap.of("user2", 4), storage.getNodeInfo(testData2Info.getId()).getAccessRights().getUsersRights());
assertEquals(ImmutableMap.of(), storage.getNodeInfo(testData2Info.getId()).getAccessRights().getGroupsRights());

// 10) check data node 2 binary data write
try (OutputStream os = storage.writeBinaryData(testData2Info.getId(), "blob")) {
os.write("word2".getBytes(StandardCharsets.UTF_8));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,73 @@ public Response setDescription(@ApiParam(value = "File system name") @PathParam(
return Response.ok().build();
}

@PUT
@Consumes(MediaType.TEXT_PLAIN)
@Path("fileSystems/{fileSystemName}/nodes/{nodeId}/userRights/{userName}")
@ApiOperation (value = "")
@ApiResponses (value = {@ApiResponse(code = 200, message = ""), @ApiResponse(code = 500, message = "Error")})
public Response modifyUserAccessRights(@ApiParam(value = "File system name") @PathParam("fileSystemName") String fileSystemName,
@ApiParam(value = "Node ID") @PathParam("nodeId") String nodeId,
@ApiParam(value = "User Name") @PathParam("userName") String userName,
@ApiParam(value = "Rights") @QueryParam("rights") Integer rights) {
AppStorage storage = appDataBean.getStorage(fileSystemName);
storage.modifyUserAccessRights(nodeId, userName, rights);
return Response.ok().build();
}

@PUT
@Consumes(MediaType.TEXT_PLAIN)
@Path("fileSystems/{fileSystemName}/nodes/{nodeId}/groupRights/{groupName}")
@ApiOperation (value = "")
@ApiResponses (value = {@ApiResponse(code = 200, message = ""), @ApiResponse(code = 500, message = "Error")})
public Response modifyGroupAccessRights(@ApiParam(value = "File system name") @PathParam("fileSystemName") String fileSystemName,
@ApiParam(value = "Node ID") @PathParam("nodeId") String nodeId,
@ApiParam(value = "Group Name") @PathParam("groupName") String groupName,
@ApiParam(value = "Rights") @QueryParam("rights") Integer rights) {
AppStorage storage = appDataBean.getStorage(fileSystemName);
storage.modifyGroupAccessRights(nodeId, groupName, rights);
return Response.ok().build();
}

@PUT
@Consumes(MediaType.TEXT_PLAIN)
@Path("fileSystems/{fileSystemName}/nodes/{nodeId}/othersRights")
@ApiOperation (value = "")
@ApiResponses (value = {@ApiResponse(code = 200, message = ""), @ApiResponse(code = 500, message = "Error")})
public Response modifyUserAccessRights(@ApiParam(value = "File system name") @PathParam("fileSystemName") String fileSystemName,
@ApiParam(value = "Node ID") @PathParam("nodeId") String nodeId,
@ApiParam(value = "Rights") @QueryParam("rights") Integer rights) {
AppStorage storage = appDataBean.getStorage(fileSystemName);
storage.modifyOthersAccessRights(nodeId, rights);
return Response.ok().build();
}

@DELETE
@Produces(MediaType.TEXT_PLAIN)
@Path("fileSystems/{fileSystemName}/nodes/{nodeId}/userRights/{userName}")
@ApiOperation (value = "", response = Boolean.class)
@ApiResponses (value = {@ApiResponse(code = 200, message = ""), @ApiResponse(code = 404, message = ""), @ApiResponse(code = 500, message = "Error")})
public Response removeUserAccessRights(@ApiParam(value = "File system name") @PathParam("fileSystemName") String fileSystemName,
@ApiParam(value = "Node ID") @PathParam("nodeId") String nodeId,
@ApiParam(value = "User name") @PathParam("userName") String userName) {
AppStorage storage = appDataBean.getStorage(fileSystemName);
boolean removed = storage.removeUserAccessRights(nodeId, userName);
return Response.ok().entity(removed).build();
}

@DELETE
@Produces(MediaType.TEXT_PLAIN)
@Path("fileSystems/{fileSystemName}/nodes/{nodeId}/groupRights/{groupName}")
@ApiOperation (value = "", response = Boolean.class)
@ApiResponses (value = {@ApiResponse(code = 200, message = ""), @ApiResponse(code = 404, message = ""), @ApiResponse(code = 500, message = "Error")})
public Response removeGroupAccessRights(@ApiParam(value = "File system name") @PathParam("fileSystemName") String fileSystemName,
@ApiParam(value = "Node ID") @PathParam("nodeId") String nodeId,
@ApiParam(value = "Group name") @PathParam("groupName") String groupName) {
AppStorage storage = appDataBean.getStorage(fileSystemName);
boolean removed = storage.removeGroupAccessRights(nodeId, groupName);
return Response.ok().entity(removed).build();
}

@PUT
@Consumes(MediaType.APPLICATION_JSON)
@Path("fileSystems/{fileSystemName}/nodes/{nodeId}/consistent")
Expand Down
Loading

0 comments on commit f8ca3c5

Please sign in to comment.