use of javax.ws.rs.PathParam in project keywhiz by square.
the class ClientResource method modifyClientGroups.
/**
* Modify groups a client has membership in
*
* @param name Client name
* @param request JSON request specifying which groups to add or remove
* @return Listing of groups client has membership in
* <p>
* responseMessage 201 Client modified successfully
* <p>
* responseMessage 404 Client not found
*/
@Timed
@ExceptionMetered
@PUT
@Path("{name}/groups")
@Produces(APPLICATION_JSON)
public Iterable<String> modifyClientGroups(@Auth AutomationClient automationClient, @PathParam("name") String name, @Valid ModifyGroupsRequestV2 request) {
Client client = clientDAOReadWrite.getClientByName(name).orElseThrow(NotFoundException::new);
String user = automationClient.getName();
long clientId = client.getId();
Set<String> oldGroups = aclDAOReadWrite.getGroupsFor(client).stream().map(Group::getName).collect(toSet());
Set<String> groupsToAdd = Sets.difference(request.addGroups(), oldGroups);
Set<String> groupsToRemove = Sets.intersection(request.removeGroups(), oldGroups);
// TODO: should optimize AclDAO to use names and return only name column
groupsToGroupIds(groupsToAdd).forEach((maybeGroupId) -> maybeGroupId.ifPresent((groupId) -> aclDAOReadWrite.findAndEnrollClient(clientId, groupId, auditLog, user, new HashMap<>())));
groupsToGroupIds(groupsToRemove).forEach((maybeGroupId) -> maybeGroupId.ifPresent((groupId) -> aclDAOReadWrite.findAndEvictClient(clientId, groupId, auditLog, user, new HashMap<>())));
return aclDAOReadWrite.getGroupsFor(client).stream().map(Group::getName).collect(toSet());
}
use of javax.ws.rs.PathParam in project alluxio by Alluxio.
the class S3RestServiceHandler method postBucket.
/**
* Currently implements the DeleteObjects request type if the query parameter "delete" exists.
*
* @param bucket the bucket name
* @param delete the delete query parameter. Existence indicates to run the DeleteObjects impl
* @param contentLength body content length
* @param is the input stream to read the request
*
* @return a {@link DeleteObjectsResult} if this was a DeleteObjects request
*/
@POST
@Path(BUCKET_PARAM)
public Response postBucket(@PathParam("bucket") final String bucket, @QueryParam("delete") String delete, @HeaderParam("Content-Length") int contentLength, final InputStream is) {
return S3RestUtils.call(bucket, () -> {
if (delete != null) {
try {
DeleteObjectsRequest request = new XmlMapper().readerFor(DeleteObjectsRequest.class).readValue(is);
List<DeleteObjectsRequest.DeleteObject> objs = request.getToDelete();
List<DeleteObjectsResult.DeletedObject> success = new ArrayList<>();
List<DeleteObjectsResult.ErrorObject> errored = new ArrayList<>();
objs.sort(Comparator.comparingInt(x -> -1 * x.getKey().length()));
objs.forEach(obj -> {
try {
AlluxioURI uri = new AlluxioURI(AlluxioURI.SEPARATOR + bucket).join(AlluxioURI.SEPARATOR + obj.getKey());
DeletePOptions options = DeletePOptions.newBuilder().build();
mFileSystem.delete(uri, options);
DeleteObjectsResult.DeletedObject del = new DeleteObjectsResult.DeletedObject();
del.setKey(obj.getKey());
success.add(del);
} catch (FileDoesNotExistException | DirectoryNotEmptyException e) {
/*
FDNE - delete on FDNE should be counted as a success, as there's nothing to do
DNE - s3 has no concept dirs - if it _is_ a dir, nothing to delete.
*/
DeleteObjectsResult.DeletedObject del = new DeleteObjectsResult.DeletedObject();
del.setKey(obj.getKey());
success.add(del);
} catch (IOException | AlluxioException e) {
DeleteObjectsResult.ErrorObject err = new DeleteObjectsResult.ErrorObject();
err.setKey(obj.getKey());
err.setMessage(e.getMessage());
errored.add(err);
}
});
DeleteObjectsResult result = new DeleteObjectsResult();
if (!request.getQuiet()) {
result.setDeleted(success);
}
result.setErrored(errored);
return result;
} catch (IOException e) {
LOG.debug("Failed to parse DeleteObjects request:", e);
return Response.Status.BAD_REQUEST;
}
} else {
return Response.Status.OK;
}
});
}
use of javax.ws.rs.PathParam in project Payara by payara.
the class RestMethodMetadata method processParameters.
/**
* Process the parameters for the method. Any parameter marked <code>@PathParam</code> is ignored, since JAX-RS
* handles setting that value, meaning its presence need not be exposed to the client. Any parameter marked with
* <code>@QueryParameter</code> is stored in the <code>queryParameter</code> list. Anything left is considered the
* type of the request body. There should be only one of these.
* @param method
*/
private void processParameters(Method method) {
Type[] paramTypes = method.getGenericParameterTypes();
Annotation[][] paramAnnos = method.getParameterAnnotations();
int paramCount = paramTypes.length;
for (int i = 0; i < paramCount; i++) {
boolean processed = false;
boolean isPathParam = false;
Type paramType = paramTypes[i];
for (Annotation annotation : paramAnnos[i]) {
processed = (annotation instanceof Suspended) || (annotation instanceof PathParam);
if (annotation instanceof QueryParam) {
queryParameters.add(new ParamMetadata(context, paramType, ((QueryParam) annotation).value(), paramAnnos[i]));
processed = true;
}
}
if (!processed && !isPathParam) {
requestPayload = calculateParameterType(paramType);
}
}
}
use of javax.ws.rs.PathParam in project kylo by Teradata.
the class FeedRestController method getAllowedActions.
@GET
@Path("{feedId}/actions/allowed")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation("Gets the list of actions permitted for the given username and/or groups.")
@ApiResponses({ @ApiResponse(code = 200, message = "Returns the actions.", response = ActionGroup.class), @ApiResponse(code = 404, message = "A feed with the given ID does not exist.", response = RestResponseStatus.class) })
public Response getAllowedActions(@PathParam("feedId") String feedIdStr, @QueryParam("user") Set<String> userNames, @QueryParam("group") Set<String> groupNames) {
log.debug("Get allowed actions for feed: {}", feedIdStr);
Set<? extends Principal> users = Arrays.stream(this.securityTransform.asUserPrincipals(userNames)).collect(Collectors.toSet());
Set<? extends Principal> groups = Arrays.stream(this.securityTransform.asGroupPrincipals(groupNames)).collect(Collectors.toSet());
return this.securityService.getAllowedFeedActions(feedIdStr, Stream.concat(users.stream(), groups.stream()).collect(Collectors.toSet())).map(g -> Response.ok(g).build()).orElseThrow(() -> new WebApplicationException("A feed with the given ID does not exist: " + feedIdStr, Status.NOT_FOUND));
}
use of javax.ws.rs.PathParam in project kylo by Teradata.
the class DatasourceController method getAllowedPermissionsChange.
@GET
@Path("{id}/actions/change")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation("Constructs and returns a permission change request for a set of users/groups containing the actions that the requester may permit or revoke.")
@ApiResponses({ @ApiResponse(code = 200, message = "Returns the change request that may be modified by the client and re-posted.", response = PermissionsChange.class), @ApiResponse(code = 400, message = "The type is not valid.", response = RestResponseStatus.class), @ApiResponse(code = 404, message = "No data source exists with the specified ID.", response = RestResponseStatus.class) })
public Response getAllowedPermissionsChange(@PathParam("id") final String datasourceIdStr, @QueryParam("type") final String changeType, @QueryParam("user") final Set<String> userNames, @QueryParam("group") final Set<String> groupNames) {
if (StringUtils.isBlank(changeType)) {
throw new WebApplicationException("The query parameter \"type\" is required", Response.Status.BAD_REQUEST);
}
Set<? extends Principal> users = Arrays.stream(this.securityTransform.asUserPrincipals(userNames)).collect(Collectors.toSet());
Set<? extends Principal> groups = Arrays.stream(this.securityTransform.asGroupPrincipals(groupNames)).collect(Collectors.toSet());
return this.securityService.createDatasourcePermissionChange(datasourceIdStr, PermissionsChange.ChangeType.valueOf(changeType.toUpperCase()), Stream.concat(users.stream(), groups.stream()).collect(Collectors.toSet())).map(p -> Response.ok(p).build()).orElseThrow(() -> new WebApplicationException("A data source with the given ID does not exist: " + datasourceIdStr, Response.Status.NOT_FOUND));
}
Aggregations