use of javax.ws.rs.NotFoundException in project keywhiz by square.
the class GroupsResource method groupDetailResponseFromId.
private GroupDetailResponse groupDetailResponseFromId(long groupId) {
Optional<Group> optionalGroup = groupDAO.getGroupById(groupId);
if (!optionalGroup.isPresent()) {
throw new NotFoundException("Group not found.");
}
Group group = optionalGroup.get();
ImmutableList<SanitizedSecret> secrets = ImmutableList.copyOf(aclDAO.getSanitizedSecretsFor(group));
ImmutableList<Client> clients = ImmutableList.copyOf(aclDAO.getClientsFor(group));
return GroupDetailResponse.fromGroup(group, secrets, clients);
}
use of javax.ws.rs.NotFoundException in project keywhiz by square.
the class GroupsResource method deleteGroup.
/**
* Delete Group by ID
*
* @excludeParams user
* @param groupId the ID of the Group to be deleted
*
* @description Deletes a single Group if found.
* Used by Keywhiz CLI and the web ui.
* @responseMessage 200 Found and deleted Group with given ID
* @responseMessage 404 Group with given ID not Found
*/
@Path("{groupId}")
@Timed
@ExceptionMetered
@DELETE
public Response deleteGroup(@Auth User user, @PathParam("groupId") LongParam groupId) {
logger.info("User '{}' deleting group id={}.", user, groupId);
Optional<Group> group = groupDAO.getGroupById(groupId.get());
if (!group.isPresent()) {
throw new NotFoundException("Group not found.");
}
groupDAO.deleteGroup(group.get());
auditLog.recordEvent(new Event(Instant.now(), EventTag.GROUP_DELETE, user.getName(), group.get().getName()));
return Response.noContent().build();
}
use of javax.ws.rs.NotFoundException in project keywhiz by square.
the class AutomationClientResource method findClient.
/**
* Retrieve Client by a specified name, or all Clients if no name given
*
* @param name the name of the Client to retrieve, if provided
* @excludeParams automationClient
* @optionalParams name
* @description Returns a single Client or a set of all Clients
* @responseMessage 200 Found and retrieved Client(s)
* @responseMessage 404 Client with given name not found (if name provided)
*/
@Timed
@ExceptionMetered
@GET
public Response findClient(@Auth AutomationClient automationClient, @QueryParam("name") Optional<String> name) {
logger.info("Automation ({}) - Looking up a name {}", automationClient.getName(), name);
if (name.isPresent()) {
Client client = clientDAO.getClient(name.get()).orElseThrow(NotFoundException::new);
ImmutableList<Group> groups = ImmutableList.copyOf(aclDAO.getGroupsFor(client));
return Response.ok().entity(ClientDetailResponse.fromClient(client, groups, ImmutableList.of())).build();
}
List<ClientDetailResponse> clients = clientDAO.getClients().stream().map(c -> ClientDetailResponse.fromClient(c, ImmutableList.copyOf(aclDAO.getGroupsFor(c)), ImmutableList.of())).collect(toList());
return Response.ok().entity(clients).build();
}
use of javax.ws.rs.NotFoundException in project keywhiz by square.
the class ClientsResource method deleteClient.
/**
* Delete Client by ID
*
* @excludeParams user
* @param clientId the ID of the Client to be deleted
*
* @description Deletes a single Client if found.
* Used by Keywhiz CLI and the web ui.
* @responseMessage 200 Found and deleted Client with given ID
* @responseMessage 404 Client with given ID not Found
*/
@Path("{clientId}")
@Timed
@ExceptionMetered
@DELETE
public Response deleteClient(@Auth User user, @PathParam("clientId") LongParam clientId) {
logger.info("User '{}' deleting client id={}.", user, clientId);
Optional<Client> client = clientDAO.getClientById(clientId.get());
if (!client.isPresent()) {
throw new NotFoundException("Client not found.");
}
clientDAO.deleteClient(client.get());
auditLog.recordEvent(new Event(Instant.now(), EventTag.CLIENT_DELETE, user.getName(), client.get().getName()));
return Response.noContent().build();
}
use of javax.ws.rs.NotFoundException in project keywhiz by square.
the class SecretDAO method partialUpdateSecret.
@VisibleForTesting
public long partialUpdateSecret(String name, String creator, PartialUpdateSecretRequestV2 request) {
return dslContext.transactionResult(configuration -> {
SecretContentDAO secretContentDAO = secretContentDAOFactory.using(configuration);
SecretSeriesDAO secretSeriesDAO = secretSeriesDAOFactory.using(configuration);
SecretSeries secretSeries = secretSeriesDAO.getSecretSeriesByName(name).orElseThrow(NotFoundException::new);
Long currentVersion = secretSeries.currentVersion().orElseThrow(NotFoundException::new);
SecretContent secretContent = secretContentDAO.getSecretContentById(currentVersion).orElseThrow(NotFoundException::new);
long secretId = secretSeries.id();
String description = request.descriptionPresent() ? request.description() : secretSeries.description();
String type = request.typePresent() ? request.type() : secretSeries.type().orElse("");
ImmutableMap<String, String> metadata = request.metadataPresent() ? request.metadata() : secretContent.metadata();
Long expiry = request.expiryPresent() ? request.expiry() : secretContent.expiry();
String encryptedContent = secretContent.encryptedContent();
String hmac = secretContent.hmac();
if (request.contentPresent()) {
hmac = cryptographer.computeHmac(request.content().getBytes(UTF_8));
if (hmac == null) {
throw new ContentEncodingException("Error encoding content for SecretBuilder!");
}
encryptedContent = cryptographer.encryptionKeyDerivedFrom(name).encrypt(request.content());
}
secretSeriesDAO.updateSecretSeries(secretId, name, creator, description, type, secretSeries.generationOptions());
long secretContentId = secretContentDAO.createSecretContent(secretId, encryptedContent, hmac, creator, metadata, expiry);
secretSeriesDAO.setCurrentVersion(secretId, secretContentId);
return secretId;
});
}
Aggregations