Search in sources :

Example 36 with NotFoundException

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();
}
Also used : HashMap(java.util.HashMap) NotFoundException(javax.ws.rs.NotFoundException) Timed(com.codahale.metrics.annotation.Timed) ExceptionMetered(com.codahale.metrics.annotation.ExceptionMetered) PUT(javax.ws.rs.PUT)

Example 37 with NotFoundException

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();
}
Also used : HashMap(java.util.HashMap) NotFoundException(javax.ws.rs.NotFoundException) DELETE(javax.ws.rs.DELETE) Timed(com.codahale.metrics.annotation.Timed) ExceptionMetered(com.codahale.metrics.annotation.ExceptionMetered)

Example 38 with NotFoundException

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();
}
Also used : Secret(keywhiz.api.model.Secret) SanitizedSecret(keywhiz.api.model.SanitizedSecret) HashMap(java.util.HashMap) NotFoundException(javax.ws.rs.NotFoundException) Event(keywhiz.log.Event) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Timed(com.codahale.metrics.annotation.Timed) ExceptionMetered(com.codahale.metrics.annotation.ExceptionMetered)

Example 39 with NotFoundException

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));
}
Also used : NotImplementedException(org.apache.commons.lang3.NotImplementedException) NotFoundException(javax.ws.rs.NotFoundException) AutomationClient(keywhiz.api.model.AutomationClient) Client(keywhiz.api.model.Client) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) ExceptionMetered(com.codahale.metrics.annotation.ExceptionMetered)

Example 40 with NotFoundException

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();
}
Also used : Group(keywhiz.api.model.Group) NotFoundException(javax.ws.rs.NotFoundException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET) ExceptionMetered(com.codahale.metrics.annotation.ExceptionMetered)

Aggregations

NotFoundException (javax.ws.rs.NotFoundException)68 Path (javax.ws.rs.Path)46 Timed (com.codahale.metrics.annotation.Timed)45 ApiOperation (io.swagger.annotations.ApiOperation)27 ExceptionMetered (com.codahale.metrics.annotation.ExceptionMetered)25 GET (javax.ws.rs.GET)22 ApiResponses (io.swagger.annotations.ApiResponses)20 DELETE (javax.ws.rs.DELETE)20 Produces (javax.ws.rs.Produces)18 AuditEvent (org.graylog2.audit.jersey.AuditEvent)16 HashMap (java.util.HashMap)15 PUT (javax.ws.rs.PUT)15 Group (keywhiz.api.model.Group)14 SanitizedSecret (keywhiz.api.model.SanitizedSecret)14 Event (keywhiz.log.Event)14 Consumes (javax.ws.rs.Consumes)12 Client (keywhiz.api.model.Client)11 POST (javax.ws.rs.POST)10 BadRequestException (javax.ws.rs.BadRequestException)9 InternalServerErrorException (javax.ws.rs.InternalServerErrorException)9