use of javax.ws.rs.NotFoundException in project keywhiz by square.
the class AutomationSecretAccessResource method allowAccess.
/**
* Assign Secret to Group
*
* @excludeParams automationClient
* @param secretId the ID of the Secret to assign
* @param groupId the ID of the Group to be assigned to
*
* @description Assigns the Secret specified by the secretID to the Group specified by the groupID
* @responseMessage 200 Successfully enrolled Secret in Group
* @responseMessage 404 Could not find Secret or Group
*/
@Timed
@ExceptionMetered
@PUT
public Response allowAccess(@Auth AutomationClient automationClient, @PathParam("secretId") LongParam secretId, @PathParam("groupId") LongParam groupId) {
logger.info("Client '{}' allowing groupId={} access to secretId={}", automationClient, secretId, groupId);
try {
Map<String, String> extraInfo = new HashMap<>();
extraInfo.put("deprecated", "true");
aclDAO.findAndAllowAccess(secretId.get(), groupId.get(), auditLog, automationClient.getName(), extraInfo);
} catch (IllegalStateException e) {
throw new NotFoundException();
}
return Response.ok().build();
}
use of javax.ws.rs.NotFoundException in project keywhiz by square.
the class AutomationSecretAccessResource method disallowAccess.
/**
* Remove Secret from Group
*
* @excludeParams automationClient
* @param secretId the ID of the Secret to unassign
* @param groupId the ID of the Group to be removed from
*
* @description Unassigns the Secret specified by the secretID from the Group specified by the groupID
* @responseMessage 200 Successfully removed Secret from Group
* @responseMessage 404 Could not find Secret or Group
*/
@Timed
@ExceptionMetered
@DELETE
public Response disallowAccess(@Auth AutomationClient automationClient, @PathParam("secretId") LongParam secretId, @PathParam("groupId") LongParam groupId) {
logger.info("Client '{}' disallowing groupId={} access to secretId={}", automationClient, secretId, groupId);
try {
Map<String, String> extraInfo = new HashMap<>();
extraInfo.put("deprecated", "true");
aclDAO.findAndRevokeAccess(secretId.get(), groupId.get(), auditLog, automationClient.getName(), extraInfo);
} catch (IllegalStateException e) {
throw new NotFoundException();
}
return Response.ok().build();
}
use of javax.ws.rs.NotFoundException in project keywhiz by square.
the class AutomationSecretResource method deleteSecretSeries.
/**
* Deletes all versions of a secret series
*
* @excludeParams automationClient
* @param secretName the name of the secret series to delete
*
* @description Deletes all versions of a secret series. This will delete a single secret ID.
* @responseMessage 200 Deleted secret series
* @responseMessage 404 Secret series not Found
*/
@Path("{secretName}")
@Timed
@ExceptionMetered
@DELETE
public Response deleteSecretSeries(@Auth AutomationClient automationClient, @PathParam("secretName") String secretName) {
Secret secret = secretController.getSecretByName(secretName).orElseThrow(() -> new NotFoundException("Secret series not found."));
Set<String> groups = aclDAO.getGroupsFor(secret).stream().map(Group::getName).collect(toSet());
secretDAO.deleteSecretsByName(secretName);
// Record all groups to which this secret belongs, so they can be restored manually if necessary
Map<String, String> extraInfo = new HashMap<>();
extraInfo.put("deprecated", "true");
extraInfo.put("groups", groups.toString());
extraInfo.put("current version", secret.getVersion().toString());
auditLog.recordEvent(new Event(Instant.now(), EventTag.SECRET_DELETE, automationClient.getName(), secretName, extraInfo));
return Response.ok().build();
}
use of javax.ws.rs.NotFoundException in project keywhiz by square.
the class ClientResource method modifyClient.
/**
* Modify a client
*
* @excludeParams automationClient
* @param currentName Client name
* @param request JSON request to modify the client
*
* @responseMessage 201 Client updated
* @responseMessage 404 Client not found
*/
@Timed
@ExceptionMetered
@POST
@Path("{name}")
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
public ClientDetailResponseV2 modifyClient(@Auth AutomationClient automationClient, @PathParam("name") String currentName, @Valid ModifyClientRequestV2 request) {
Client client = clientDAOReadWrite.getClient(currentName).orElseThrow(NotFoundException::new);
String newName = request.name();
// TODO: implement change client (name, updatedAt, updatedBy)
throw new NotImplementedException(format("Need to implement mutation methods in DAO to rename %s to %s", client.getName(), newName));
}
use of javax.ws.rs.NotFoundException in project keywhiz by square.
the class GroupResource method groupInfo.
/**
* Retrieve information on a group
*
* @excludeParams automationClient
* @param name Group name
*
* @responseMessage 200 Group information retrieved
* @responseMessage 404 Group not found
*/
@Timed
@ExceptionMetered
@GET
@Path("{name}")
@Produces(APPLICATION_JSON)
public GroupDetailResponseV2 groupInfo(@Auth AutomationClient automationClient, @PathParam("name") String name) {
Group group = groupDAOReadOnly.getGroup(name).orElseThrow(NotFoundException::new);
Set<String> secrets = aclDAOReadOnly.getSanitizedSecretsFor(group).stream().map(SanitizedSecret::name).collect(toSet());
Set<String> clients = aclDAOReadOnly.getClientsFor(group).stream().map(Client::getName).collect(toSet());
return GroupDetailResponseV2.builder().group(group).secrets(secrets).clients(clients).build();
}
Aggregations