use of javax.ws.rs.NotFoundException in project keywhiz by square.
the class SecretsResource method deleteSecret.
/**
* Delete Secret by ID
*
* @excludeParams user
* @param secretId the ID of the Secret to be deleted
*
* @description Deletes a single Secret if found.
* Used by Keywhiz CLI and the web ui.
* @responseMessage 200 Found and deleted Secret with given ID
* @responseMessage 404 Secret with given ID not Found
*/
@Path("{secretId}")
@Timed
@ExceptionMetered
@DELETE
public Response deleteSecret(@Auth User user, @PathParam("secretId") LongParam secretId) {
Optional<Secret> secret = secretController.getSecretById(secretId.get());
if (!secret.isPresent()) {
logger.info("User '{}' tried deleting a secret which was not found (id={})", user, secretId.get());
throw new NotFoundException("Secret not found.");
}
logger.info("User '{}' deleting secret id={}, name='{}'", user, secretId, secret.get().getName());
// Get the groups for this secret, so they can be restored manually if necessary
Set<String> groups = aclDAOReadOnly.getGroupsFor(secret.get()).stream().map(Group::getName).collect(toSet());
secretDAOReadWrite.deleteSecretsByName(secret.get().getName());
// Record the deletion
Map<String, String> extraInfo = new HashMap<>();
extraInfo.put("groups", groups.toString());
extraInfo.put("current version", secret.get().getVersion().toString());
auditLog.recordEvent(new Event(Instant.now(), EventTag.SECRET_DELETE, user.getName(), secret.get().getName(), extraInfo));
return Response.noContent().build();
}
use of javax.ws.rs.NotFoundException in project keywhiz by square.
the class AutomationClientResource method deleteClient.
/**
* Deletes a client
*
* @param clientId the ID of the client to delete
* @excludeParams automationClient
* @description Deletes a single client by id
* @responseMessage 200 Deleted client
* @responseMessage 404 Client not found by id
*/
@Timed
@ExceptionMetered
@DELETE
@Path("{clientId}")
public Response deleteClient(@Auth AutomationClient automationClient, @PathParam("clientId") LongParam clientId) {
Client client = clientDAO.getClientById(clientId.get()).orElseThrow(NotFoundException::new);
clientDAO.deleteClient(client);
Map<String, String> extraInfo = new HashMap<>();
extraInfo.put("deprecated", "true");
auditLog.recordEvent(new Event(Instant.now(), EventTag.CLIENT_CREATE, automationClient.getName(), client.getName(), extraInfo));
return Response.ok().build();
}
use of javax.ws.rs.NotFoundException in project keywhiz by square.
the class AutomationClientResource method findClientById.
/**
* Retrieve Client by ID
*
* @param clientId the ID of the Client to retrieve
* @excludeParams automationClient
* @description Returns a single Client if found
* @responseMessage 200 Found and retrieved Client with given ID
* @responseMessage 404 Client with given ID not Found
*/
@Timed
@ExceptionMetered
@GET
@Path("{clientId}")
public Response findClientById(@Auth AutomationClient automationClient, @PathParam("clientId") LongParam clientId) {
logger.info("Automation ({}) - Looking up an ID {}", automationClient.getName(), clientId);
Client client = clientDAO.getClientById(clientId.get()).orElseThrow(NotFoundException::new);
ImmutableList<Group> groups = ImmutableList.copyOf(aclDAO.getGroupsFor(client));
return Response.ok().entity(ClientDetailResponse.fromClient(client, groups, ImmutableList.of())).build();
}
use of javax.ws.rs.NotFoundException in project keywhiz by square.
the class SecretDAO method setCurrentSecretVersionByName.
/**
* @param name of secret series for which to reset secret version
* @param versionId The identifier for the desired current version
* @throws NotFoundException if secret not found
*/
public void setCurrentSecretVersionByName(String name, long versionId) {
checkArgument(!name.isEmpty());
checkArgument(versionId >= 0);
SecretSeriesDAO secretSeriesDAO = secretSeriesDAOFactory.using(dslContext.configuration());
SecretSeries series = secretSeriesDAO.getSecretSeriesByName(name).orElseThrow(NotFoundException::new);
secretSeriesDAO.setCurrentVersion(series.id(), versionId);
}
use of javax.ws.rs.NotFoundException in project keywhiz by square.
the class SecretDeliveryResource method getSecret.
/**
* Retrieve Secret by name
*
* @excludeParams client
* @param secretName the name of the Secret to retrieve
*
* @description Returns a single Secret if found
* @responseMessage 200 Found and retrieved Secret with given name
* @responseMessage 403 Secret is not assigned to Client
* @responseMessage 404 Secret with given name not found
* @responseMessage 500 Secret response could not be generated for given Secret
*/
@Timed
@ExceptionMetered
@GET
public SecretDeliveryResponse getSecret(@NotEmpty @PathParam("secretName") String secretName, @Auth Client client) {
Optional<SanitizedSecret> sanitizedSecret = aclDAO.getSanitizedSecretFor(client, secretName);
Optional<Secret> secret = secretController.getSecretByName(secretName);
if (!sanitizedSecret.isPresent()) {
boolean clientExists = clientDAO.getClient(client.getName()).isPresent();
boolean secretExists = secret.isPresent();
if (clientExists && secretExists) {
throw new ForbiddenException(format("Access denied: %s at '%s' by '%s'", client.getName(), "/secret/" + secretName, client));
} else {
if (clientExists) {
logger.info("Client {} requested unknown secret {}", client.getName(), secretName);
}
throw new NotFoundException();
}
}
logger.info("Client {} granted access to {}.", client.getName(), secretName);
try {
return SecretDeliveryResponse.fromSecret(secret.get());
} catch (IllegalArgumentException e) {
logger.error(format("Failed creating response for secret %s", secretName), e);
throw new InternalServerErrorException();
}
}
Aggregations